diff options
author | Shelly Shaver <shelly.shaver@rtspecialty.com> | 2020-01-29 14:46:30 -0500 |
---|---|---|
committer | Shelly Shaver <shelly.shaver@rtspecialty.com> | 2020-02-03 16:19:17 -0500 |
commit | 44a42bd256aea77f309effb02403cbca2912782f (patch) | |
tree | de66bebeb47bb91214400859ecf09bd11ad0dde1 /test | |
parent | 41343fccddb7b068662b462677fe4b6fac786f3a (diff) | |
download | liza-44a42bd256aea77f309effb02403cbca2912782f.tar.gz liza-44a42bd256aea77f309effb02403cbca2912782f.tar.bz2 liza-44a42bd256aea77f309effb02403cbca2912782f.zip |
[DEV-6323] Send action to client for re-rating
Delay action is sent if any raters have not completed
rating and a re-try is needed. The __rate_pending count
of pending suppliers is saved in ratedate and used to
prevent post-rate messages from being processed by the
delta processor.
Diffstat (limited to 'test')
-rw-r--r-- | test/server/service/RatingServiceTest.ts | 70 | ||||
-rw-r--r-- | test/system/db/MongoDeltaDaoTest.ts | 112 |
2 files changed, 182 insertions, 0 deletions
diff --git a/test/server/service/RatingServiceTest.ts b/test/server/service/RatingServiceTest.ts index e781ceb..1434a5c 100644 --- a/test/server/service/RatingServiceTest.ts +++ b/test/server/service/RatingServiceTest.ts @@ -423,6 +423,76 @@ describe( 'RatingService', () => .then( () => expect( sent ).to.be.true ); } ); + ( <[string, Record<string, any>, number, boolean][]>[ + [ + "delay action is returned when raters are pending", + { + 'supplier-a__retry': [ 0 ], + 'supplier-b__retry': [ 1 ], + 'supplier-c__retry': [ 1 ], + 'supplier-d__retry': [ 0 ], + }, + 2, + true + ], + [ + "delay action is not returned when all raters are completed", + { + 'supplier-a__retry': [ 0 ], + 'supplier-b__retry': [ 0 ], + 'supplier-c__retry': [ 0 ], + 'supplier-d__retry': [ 0 ], + }, + 0, + false + ], + ] ).forEach( ( [label, supplier_data, expected_count, expected_delay_action ]) => + { + it( label, () => + { + const { + dao, + logger, + quote, + raters, + request, + response, + server, + stub_rate_data, + createDelta, + } = getStubs(); + + let sent = false; + + Object.assign( stub_rate_data, supplier_data ); + + server.sendResponse = ( + _request: any, + _quote: any, + resp: RateRequestResult, + actions: ClientActions + ) => + { + const expected_action = { + "action": "delay", + "seconds": 2, + "then": { action: "rate" } + }; + + ( expected_delay_action ) + ? expect( actions ).to.deep.equal( [ expected_action ] ) + : expect( actions ).to.not.equal( [ expected_action ] ); + + expect( resp.data[ '__rate_pending' ] ).to.equal( expected_count ); + sent = true; + return server; + }; + + const sut = new Sut( logger, dao, server, raters, createDelta ); + return sut.request( request, response, quote, "" ) + .then( () => expect( sent ).to.be.true ); + } ); + } ); describe( "protected API", () => { diff --git a/test/system/db/MongoDeltaDaoTest.ts b/test/system/db/MongoDeltaDaoTest.ts new file mode 100644 index 0000000..9c9a15f --- /dev/null +++ b/test/system/db/MongoDeltaDaoTest.ts @@ -0,0 +1,112 @@ +/** + * Delta data access test + * + * Copyright (C) 2010-2019 R-T Specialty, LLC. + * + * This file is part of the Liza Data Collection Framework. + * + * liza is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import { MongoDeltaDao as Sut } from "../../../src/system/db/MongoDeltaDao"; +import { MongoCollection } from "mongodb"; +import { DeltaDocument } from "../../../src/bucket/delta"; +import { DaoError } from '../../../src/error/DaoError'; +import { expect, use as chai_use } from 'chai'; +import {DocumentId} from "../../../src/document/Document"; +chai_use( require( 'chai-as-promised' ) ); + + +describe( 'system.db.MongoDeltaDao', () => +{ + describe( '#getUnprocessedDocuments', () => + { + it( "finds unprocessed documents that do not have rates pending", () => + { + const stub_env = 'foo'; + let find_called = false; + + const delta_docs = <DeltaDocument[]>[ { + id: <DocumentId>123, + programId: '', + agentName: '', + agentEntityId: 0, + startDate: <UnixTimestamp>0, + lastUpdate: <UnixTimestamp>0, + data: {}, + ratedata: {}, + rdelta: {}, + } ]; + + const coll: MongoCollection = { + findAndModify() {}, + findOne() {}, + update() {}, + createIndex() {}, + insert() {}, + find( + selector, + _fields, + callback ) + { + expect( selector[ 'ratedata.__rate_pending' ] ) + .to.deep.equal( { $in: [ 0, null ] } ); + expect( selector.deltaError ) + .to.deep.equal( { $ne: true } ); + expect( selector.published ) + .to.be.false; + expect( selector.env ) + .to.equal( stub_env ); + + find_called = true; + callback( null, { + toArray: ( c: any ) => c( null, delta_docs ), + } ); + }, + }; + + const sut = new Sut( coll, stub_env ); + return sut.getUnprocessedDocuments() + .then( () => expect( find_called ).to.be.true ); + } ); + + it( "rejects with error on query failure", () => + { + const stub_env = 'foo'; + let find_called = false; + const expected_error_msg = 'expected error!'; + + const coll: MongoCollection = { + findAndModify() {}, + findOne() {}, + update() {}, + createIndex() {}, + insert() {}, + find( + _selector, + _fields, + callback ) + { + find_called = true; + callback( new Error( expected_error_msg ), {} ); + }, + }; + + const sut = new Sut( coll, stub_env ); + return expect( sut.getUnprocessedDocuments() ) + .to.eventually.rejectedWith( DaoError, expected_error_msg ) + .then( () => expect( find_called ).to.be.true ); + } ); + } ); +} ); |