RatingServiceSubmitNotify: Create dapi dynamically with session
Session information needs to be available for request session spoofing.master
parent
d9c442b8e2
commit
ae0d9b3862
|
@ -155,7 +155,7 @@ module.exports = Class( 'RatingService',
|
|||
actions = actions || [];
|
||||
|
||||
_self.postProcessRaterData(
|
||||
rate_data, actions, program, quote
|
||||
request, rate_data, actions, program, quote
|
||||
);
|
||||
|
||||
const class_dest = {};
|
||||
|
@ -244,6 +244,7 @@ module.exports = Class( 'RatingService',
|
|||
/**
|
||||
* Process rater data returned from a rater
|
||||
*
|
||||
* @param {UserRequest} request user request to satisfy
|
||||
* @param {Object} data rating data returned
|
||||
* @param {Array} actions actions to send to client
|
||||
* @param {Program} program program used to perform rating
|
||||
|
@ -251,7 +252,9 @@ module.exports = Class( 'RatingService',
|
|||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
'virtual protected postProcessRaterData': function( data, actions, program, quote )
|
||||
'virtual protected postProcessRaterData': function(
|
||||
request, data, actions, program, quote
|
||||
)
|
||||
{
|
||||
var meta = data._cmpdata || {};
|
||||
|
||||
|
|
|
@ -41,10 +41,10 @@ module.exports = Trait( 'RatingServiceSubmitNotify' )
|
|||
.extend( RatingService,
|
||||
{
|
||||
/**
|
||||
* DataApi to trigger
|
||||
* @type {DataApi}
|
||||
* Function returning DataApi to trigger
|
||||
* @type {Function(UserSession):DataApi}
|
||||
*/
|
||||
'private _dapi': null,
|
||||
'private _dapif': null,
|
||||
|
||||
/**
|
||||
* Data store for notification flag
|
||||
|
@ -56,12 +56,12 @@ module.exports = Trait( 'RatingServiceSubmitNotify' )
|
|||
/**
|
||||
* Initialize mixin with DataApi to trigger
|
||||
*
|
||||
* @param {DataApi} dapi DataApi to trigger
|
||||
* @param {ServerDao} dao data store for notification flag
|
||||
* @param {Function(UserSession):DataApi} dapif Function producing DataApi
|
||||
* @param {ServerDao} dao store for notification flag
|
||||
*/
|
||||
__mixin( dapi, dao )
|
||||
__mixin( dapif, dao )
|
||||
{
|
||||
this._dapi = dapi;
|
||||
this._dapif = dapif;
|
||||
this._notifyDao = dao;
|
||||
},
|
||||
|
||||
|
@ -71,6 +71,7 @@ module.exports = Trait( 'RatingServiceSubmitNotify' )
|
|||
*
|
||||
* Result count is determined by DATA.__prem_avail_count.
|
||||
*
|
||||
* @param {UserRequest} request user request
|
||||
* @param {Object} data rating data returned
|
||||
* @param {Array} actions actions to send to client
|
||||
* @param {Program} program program used to perform rating
|
||||
|
@ -78,7 +79,9 @@ module.exports = Trait( 'RatingServiceSubmitNotify' )
|
|||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
'override protected postProcessRaterData'( data, actions, program, quote )
|
||||
'override protected postProcessRaterData'(
|
||||
request, data, actions, program, quote
|
||||
)
|
||||
{
|
||||
const quote_id = quote.getId();
|
||||
const avail = ( data.__prem_avail_count || [ 0 ] )[ 0 ];
|
||||
|
@ -92,12 +95,14 @@ module.exports = Trait( 'RatingServiceSubmitNotify' )
|
|||
return;
|
||||
}
|
||||
|
||||
this._dapi.request( { quote_id: quote_id }, () => {} );
|
||||
this._dapif( request )
|
||||
.request( { quote_id: quote_id }, () => {} );
|
||||
|
||||
this._setNotified( quote_id );
|
||||
} );
|
||||
}
|
||||
|
||||
this.__super( data, actions, program, quote );
|
||||
this.__super( request, data, actions, program, quote );
|
||||
},
|
||||
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ exports.getStubs = function()
|
|||
|
||||
const request = {
|
||||
getSession: () => session,
|
||||
getSessionIdName: () => {},
|
||||
};
|
||||
const response = {};
|
||||
|
||||
|
|
|
@ -86,33 +86,35 @@ describe( 'RatingServiceSubmitNotify', () =>
|
|||
it( `sends request on post process if no premiums (#${i})`, done =>
|
||||
{
|
||||
const {
|
||||
stub_rate_data,
|
||||
logger,
|
||||
server,
|
||||
raters,
|
||||
dao,
|
||||
logger,
|
||||
quote,
|
||||
raters,
|
||||
request,
|
||||
response,
|
||||
quote,
|
||||
server,
|
||||
stub_rate_data,
|
||||
} = RatingServiceStub.getStubs();
|
||||
|
||||
const quote_id = 1234;
|
||||
let requested = false;
|
||||
|
||||
const dapi = Class.implement( DataApi ).extend(
|
||||
const dapif = given_request =>
|
||||
Class.implement( DataApi ).extend(
|
||||
{
|
||||
// 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 } );
|
||||
|
||||
requested = true;
|
||||
},
|
||||
} )();
|
||||
|
||||
const sut = RatingService.use( Sut( dapi, dao ) )(
|
||||
const sut = RatingService.use( Sut( dapif, dao ) )(
|
||||
logger, dao, server, raters
|
||||
);
|
||||
|
||||
|
|
|
@ -33,7 +33,15 @@ describe( 'RatingService', () =>
|
|||
{
|
||||
let processed = false;
|
||||
|
||||
const { logger, server, raters, dao, request, response, quote } = RatingServiceStub.getStubs();
|
||||
const {
|
||||
logger,
|
||||
server,
|
||||
raters,
|
||||
dao,
|
||||
request,
|
||||
response,
|
||||
quote,
|
||||
} = RatingServiceStub.getStubs();
|
||||
|
||||
dao.mergeBucket = () =>
|
||||
{
|
||||
|
@ -43,7 +51,9 @@ describe( 'RatingService', () =>
|
|||
|
||||
const sut = Sut.extend(
|
||||
{
|
||||
'override postProcessRaterData'( data, actions, program, quote )
|
||||
'override postProcessRaterData'(
|
||||
request, data, actions, program, quote
|
||||
)
|
||||
{
|
||||
processed = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue