Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-10-31 14:26:12 -0400
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-10-31 14:26:12 -0400
commit64718d55134612f96a61e3779d8e057b161e318c (patch)
tree67a790277ec3b6b54e52952bbbde7f2ba8b51522
parentf0e246deef1e10f382cafcd36eca89620a8f6ace (diff)
downloadliza-64718d55134612f96a61e3779d8e057b161e318c.tar.gz
liza-64718d55134612f96a61e3779d8e057b161e318c.tar.bz2
liza-64718d55134612f96a61e3779d8e057b161e318c.zip
RatingService: Fix initialRatedDate and lastRatedDate reply
Recent changes caused the quote to be read before it was mutated by _saveRatingData.
-rw-r--r--src/server/service/RatingService.ts22
-rw-r--r--test/server/service/RatingServiceTest.ts73
2 files changed, 83 insertions, 12 deletions
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 <http://www.gnu.org/licenses/>.
*/
-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 = <UnixTimestamp>12345;
+ let stub_rated_date_ts = <UnixTimestamp>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 {