Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-10-24 14:34:11 -0400
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-10-29 13:36:55 -0400
commit1aa69c2a56fe2ad46dfdf10061b9726c18f0e8d8 (patch)
tree747d9f3fc1df166cc9b5f7874e959f35b6b5e7e9 /test
parentcffd9ddeb0143d027ed7407a819552881b0fefb3 (diff)
downloadliza-1aa69c2a56fe2ad46dfdf10061b9726c18f0e8d8.tar.gz
liza-1aa69c2a56fe2ad46dfdf10061b9726c18f0e8d8.tar.bz2
liza-1aa69c2a56fe2ad46dfdf10061b9726c18f0e8d8.zip
RatingService: Save rating data to separate field (ratedata)
This adds ratedata to the quote collection. We use the existing saveQuote method so that this operation is atomic. We're also continuing to save to the bucket for now so as not to break existing code, but the intent in the future will be to remove all but necessary data that should be exposed to the client.
Diffstat (limited to 'test')
-rw-r--r--test/server/service/RatingServiceTest.ts56
1 files changed, 54 insertions, 2 deletions
diff --git a/test/server/service/RatingServiceTest.ts b/test/server/service/RatingServiceTest.ts
index dfee767..c40ea06 100644
--- a/test/server/service/RatingServiceTest.ts
+++ b/test/server/service/RatingServiceTest.ts
@@ -29,15 +29,61 @@ import { Program } from "../../../src/program/Program";
import { QuoteId } from "../../../src/quote/Quote";
import { Rater, RateResult } from "../../../src/server/rater/Rater";
import { Server } from "../../../src/server/Server";
-import { ServerDao } from "../../../src/server/db/ServerDao";
import { ServerSideQuote } from "../../../src/server/quote/ServerSideQuote";
import { UserRequest } from "../../../src/server/request/UserRequest";
import { UserResponse } from "../../../src/server/request/UserResponse";
import { UserSession } from "../../../src/server/request/UserSession";
+import {
+ ServerDao,
+ Callback as ServerDaoCallback
+} from "../../../src/server/db/ServerDao";
+
describe( 'RatingService', () =>
{
+ it( "saves rate data to own field", done =>
+ {
+ const {
+ logger,
+ server,
+ raters,
+ dao,
+ request,
+ response,
+ quote,
+ stub_rate_data,
+ } = getStubs();
+
+ let saved_rates = false;
+
+ dao.saveQuote = (
+ quote: ServerSideQuote,
+ success: ServerDaoCallback,
+ _failure: ServerDaoCallback,
+ save_data: Record<string, any>,
+ ) =>
+ {
+ expect( save_data ).to.deep.equal( {
+ ratedata: stub_rate_data,
+ } );
+
+ saved_rates = true;
+ success( quote );
+
+ return dao;
+ };
+
+ const sut = new Sut( logger, dao, server, raters );
+
+ sut.request( request, response, quote, "", () =>
+ {
+ expect( saved_rates ).to.be.true;
+ done();
+ } );
+ } );
+
+
describe( "protected API", () =>
{
it( "calls #postProcessRaterData after rating before save", done =>
@@ -171,8 +217,14 @@ function getStubs()
const dao = new class implements ServerDao
{
- saveQuote(): this
+ saveQuote(
+ quote: ServerSideQuote,
+ success: ServerDaoCallback,
+ _failure: ServerDaoCallback,
+ _save_data: Record<string, any>,
+ ): this
{
+ success( quote );
return this;
}