[DEV-5333] Pass last rated date from the server quote back to the client quote
Correct and add more elaborate tests for RateEventHandlermaster
parent
23889cbfca
commit
9637fc22e1
|
@ -141,7 +141,7 @@ module.exports = Class( 'RateEventHandler' )
|
|||
this._dataProxy.get( this._genRateUrl( quote, indv ),
|
||||
function( response, err )
|
||||
{
|
||||
const { initialRatedDate: initial_rated = 0, data = {} } = response.content || {};
|
||||
const { initialRatedDate: initial_rated = 0, lastRatedDate: last_rated = 0, data = {} } = response.content || {};
|
||||
|
||||
if ( err )
|
||||
{
|
||||
|
@ -155,6 +155,7 @@ module.exports = Class( 'RateEventHandler' )
|
|||
quote.refreshData( data );
|
||||
|
||||
quote.setInitialRatedDate( initial_rated );
|
||||
quote.setLastPremiumDate( last_rated );
|
||||
|
||||
// let subtypes handle additional processing
|
||||
_self.postRate( err, data, _self._client, quote );
|
||||
|
|
|
@ -139,6 +139,7 @@ module.exports = Class( 'ClientQuote' )
|
|||
.setAgentEntityId( data.agentEntityId || "" )
|
||||
.setStartDate( data.startDate || 0 )
|
||||
.setInitialRatedDate( data.initialRatedDate || 0 )
|
||||
.setLastPremiumDate( data.lastRatedDate || 0 )
|
||||
.setImported( data.imported || false )
|
||||
.setBound( data.bound || false )
|
||||
.needsImport( data.needsImport || false )
|
||||
|
@ -575,6 +576,24 @@ module.exports = Class( 'ClientQuote' )
|
|||
'public proxy setInitialRatedDate': '_quote',
|
||||
|
||||
|
||||
/**
|
||||
* Set the date that the premium was calculated as a Unix timestamp
|
||||
*
|
||||
* @param {number} timestamp Unix timestamp representing premium date
|
||||
*
|
||||
* @return {Quote} self
|
||||
*/
|
||||
'public proxy setLastPremiumDate': '_quote',
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the last time the premium was calculated
|
||||
*
|
||||
* @return {number} last calculated time or 0
|
||||
*/
|
||||
'public proxy getLastPremiumDate': '_quote',
|
||||
|
||||
|
||||
/**
|
||||
* Returns the quote's expiration date
|
||||
*
|
||||
|
|
|
@ -85,6 +85,12 @@ module.exports = Class( 'BaseQuote' )
|
|||
*/
|
||||
'private _initialRatedDate': 0,
|
||||
|
||||
/**
|
||||
* Unix timestamp containing date of last premium calculation
|
||||
* @type {number}
|
||||
*/
|
||||
'private _lastPremDate': 0,
|
||||
|
||||
/**
|
||||
* Id of agent that owns the quote
|
||||
* @type {number}
|
||||
|
@ -270,6 +276,31 @@ module.exports = Class( 'BaseQuote' )
|
|||
},
|
||||
|
||||
|
||||
/**
|
||||
* Set the date that the premium was calculated as a Unix timestamp
|
||||
*
|
||||
* @param {number} timestamp Unix timestamp representing premium date
|
||||
*
|
||||
* @return {Quote} self
|
||||
*/
|
||||
'public setLastPremiumDate': function( timestamp )
|
||||
{
|
||||
this._lastPremDate = ( timestamp || 0 );
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the last time the premium was calculated
|
||||
*
|
||||
* @return {number} last calculated time or 0
|
||||
*/
|
||||
'public getLastPremiumDate': function()
|
||||
{
|
||||
return ( this._lastPremDate || 0 );
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Returns the quote's expiration date
|
||||
*
|
||||
|
|
|
@ -40,11 +40,6 @@ module.exports = Class( 'ServerSideQuote' )
|
|||
*/
|
||||
'private _creditScoreRef': 0,
|
||||
|
||||
/**
|
||||
* Unix timestamp containing date of last premium calculation
|
||||
* @type {number}
|
||||
*/
|
||||
'private _lastPremDate': 0,
|
||||
|
||||
/**
|
||||
* Unix timestamp containing date of first premium calculation
|
||||
|
@ -85,20 +80,6 @@ module.exports = Class( 'ServerSideQuote' )
|
|||
},
|
||||
|
||||
|
||||
/**
|
||||
* Set the date that the premium was calculated as a Unix timestamp
|
||||
*
|
||||
* @param {number} timestamp Unix timestamp representing premium date
|
||||
*
|
||||
* @return {Quote} self
|
||||
*/
|
||||
'public setLastPremiumDate': function( timestamp )
|
||||
{
|
||||
this._lastPremDate = ( timestamp || 0 );
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Set the timestamp of the first time quote was rated
|
||||
*
|
||||
|
@ -118,17 +99,6 @@ module.exports = Class( 'ServerSideQuote' )
|
|||
},
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the last time the premium was calculated
|
||||
*
|
||||
* @return {number} last calculated time or 0
|
||||
*/
|
||||
'public getLastPremiumDate': function()
|
||||
{
|
||||
return ( this._lastPremDate || 0 );
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* If the quote has been rated
|
||||
*
|
||||
|
|
|
@ -178,8 +178,9 @@ module.exports = Class( 'RatingService',
|
|||
|
||||
// no need to wait for the save; send the response
|
||||
_self._server.sendResponse( request, quote, {
|
||||
data: cleaned,
|
||||
initialRatedDate: quote.getInitialRatedDate()
|
||||
data: cleaned,
|
||||
initialRatedDate: quote.getRatedDate(),
|
||||
lastRatedDate: quote.getLastPremiumDate()
|
||||
}, actions );
|
||||
},
|
||||
function( message )
|
||||
|
@ -217,7 +218,6 @@ module.exports = Class( 'RatingService',
|
|||
|
||||
quote.setLastPremiumDate( cur_date );
|
||||
quote.setRatedDate( cur_date );
|
||||
quote.setInitialRatedDate( cur_date );
|
||||
|
||||
function done()
|
||||
{
|
||||
|
|
|
@ -53,6 +53,7 @@ exports.getStubs = function()
|
|||
mergeBucket: () => {},
|
||||
saveQuoteClasses: () => {},
|
||||
setWorksheets: () => {},
|
||||
saveQuote: () => {},
|
||||
};
|
||||
|
||||
const session = {
|
||||
|
@ -60,15 +61,19 @@ exports.getStubs = function()
|
|||
};
|
||||
|
||||
const request = {
|
||||
getSession: () => session,
|
||||
getSession: () => session,
|
||||
getSessionIdName: () => {},
|
||||
};
|
||||
const response = {};
|
||||
|
||||
const quote = {
|
||||
getProgramId: () => program_id,
|
||||
getProgram: () => program,
|
||||
getId: () => 0,
|
||||
getProgramId: () => program_id,
|
||||
getProgram: () => program,
|
||||
getId: () => 0,
|
||||
setLastPremiumDate: () => {},
|
||||
setRatedDate: () => {},
|
||||
getRatedDate: () => 0,
|
||||
getLastPremiumDate: () => 0
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
@ -26,20 +26,40 @@ const Sut = require( '../../..' ).client.event.RateEventHandler;
|
|||
|
||||
describe( 'RateEventHandler', () =>
|
||||
{
|
||||
describe( "Handle Rating Event", () =>
|
||||
describe( "Handle Rating Event with all conditions met for clean rating", () =>
|
||||
{
|
||||
it( "calls #handle to do the rating", done =>
|
||||
{
|
||||
const stepId = 0;
|
||||
const lockStep = 1;
|
||||
let test_init_date = false;
|
||||
let test_last_prem_date = false;
|
||||
let test_lock_quote = false;
|
||||
|
||||
const stepId = 1;
|
||||
const lockStep = 0;
|
||||
const indv = "somerater";
|
||||
const initial_rated_date = 111;
|
||||
const last_premium_date = 222;
|
||||
|
||||
const quote = {
|
||||
getExplicitLockStep: () => lockStep,
|
||||
setInitialRatedDate: ( value ) => {},
|
||||
setLastPremiumDate: given =>
|
||||
{
|
||||
expect( given ).to.equal( last_premium_date );
|
||||
test_init_date = true;
|
||||
},
|
||||
setInitialRatedDate: given =>
|
||||
{
|
||||
expect( given ).to.equal( initial_rated_date );
|
||||
test_last_prem_date = true;
|
||||
},
|
||||
getCurrentStepId: () => stepId,
|
||||
refreshData: () => {},
|
||||
isLocked: () => false
|
||||
isLocked: given =>
|
||||
{
|
||||
test_lock_quote = true;
|
||||
return false;
|
||||
},
|
||||
getId: () => "111111"
|
||||
};
|
||||
|
||||
const step = {
|
||||
|
@ -51,6 +71,7 @@ describe( 'RateEventHandler', () =>
|
|||
};
|
||||
|
||||
const client = {
|
||||
showRatingInProgressDialog: () => "Some Dialog",
|
||||
getQuote: () => quote,
|
||||
isSaving: () => false,
|
||||
once: ( event, callback ) => {},
|
||||
|
@ -59,11 +80,13 @@ describe( 'RateEventHandler', () =>
|
|||
|
||||
const response = {
|
||||
content: {
|
||||
data: "Some Data"
|
||||
data: "Some Data",
|
||||
initialRatedDate: initial_rated_date,
|
||||
lastRatedDate: last_premium_date
|
||||
}
|
||||
};
|
||||
|
||||
const error = "ERROR";
|
||||
const error = null;
|
||||
|
||||
const proxy = {
|
||||
get: ( url, callback ) => callback( response, error )
|
||||
|
@ -71,11 +94,159 @@ describe( 'RateEventHandler', () =>
|
|||
|
||||
const sut = Sut( client, proxy );
|
||||
|
||||
sut.handle( "", function() {}, {
|
||||
indv: indv,
|
||||
stepId: stepId
|
||||
} );
|
||||
done();
|
||||
sut.handle(
|
||||
"",
|
||||
( err, result ) =>
|
||||
{
|
||||
expect( err ).to.equal( error );
|
||||
expect( result ).to.equal( response.content.data );
|
||||
expect( test_init_date ).to.equal( true );
|
||||
expect( test_last_prem_date ).to.equal( true );
|
||||
expect( test_lock_quote ).to.equal( true );
|
||||
done();
|
||||
},
|
||||
{
|
||||
indv: indv,
|
||||
stepId: stepId
|
||||
}
|
||||
)
|
||||
|
||||
} )
|
||||
} )
|
||||
} );
|
||||
|
||||
describe( "Handle Rating Event with locked quote", () =>
|
||||
{
|
||||
it( "calls #handle to do the rating with a locked quote", done =>
|
||||
{
|
||||
|
||||
let test_lock_quote = false;
|
||||
|
||||
const stepId = 1;
|
||||
const lockStep = 0;
|
||||
const indv = "somerater";
|
||||
const error = null;
|
||||
const proxy = {
|
||||
get: ( url, callback ) => callback( response, error )
|
||||
};
|
||||
|
||||
const quote = {
|
||||
getExplicitLockStep: () => lockStep,
|
||||
getCurrentStepId: () => stepId,
|
||||
isLocked: given =>
|
||||
{
|
||||
test_lock_quote = true;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
const client = {
|
||||
getQuote: () => quote,
|
||||
isSaving: () => false,
|
||||
getUi: () => ui
|
||||
};
|
||||
|
||||
|
||||
const sut = Sut( client, proxy );
|
||||
|
||||
sut.handle(
|
||||
"",
|
||||
( err, result ) =>
|
||||
{
|
||||
expect( test_lock_quote ).to.equal( true );
|
||||
done();
|
||||
},
|
||||
{
|
||||
indv: indv,
|
||||
stepId: stepId
|
||||
}
|
||||
)
|
||||
} )
|
||||
} );
|
||||
|
||||
describe( "Handle Rating Event during a save event", () =>
|
||||
{
|
||||
it( "calls #handle to do the rating with a saving quote", done =>
|
||||
{
|
||||
let test_init_date = false;
|
||||
let test_last_prem_date = false;
|
||||
let test_save_quote = false;
|
||||
|
||||
const stepId = 1;
|
||||
const lockStep = 0;
|
||||
const indv = "somerater";
|
||||
const initial_rated_date = 111;
|
||||
const last_premium_date = 222;
|
||||
|
||||
const quote = {
|
||||
getExplicitLockStep: () => lockStep,
|
||||
setLastPremiumDate: given =>
|
||||
{
|
||||
expect( given ).to.equal( last_premium_date );
|
||||
test_init_date = true;
|
||||
},
|
||||
setInitialRatedDate: given =>
|
||||
{
|
||||
expect( given ).to.equal( initial_rated_date );
|
||||
test_last_prem_date = true;
|
||||
},
|
||||
getCurrentStepId: () => stepId,
|
||||
refreshData: () => {},
|
||||
isLocked: () => false,
|
||||
getId: () => "111111"
|
||||
};
|
||||
|
||||
const step = {
|
||||
invalidate: () => {}
|
||||
};
|
||||
|
||||
const ui = {
|
||||
getStep: ( dest ) => step
|
||||
};
|
||||
|
||||
const client = {
|
||||
showRatingInProgressDialog: () => "Some Dialog",
|
||||
getQuote: () => quote,
|
||||
isSaving: given =>
|
||||
{
|
||||
test_save_quote = true;
|
||||
return true;
|
||||
},
|
||||
once: ( event, callback ) => callback(),
|
||||
getUi: () => ui
|
||||
};
|
||||
|
||||
const response = {
|
||||
content: {
|
||||
data: "Some Data",
|
||||
initialRatedDate: initial_rated_date,
|
||||
lastRatedDate: last_premium_date
|
||||
}
|
||||
};
|
||||
|
||||
const error = null;
|
||||
|
||||
const proxy = {
|
||||
get: ( url, callback ) => callback( response, error )
|
||||
};
|
||||
|
||||
const sut = Sut( client, proxy );
|
||||
|
||||
sut.handle(
|
||||
"",
|
||||
( err, result ) =>
|
||||
{
|
||||
expect( err ).to.equal( error );
|
||||
expect( result ).to.equal( response.content.data );
|
||||
expect( test_init_date ).to.equal( true );
|
||||
expect( test_last_prem_date ).to.equal( true );
|
||||
expect( test_save_quote ).to.equal( true );
|
||||
done();
|
||||
},
|
||||
{
|
||||
indv: indv,
|
||||
stepId: stepId
|
||||
}
|
||||
)
|
||||
} )
|
||||
} );
|
||||
} )
|
||||
|
|
|
@ -35,16 +35,18 @@ describe( 'ClientQuote', () =>
|
|||
const agent_name = 'John Doe';
|
||||
const agent_entity_id = 12434300;
|
||||
const initial_rated_date = 1531507748;
|
||||
const last_rated_date = 1531508748;
|
||||
const quote = ClientQuote(
|
||||
base_quote,
|
||||
{
|
||||
startDate: start_date,
|
||||
agentId: agent_id,
|
||||
agentName: agent_name,
|
||||
agentEntityId: agent_entity_id,
|
||||
startDate: start_date,
|
||||
agentId: agent_id,
|
||||
agentName: agent_name,
|
||||
agentEntityId: agent_entity_id,
|
||||
initialRatedDate: initial_rated_date,
|
||||
lastRatedDate: last_rated_date,
|
||||
},
|
||||
bucket => bucket
|
||||
bucket => bucket
|
||||
);
|
||||
|
||||
it( 'getStartDate returns base quote startDate', () =>
|
||||
|
@ -71,4 +73,9 @@ describe( 'ClientQuote', () =>
|
|||
{
|
||||
expect( quote.getInitialRatedDate() ).to.equal( initial_rated_date );
|
||||
} );
|
||||
|
||||
it( 'getLastPremiumDate returns base quote lastRatedDate', () =>
|
||||
{
|
||||
expect( quote.getLastPremiumDate() ).to.equal( last_rated_date );
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -179,8 +179,8 @@ describe( 'RatingServiceSubmitNotify', () =>
|
|||
// only save notification status if we're notifying
|
||||
expect( notify_saved ).to.equal( expected.save );
|
||||
|
||||
done();
|
||||
} );
|
||||
done();
|
||||
} )
|
||||
);
|
||||
} );
|
||||
|
|
|
@ -61,5 +61,45 @@ describe( 'RatingService', () =>
|
|||
|
||||
sut.request( request, response, quote, 'something', () => {} );
|
||||
} );
|
||||
|
||||
it( "calls getLastPremiumDate during #_performRating", done =>
|
||||
{
|
||||
let getLastPremiumDateCallCount = 0;
|
||||
|
||||
const last_date = 1234;
|
||||
const initial_date = 2345;
|
||||
|
||||
const {
|
||||
logger,
|
||||
server,
|
||||
raters,
|
||||
dao,
|
||||
request,
|
||||
response,
|
||||
quote,
|
||||
} = RatingServiceStub.getStubs();
|
||||
|
||||
quote.getLastPremiumDate = () =>
|
||||
{
|
||||
getLastPremiumDateCallCount++;
|
||||
return last_date
|
||||
};
|
||||
|
||||
quote.getRatedDate = () => initial_date;
|
||||
|
||||
const sut = Sut( logger, dao, server, raters );
|
||||
|
||||
server.sendResponse = ( request, quote, resp, actions ) =>
|
||||
{
|
||||
expect( getLastPremiumDateCallCount ).to.equal( 2 );
|
||||
expect( resp.initialRatedDate ).to.equal( initial_date );
|
||||
expect( resp.lastRatedDate ).to.equal( last_date );
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
sut.request( request, response, quote, null, () => {} );
|
||||
} );
|
||||
|
||||
} );
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue