diff --git a/src/server/service/RatingService.ts b/src/server/service/RatingService.ts
index b2a5062..f95f4ea 100644
--- a/src/server/service/RatingService.ts
+++ b/src/server/service/RatingService.ts
@@ -212,22 +212,22 @@ export class RatingService
quote, class_dest, () => {}, () => {}
);
- const result = {
- data: cleaned,
- initialRatedDate: quote.getRatedDate(),
- lastRatedDate: quote.getLastPremiumDate()
- };
-
// save all data server-side (important: do after
// post-processing); async
- this._saveRatingData( quote, rate_data, indv, function()
+ this._saveRatingData( quote, rate_data, indv, () =>
{
- // we're done
+ const result = {
+ data: cleaned,
+ initialRatedDate: quote.getRatedDate(),
+ lastRatedDate: quote.getLastPremiumDate()
+ };
+
+ this._server.sendResponse(
+ request, quote, result, actions
+ );
+
resolve( result );
} );
-
- // no need to wait for the save; send the response
- this._server.sendResponse( request, quote, result, actions );
},
( message: string ) =>
{
diff --git a/test/server/service/RatingServiceTest.ts b/test/server/service/RatingServiceTest.ts
index 7bab2e4..1b7f7d7 100644
--- a/test/server/service/RatingServiceTest.ts
+++ b/test/server/service/RatingServiceTest.ts
@@ -19,7 +19,10 @@
* along with this program. If not, see .
*/
-import { RatingService as Sut } from "../../../src/server/service/RatingService";
+import {
+ RatingService as Sut,
+ RateRequestResult
+} from "../../../src/server/service/RatingService";
import { ClientActions } from "../../../src/client/action/ClientAction";
import { PriorityLog } from "../../../src/server/log/PriorityLog";
@@ -69,6 +72,74 @@ describe( 'RatingService', () =>
.to.eventually.deep.equal( expected );
} );
+
+ it( "updates rating dates before serving to client", () =>
+ {
+ const {
+ logger,
+ server,
+ raters,
+ dao,
+ request,
+ response,
+ quote,
+ stub_rate_data,
+ } = getStubs();
+
+ const sut = new Sut( logger, dao, server, raters );
+
+ let last_prem_called = false;
+ let rated_date_called = false;
+
+ let stub_last_prem_ts = 12345;
+ let stub_rated_date_ts = 23456;
+
+ let sent = false;
+
+ quote.setLastPremiumDate = () =>
+ {
+ last_prem_called = true;
+ return quote;
+ };
+
+ quote.setRatedDate = () =>
+ {
+ rated_date_called = true;
+ return quote;
+ };
+
+ quote.getLastPremiumDate = () => stub_last_prem_ts;
+ quote.getRatedDate = () => stub_rated_date_ts;
+
+ server.sendResponse = (
+ _request: any,
+ _quote: any,
+ resp: RateRequestResult,
+ _actions: ClientActions
+ ) =>
+ {
+ expect( resp.initialRatedDate ).to.equal( stub_rated_date_ts );
+ expect( resp.lastRatedDate ).to.equal( stub_last_prem_ts );
+
+ expect( last_prem_called ).to.be.true;
+ expect( rated_date_called ).to.be.true;
+
+ sent = true;
+
+ return server;
+ };
+
+ const expected = {
+ data: stub_rate_data,
+ initialRatedDate: stub_rated_date_ts,
+ lastRatedDate: stub_last_prem_ts,
+ };
+
+ return expect( sut.request( request, response, quote, "" ) )
+ .to.eventually.deep.equal( expected )
+ .then( () => expect( sent ).to.be.true );
+ } );
+
it( "saves rate data to own field", () =>
{
const {