2018-04-25 15:35:16 -04:00
|
|
|
/**
|
|
|
|
* Tests RatingServiceSubmitNotify
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const { Class } = require( 'easejs' );
|
|
|
|
const { expect } = require( 'chai' );
|
|
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
dapi: {
|
|
|
|
DataApi,
|
|
|
|
},
|
|
|
|
server: {
|
|
|
|
service: {
|
|
|
|
RatingServiceSubmitNotify: Sut,
|
|
|
|
RatingService,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
test: {
|
|
|
|
server: {
|
|
|
|
service: {
|
|
|
|
RatingServiceStub,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} = require( '../../../' );
|
|
|
|
|
|
|
|
|
|
|
|
describe( 'RatingServiceSubmitNotify', () =>
|
|
|
|
{
|
|
|
|
[
|
2018-05-02 14:23:39 -04:00
|
|
|
// not available; make successful request and save flag
|
2018-04-25 15:35:16 -04:00
|
|
|
{
|
|
|
|
prem_avail_count: [ 0 ],
|
2018-04-26 15:30:04 -04:00
|
|
|
prev_called: false,
|
2018-04-25 15:35:16 -04:00
|
|
|
expected_request: true,
|
2018-05-02 14:23:39 -04:00
|
|
|
request_err: null,
|
|
|
|
save: true,
|
2018-04-25 15:35:16 -04:00
|
|
|
},
|
2018-05-02 14:23:39 -04:00
|
|
|
// not available; make failing request, don't save flag
|
|
|
|
{
|
|
|
|
prem_avail_count: [ 0 ],
|
|
|
|
prev_called: false,
|
|
|
|
expected_request: true,
|
|
|
|
request_err: Error(),
|
|
|
|
save: false,
|
|
|
|
},
|
|
|
|
// available
|
2018-04-25 15:35:16 -04:00
|
|
|
{
|
|
|
|
prem_avail_count: [ 2 ],
|
2018-04-26 15:30:04 -04:00
|
|
|
prev_called: false,
|
2018-04-25 15:35:16 -04:00
|
|
|
expected_request: false,
|
2018-05-02 14:23:39 -04:00
|
|
|
request_err: null,
|
|
|
|
save: false,
|
2018-04-25 15:35:16 -04:00
|
|
|
},
|
2018-05-02 14:23:39 -04:00
|
|
|
// this shouldn't happen; ignore all but first index
|
2018-04-25 15:35:16 -04:00
|
|
|
{
|
|
|
|
prem_avail_count: [ 2, 2 ],
|
2018-04-26 15:30:04 -04:00
|
|
|
prev_called: false,
|
2018-04-25 15:35:16 -04:00
|
|
|
expected_request: false,
|
2018-05-02 14:23:39 -04:00
|
|
|
request_err: null,
|
|
|
|
save: false,
|
2018-04-25 15:35:16 -04:00
|
|
|
},
|
2018-04-26 15:30:04 -04:00
|
|
|
// save as above, but already saved
|
|
|
|
{
|
|
|
|
prem_avail_count: [ 0 ],
|
|
|
|
prev_called: true,
|
|
|
|
expected_request: false,
|
2018-05-02 14:23:39 -04:00
|
|
|
request_err: null,
|
|
|
|
save: false,
|
2018-04-26 15:30:04 -04:00
|
|
|
},
|
2018-05-02 14:23:39 -04:00
|
|
|
// available; don't make request
|
2018-04-26 15:30:04 -04:00
|
|
|
{
|
|
|
|
prem_avail_count: [ 2 ],
|
|
|
|
prev_called: true,
|
|
|
|
expected_request: false,
|
2018-05-02 14:23:39 -04:00
|
|
|
request_err: null,
|
|
|
|
save: false,
|
2018-04-26 15:30:04 -04:00
|
|
|
},
|
2018-05-02 14:23:39 -04:00
|
|
|
// this shouldn't happen; ignore all but first index
|
2018-04-26 15:30:04 -04:00
|
|
|
{
|
|
|
|
prem_avail_count: [ 2, 2 ],
|
|
|
|
prev_called: true,
|
|
|
|
expected_request: false,
|
2018-05-02 14:23:39 -04:00
|
|
|
request_err: null,
|
|
|
|
save: false,
|
2018-04-26 15:30:04 -04:00
|
|
|
},
|
2018-05-02 14:23:39 -04:00
|
|
|
].forEach( ( expected, i ) =>
|
2018-04-25 15:35:16 -04:00
|
|
|
it( `sends request on post process if no premiums (#${i})`, done =>
|
|
|
|
{
|
|
|
|
const {
|
2018-04-27 16:06:33 -04:00
|
|
|
dao,
|
2018-04-25 15:35:16 -04:00
|
|
|
logger,
|
2018-04-27 16:06:33 -04:00
|
|
|
quote,
|
2018-04-25 15:35:16 -04:00
|
|
|
raters,
|
|
|
|
request,
|
|
|
|
response,
|
2018-04-27 16:06:33 -04:00
|
|
|
server,
|
|
|
|
stub_rate_data,
|
2018-04-25 15:35:16 -04:00
|
|
|
} = RatingServiceStub.getStubs();
|
|
|
|
|
|
|
|
const quote_id = 1234;
|
|
|
|
let requested = false;
|
|
|
|
|
2018-04-27 16:06:33 -04:00
|
|
|
const dapif = given_request =>
|
|
|
|
Class.implement( DataApi ).extend(
|
2018-04-25 15:35:16 -04:00
|
|
|
{
|
2018-04-27 16:06:33 -04:00
|
|
|
// warning: if an expectation fails, because of how
|
|
|
|
// RatingService handles errors, it will cause the test to
|
|
|
|
// _hang_ rather than throw the assertion error
|
|
|
|
request( data, callback )
|
|
|
|
{
|
|
|
|
expect( given_request ).to.equal( request );
|
|
|
|
expect( data ).to.deep.equal( { quote_id: quote_id } );
|
2018-04-25 15:35:16 -04:00
|
|
|
|
2018-04-27 16:06:33 -04:00
|
|
|
requested = true;
|
2018-05-02 14:23:39 -04:00
|
|
|
|
|
|
|
callback( expected.request_err, null );
|
2018-04-27 16:06:33 -04:00
|
|
|
},
|
|
|
|
} )();
|
2018-04-25 15:35:16 -04:00
|
|
|
|
2018-04-27 16:06:33 -04:00
|
|
|
const sut = RatingService.use( Sut( dapif, dao ) )(
|
2018-04-25 15:35:16 -04:00
|
|
|
logger, dao, server, raters
|
|
|
|
);
|
|
|
|
|
|
|
|
quote.getId = () => quote_id;
|
|
|
|
|
|
|
|
// one of the methods that is called by the supertype
|
|
|
|
let save_called = false;
|
|
|
|
dao.setWorksheets = () => save_called = true;
|
|
|
|
|
2018-04-26 15:30:04 -04:00
|
|
|
// whether the notify flag is actually set
|
|
|
|
let notify_saved = false;
|
|
|
|
|
|
|
|
// request for notification status
|
|
|
|
dao.getDocumentField = ( qid, key, callback ) =>
|
|
|
|
{
|
|
|
|
expect( qid ).to.equal( quote_id );
|
|
|
|
expect( key ).to.equal( 'submitNotified' );
|
|
|
|
|
2018-05-02 14:23:39 -04:00
|
|
|
callback( expected.flag_error, expected.prev_called );
|
2018-04-26 15:30:04 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
dao.setDocumentField = ( qid, key, value, callback ) =>
|
|
|
|
{
|
|
|
|
expect( qid ).to.equal( quote_id );
|
|
|
|
expect( key ).to.equal( 'submitNotified' );
|
|
|
|
expect( value ).to.equal( true );
|
|
|
|
|
|
|
|
notify_saved = true;
|
|
|
|
};
|
|
|
|
|
2018-05-02 14:23:39 -04:00
|
|
|
stub_rate_data.__prem_avail_count = expected.prem_avail_count;
|
2018-04-25 15:35:16 -04:00
|
|
|
|
|
|
|
sut.request( request, response, quote, 'something', () =>
|
|
|
|
{
|
2018-05-02 14:23:39 -04:00
|
|
|
expect( requested ).to.equal( expected.expected_request );
|
2018-04-25 15:35:16 -04:00
|
|
|
expect( save_called ).to.be.true;
|
|
|
|
|
2018-04-26 15:30:04 -04:00
|
|
|
// only save notification status if we're notifying
|
2018-05-02 14:23:39 -04:00
|
|
|
expect( notify_saved ).to.equal( expected.save );
|
2018-04-26 15:30:04 -04:00
|
|
|
|
2018-04-25 15:35:16 -04:00
|
|
|
done();
|
|
|
|
} );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
} );
|