[DEV-5333] Expose formatted expiration date
commit
823e91c8bb
|
@ -274,7 +274,7 @@ exports.relativeDate = function( data, value )
|
|||
|
||||
// days
|
||||
case 'd':
|
||||
date_new.setDay( date_new.getDay() + +tval );
|
||||
date_new.setDate( date_new.getUTCDate() + +tval );
|
||||
break;
|
||||
|
||||
// seconds
|
||||
|
|
|
@ -141,7 +141,7 @@ module.exports = Class( 'RateEventHandler' )
|
|||
this._dataProxy.get( this._genRateUrl( quote, indv ),
|
||||
function( response, err )
|
||||
{
|
||||
var data = ( response.content.data || {} );
|
||||
const { initialRatedDate: initial_rated = 0, lastRatedDate: last_rated = 0, data = {} } = response.content || {};
|
||||
|
||||
if ( err )
|
||||
{
|
||||
|
@ -154,6 +154,9 @@ module.exports = Class( 'RateEventHandler' )
|
|||
// save only; no transport is specified)
|
||||
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 )
|
||||
|
@ -565,6 +566,42 @@ module.exports = Class( 'ClientQuote' )
|
|||
'public proxy getInitialRatedDate': '_quote',
|
||||
|
||||
|
||||
/**
|
||||
* Sets the quote's initial rated date
|
||||
*
|
||||
* @param {number} time initial rated date as a Unix timestamp
|
||||
*
|
||||
* @return {Quote} self
|
||||
*/
|
||||
'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
|
||||
*
|
||||
* @return {number} quote's initial rated date
|
||||
*/
|
||||
'public proxy getExpirationDate': '_quote',
|
||||
|
||||
|
||||
/**
|
||||
* Returns the id of the agent that owns the quote
|
||||
*
|
||||
|
|
|
@ -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,7 +178,9 @@ module.exports = Class( 'RatingService',
|
|||
|
||||
// no need to wait for the save; send the response
|
||||
_self._server.sendResponse( request, quote, {
|
||||
data: cleaned
|
||||
data: cleaned,
|
||||
initialRatedDate: quote.getRatedDate(),
|
||||
lastRatedDate: quote.getLastPremiumDate()
|
||||
}, actions );
|
||||
},
|
||||
function( message )
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,252 @@
|
|||
/**
|
||||
* Tests RateEventHandler
|
||||
*
|
||||
* Copyright (C) 2019, 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/>.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const { expect } = require( 'chai' );
|
||||
const Sut = require( '../../..' ).client.event.RateEventHandler;
|
||||
|
||||
describe( 'RateEventHandler', () =>
|
||||
{
|
||||
describe( "Handle Rating Event with all conditions met for clean rating", () =>
|
||||
{
|
||||
it( "calls #handle to do the rating", done =>
|
||||
{
|
||||
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,
|
||||
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: given =>
|
||||
{
|
||||
test_lock_quote = true;
|
||||
return false;
|
||||
},
|
||||
getId: () => "111111"
|
||||
};
|
||||
|
||||
const step = {
|
||||
invalidate: () => {}
|
||||
};
|
||||
|
||||
const ui = {
|
||||
getStep: ( dest ) => step
|
||||
};
|
||||
|
||||
const client = {
|
||||
showRatingInProgressDialog: () => "Some Dialog",
|
||||
getQuote: () => quote,
|
||||
isSaving: () => false,
|
||||
once: ( event, 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_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 );
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -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