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.master
parent
cffd9ddeb0
commit
1aa69c2a56
|
@ -277,7 +277,9 @@ export class RatingService
|
|||
// save the last prem status (we pass an empty object as the save
|
||||
// data argument to ensure that we do not save the actual bucket
|
||||
// data, which may cause a race condition with the below merge call)
|
||||
this._dao.saveQuote( quote, c, c, {} );
|
||||
this._dao.saveQuote( quote, c, c, {
|
||||
ratedata: data,
|
||||
} );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue