From 2c0bf764d1cb8cef86227f280622844a4dade8f8 Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Wed, 15 Aug 2018 14:06:07 -0400 Subject: [PATCH 1/7] [DEV-3393] Add more metadata to the init endpoint --- src/client/quote/ClientQuote.js | 28 +++++++++ src/quote/BaseQuote.js | 61 ++++++++++++++++++++ src/server/Server.js | 5 ++ test/client/quote/ClientQuoteTest.js | 86 ++++++++++++++++++++++++++++ test/quote/BaseQuoteTest.js | 65 +++++++++++++++++++++ 5 files changed, 245 insertions(+) create mode 100644 test/client/quote/ClientQuoteTest.js create mode 100644 test/quote/BaseQuoteTest.js diff --git a/src/client/quote/ClientQuote.js b/src/client/quote/ClientQuote.js index cc44889..acdcfb0 100644 --- a/src/client/quote/ClientQuote.js +++ b/src/client/quote/ClientQuote.js @@ -135,6 +135,10 @@ module.exports = Class( 'ClientQuote' ) .setCurrentStepId( data.currentStepId || 0 ) .setTopVisitedStepId( data.topVisitedStepId || 0 ) .setAgentId( data.agentId || 0 ) + .setAgentName( data.agentName || "" ) + .setAgentEntityId( data.agentEntityId || "" ) + .setStartDate( data.startDate || 0 ) + .setInitialRatedDate( data.initialRatedDate || 0 ) .setImported( data.imported || false ) .setBound( data.bound || false ) .needsImport( data.needsImport || false ) @@ -553,6 +557,14 @@ module.exports = Class( 'ClientQuote' ) 'public proxy getStartDate': '_quote', + /** + * Returns the quote's initial rated date + * + * @return {number} quote's initial rated date + */ + 'public proxy getInitialRatedDate': '_quote', + + /** * Returns the id of the agent that owns the quote * @@ -561,6 +573,22 @@ module.exports = Class( 'ClientQuote' ) 'public proxy getAgentId': '_quote', + /** + * Returns the name of the agent that owns the quote + * + * @return {string} agent name + */ + 'public proxy getAgentName': '_quote', + + + /** + * Returns the entity id of the agent that owns the quote + * + * @return {string} agent entity id + */ + 'public proxy getAgentEntityId': '_quote', + + /** * Returns whether the quote has been imported * diff --git a/src/quote/BaseQuote.js b/src/quote/BaseQuote.js index c44eece..8b146c6 100644 --- a/src/quote/BaseQuote.js +++ b/src/quote/BaseQuote.js @@ -80,12 +80,24 @@ module.exports = Class( 'BaseQuote' ) */ 'private _startDate': 0, + /** + * Date (UNIX timestamp) that the quote was initially rated + * @type {number} + */ + 'private _initialRatedDate': 0, + /** * Id of agent that owns the quote * @type {number} */ 'private _agentId': 0, + /** + * Id of agent entity that owns the quote + * @type {string} + */ + 'private _agentEntityId': '', + /** * Agency name * @type {string} @@ -235,6 +247,30 @@ module.exports = Class( 'BaseQuote' ) }, + /** + * Sets the quote's initial rated date + * + * @param {number} time initial rated date as a UNIX timestamp + * + * @return {Quote} self + */ + 'public setInitialRatedDate': function( time ) + { + this._initialRatedDate = +( time ); + return this; + }, + + /** + * Returns the quote's initial rated date + * + * @return {number} quote's initial rated date + */ + 'public getInitialRatedDate': function() + { + return this._initialRatedDate; + }, + + /** * Sets id of agent that owns the quote * @@ -260,6 +296,31 @@ module.exports = Class( 'BaseQuote' ) }, + /** + * Sets id of agent entity that owns the quote + * + * @param {string} id agent id + * + * @return {Quote} self + */ + 'public setAgentEntityId': function( id ) + { + this._agentEntityId = ''+( id ); + return this; + }, + + + /** + * Returns the id of the agent entity that owns the quote + * + * @return {string} agent entity id + */ + 'public getAgentEntityId': function() + { + return this._agentEntityId; + }, + + /** * Sets name of agent that owns the quote * diff --git a/src/server/Server.js b/src/server/Server.js index de66a8c..9c3536e 100644 --- a/src/server/Server.js +++ b/src/server/Server.js @@ -326,6 +326,8 @@ module.exports = Class( 'Server' ) .setQuickSaveData( quote_data.quicksave || {} ) .setAgentId( quote_data.agentId || agent_id ) .setAgentName( quote_data.agentName || agent_name ) + .setAgentEntityId( data.agentEntityId || "" ) + .setInitialRatedDate( data.initialRatedDate || 0 ) .setStartDate( quote_data.getStartDate || Math.round( new Date().getTime() / 1000 ) @@ -739,6 +741,9 @@ module.exports = Class( 'Server' ) explicitLockStepId: lock_step, agentId: quote.getAgentId(), agentName: quote.getAgentName(), + agentEntityId: quote.getAgentEntityId(), + startDate: quote.getStartDate(), + initialRatedDate: quote.getInitialRatedDate(), quicksave: quote.getQuickSaveData(), diff --git a/test/client/quote/ClientQuoteTest.js b/test/client/quote/ClientQuoteTest.js new file mode 100644 index 0000000..1c8f308 --- /dev/null +++ b/test/client/quote/ClientQuoteTest.js @@ -0,0 +1,86 @@ +/** + * Tests ClientQuote + * + * Copyright (C) 2017 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 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 General Public License + * along with this program. If not, see . + */ + +'use strict'; + +const chai = require( 'chai' ); +const expect = chai.expect; +const { BaseQuote } = require( '../../../' ).quote; +const { ClientQuote } = require( '../../../' ).client.quote; +const { QuoteDataBucket } = require( '../../../' ).bucket; + +chai.use( require( 'chai-as-promised' ) ); + +describe( 'ClientQuote', () => +{ + const baseQuote = BaseQuote( 123, QuoteDataBucket() ), + startDate = 12345, + agentId = 90000, + agentName = 'John Doe', + agentEntityId = '12434300', + initialRatedDate = 1531507748, + quote = ClientQuote( + baseQuote, + { + startDate: startDate, + agentId: agentId, + agentName: agentName, + agentEntityId: agentEntityId, + initialRatedDate: initialRatedDate, + }, + bucket => bucket + ); + + it( 'constructor', () => + { + expect( quote ).to.be.an.instanceof( ClientQuote ); + } ); + + it( 'getStartDate proxy', () => + { + expect( quote.getStartDate ).to.not.be.undefined; + expect( quote.getStartDate() ).to.equal( startDate ); + } ); + + it( 'getAgentId proxy', () => + { + expect( quote.getAgentId ).to.not.be.undefined; + expect( quote.getAgentId() ).to.equal( agentId ); + } ); + + it( 'getAgentName proxy', () => + { + expect( quote.getAgentName ).to.not.be.undefined; + expect( quote.getAgentName() ).to.equal( agentName ); + } ); + + it( 'getAgentEntityId proxy', () => + { + expect( quote.getAgentEntityId ).to.not.be.undefined; + expect( quote.getAgentEntityId() ).to.equal( agentEntityId ); + } ); + + it( 'getInitialRatedDate proxy', () => + { + expect( quote.getInitialRatedDate ).to.not.be.undefined; + expect( quote.getInitialRatedDate() ).to.equal( initialRatedDate ); + } ); +} ); diff --git a/test/quote/BaseQuoteTest.js b/test/quote/BaseQuoteTest.js new file mode 100644 index 0000000..746cbd7 --- /dev/null +++ b/test/quote/BaseQuoteTest.js @@ -0,0 +1,65 @@ +/** + * Tests BaseQuote + * + * Copyright (C) 2017 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 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 General Public License + * along with this program. If not, see . + */ + +'use strict'; + +const chai = require( 'chai' ); +const expect = chai.expect; +const { BaseQuote } = require( '../../' ).quote; + +chai.use( require( 'chai-as-promised' ) ); + +describe( 'BaseQuote', () => +{ + [ + { + property: 'startDate', + value: 12345 + }, + { + property: 'initialRatedDate', + value: 12345 + }, + { + property: 'agentEntityId', + value: 'AGT5432' + }, + ].forEach( testCase => + { + const quote = BaseQuote( 123, {} ), + property = testCase.property, + titleCased = property.charAt( 0 ).toUpperCase() + property.slice( 1 ), + setter = 'set' + titleCased, + getter = 'get' + titleCased; + + it( property, () => + { + expect( quote ).to.be.an.instanceof( BaseQuote ); + + expect( quote[setter] ).to.not.be.undefined; + expect( quote[getter] ).to.not.be.undefined; + expect( quote[getter].call( null ) ).to.be.undefined; + + quote[setter].call( null, testCase.value ); + expect( quote[getter].call( null ) ).to.equal( testCase.value ); + } ); + } ); +} ); From eb980f4fb777b3ec337e9ab03062317d30af5269 Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Wed, 15 Aug 2018 14:48:48 -0400 Subject: [PATCH 2/7] [DEV-3393] Replace UNIX with Unix --- src/quote/BaseQuote.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/quote/BaseQuote.js b/src/quote/BaseQuote.js index 8b146c6..319fc4e 100644 --- a/src/quote/BaseQuote.js +++ b/src/quote/BaseQuote.js @@ -75,13 +75,13 @@ module.exports = Class( 'BaseQuote' ) 'private _program': null, /** - * Date (UNIX timestamp) that the quote was started + * Date (Unix timestamp) that the quote was started * @type {number} */ 'private _startDate': 0, /** - * Date (UNIX timestamp) that the quote was initially rated + * Date (Unix timestamp) that the quote was initially rated * @type {number} */ 'private _initialRatedDate': 0, @@ -225,7 +225,7 @@ module.exports = Class( 'BaseQuote' ) /** * Sets the quote start date * - * @param {number} time start date as a UNIX timestamp + * @param {number} time start date as a Unix timestamp * * @return {Quote} self */ @@ -250,7 +250,7 @@ module.exports = Class( 'BaseQuote' ) /** * Sets the quote's initial rated date * - * @param {number} time initial rated date as a UNIX timestamp + * @param {number} time initial rated date as a Unix timestamp * * @return {Quote} self */ From 4b1fda57b8cbfca0f049dc4ef182300fdc176f0b Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Wed, 15 Aug 2018 15:05:21 -0400 Subject: [PATCH 3/7] [DEV-3393] minor changes to improve code quality --- src/client/quote/ClientQuote.js | 2 +- src/quote/BaseQuote.js | 2 +- test/client/quote/ClientQuoteTest.js | 60 +++++++++++----------------- test/quote/BaseQuoteTest.js | 21 ++++------ 4 files changed, 33 insertions(+), 52 deletions(-) diff --git a/src/client/quote/ClientQuote.js b/src/client/quote/ClientQuote.js index acdcfb0..ced0ce1 100644 --- a/src/client/quote/ClientQuote.js +++ b/src/client/quote/ClientQuote.js @@ -1,7 +1,7 @@ /** * Client-side quote * - * Copyright (C) 2017 R-T Specialty, LLC. + * Copyright (C) 2017, 2018 R-T Specialty, LLC. * * This file is part of the Liza Data Collection Framework. * diff --git a/src/quote/BaseQuote.js b/src/quote/BaseQuote.js index 319fc4e..9947dea 100644 --- a/src/quote/BaseQuote.js +++ b/src/quote/BaseQuote.js @@ -1,7 +1,7 @@ /** * Contains program Quote class * - * Copyright (C) 2017 R-T Specialty, LLC. + * Copyright (C) 2017, 2018 R-T Specialty, LLC. * * This file is part of the Liza Data Collection Framework. * diff --git a/test/client/quote/ClientQuoteTest.js b/test/client/quote/ClientQuoteTest.js index 1c8f308..cb3ad46 100644 --- a/test/client/quote/ClientQuoteTest.js +++ b/test/client/quote/ClientQuoteTest.js @@ -1,7 +1,7 @@ /** * Tests ClientQuote * - * Copyright (C) 2017 R-T Specialty, LLC. + * Copyright (C) 2018 R-T Specialty, LLC. * * This file is part of the Liza Data Collection Framework. * @@ -27,60 +27,48 @@ const { BaseQuote } = require( '../../../' ).quote; const { ClientQuote } = require( '../../../' ).client.quote; const { QuoteDataBucket } = require( '../../../' ).bucket; -chai.use( require( 'chai-as-promised' ) ); - describe( 'ClientQuote', () => { - const baseQuote = BaseQuote( 123, QuoteDataBucket() ), - startDate = 12345, - agentId = 90000, - agentName = 'John Doe', - agentEntityId = '12434300', - initialRatedDate = 1531507748, - quote = ClientQuote( - baseQuote, + const base_quote = BaseQuote( 123, QuoteDataBucket() ); + const start_date = 12345; + const agent_id = 90000; + const agent_name = 'John Doe'; + const agent_entity_id = '12434300'; + const initial_rated_date = 1531507748; + const quote = ClientQuote( + base_quote, { - startDate: startDate, - agentId: agentId, - agentName: agentName, - agentEntityId: agentEntityId, - initialRatedDate: initialRatedDate, + startDate: start_date, + agentId: agent_id, + agentName: agent_name, + agentEntityId: agent_entity_id, + initialRatedDate: initial_rated_date, }, bucket => bucket ); - it( 'constructor', () => + it( 'getStartDate returns base quote startDate', () => { - expect( quote ).to.be.an.instanceof( ClientQuote ); + expect( quote.getStartDate() ).to.equal( start_date ); } ); - it( 'getStartDate proxy', () => + it( 'getAgentId returns base quote agentId', () => { - expect( quote.getStartDate ).to.not.be.undefined; - expect( quote.getStartDate() ).to.equal( startDate ); + expect( quote.getAgentId() ).to.equal( agent_id ); } ); - it( 'getAgentId proxy', () => + it( 'getAgentName returns base quote agentName', () => { - expect( quote.getAgentId ).to.not.be.undefined; - expect( quote.getAgentId() ).to.equal( agentId ); + expect( quote.getAgentName() ).to.equal( agent_name ); } ); - it( 'getAgentName proxy', () => + it( 'getAgentEntityId returns base quote agentEntityId', () => { - expect( quote.getAgentName ).to.not.be.undefined; - expect( quote.getAgentName() ).to.equal( agentName ); + expect( quote.getAgentEntityId() ).to.equal( agent_entity_id ); } ); - it( 'getAgentEntityId proxy', () => + it( 'getInitialRatedDate returns base quote initialRatedDate', () => { - expect( quote.getAgentEntityId ).to.not.be.undefined; - expect( quote.getAgentEntityId() ).to.equal( agentEntityId ); - } ); - - it( 'getInitialRatedDate proxy', () => - { - expect( quote.getInitialRatedDate ).to.not.be.undefined; - expect( quote.getInitialRatedDate() ).to.equal( initialRatedDate ); + expect( quote.getInitialRatedDate() ).to.equal( initial_rated_date ); } ); } ); diff --git a/test/quote/BaseQuoteTest.js b/test/quote/BaseQuoteTest.js index 746cbd7..401e3d9 100644 --- a/test/quote/BaseQuoteTest.js +++ b/test/quote/BaseQuoteTest.js @@ -1,7 +1,7 @@ /** * Tests BaseQuote * - * Copyright (C) 2017 R-T Specialty, LLC. + * Copyright (C) 2018 R-T Specialty, LLC. * * This file is part of the Liza Data Collection Framework. * @@ -25,8 +25,6 @@ const chai = require( 'chai' ); const expect = chai.expect; const { BaseQuote } = require( '../../' ).quote; -chai.use( require( 'chai-as-promised' ) ); - describe( 'BaseQuote', () => { [ @@ -44,20 +42,15 @@ describe( 'BaseQuote', () => }, ].forEach( testCase => { - const quote = BaseQuote( 123, {} ), - property = testCase.property, - titleCased = property.charAt( 0 ).toUpperCase() + property.slice( 1 ), - setter = 'set' + titleCased, - getter = 'get' + titleCased; + const quote = BaseQuote( 123, {} ); + const property = testCase.property; + const title_cased = property.charAt( 0 ).toUpperCase() + property.slice( 1 ); + const setter = 'set' + title_cased; + const getter = 'get' + title_cased; - it( property, () => + it( property + ' can be mutated and accessed', () => { - expect( quote ).to.be.an.instanceof( BaseQuote ); - - expect( quote[setter] ).to.not.be.undefined; - expect( quote[getter] ).to.not.be.undefined; expect( quote[getter].call( null ) ).to.be.undefined; - quote[setter].call( null, testCase.value ); expect( quote[getter].call( null ) ).to.equal( testCase.value ); } ); From 52491c1ce0814936959be6571b53ed6fdba5bba3 Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Wed, 15 Aug 2018 15:10:13 -0400 Subject: [PATCH 4/7] [DEV-3393] The entity id should not be sent unless the request is internal. --- src/server/Server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/Server.js b/src/server/Server.js index 9c3536e..19cab52 100644 --- a/src/server/Server.js +++ b/src/server/Server.js @@ -741,7 +741,7 @@ module.exports = Class( 'Server' ) explicitLockStepId: lock_step, agentId: quote.getAgentId(), agentName: quote.getAgentName(), - agentEntityId: quote.getAgentEntityId(), + agentEntityId: ( internal ) ? quote.getAgentEntityId() : 0, startDate: quote.getStartDate(), initialRatedDate: quote.getInitialRatedDate(), From c61c1196c4357f1d9c705a42d5994c23fdad302d Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Wed, 15 Aug 2018 15:14:10 -0400 Subject: [PATCH 5/7] [DEV-3393] Chnage property type to correct type --- src/quote/BaseQuote.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/quote/BaseQuote.js b/src/quote/BaseQuote.js index 9947dea..6a6e6ba 100644 --- a/src/quote/BaseQuote.js +++ b/src/quote/BaseQuote.js @@ -299,13 +299,13 @@ module.exports = Class( 'BaseQuote' ) /** * Sets id of agent entity that owns the quote * - * @param {string} id agent id + * @param {number} id agent entity id * * @return {Quote} self */ 'public setAgentEntityId': function( id ) { - this._agentEntityId = ''+( id ); + this._agentEntityId = ( id ); return this; }, @@ -313,7 +313,7 @@ module.exports = Class( 'BaseQuote' ) /** * Returns the id of the agent entity that owns the quote * - * @return {string} agent entity id + * @return {number} agent entity id */ 'public getAgentEntityId': function() { From 11a565422a1f50a847a82322852eacfd5b3bc9a3 Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Wed, 15 Aug 2018 16:13:35 -0400 Subject: [PATCH 6/7] [DEV-3393] Use the correct variable name --- src/server/Server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/Server.js b/src/server/Server.js index 19cab52..6fd7127 100644 --- a/src/server/Server.js +++ b/src/server/Server.js @@ -326,8 +326,8 @@ module.exports = Class( 'Server' ) .setQuickSaveData( quote_data.quicksave || {} ) .setAgentId( quote_data.agentId || agent_id ) .setAgentName( quote_data.agentName || agent_name ) - .setAgentEntityId( data.agentEntityId || "" ) - .setInitialRatedDate( data.initialRatedDate || 0 ) + .setAgentEntityId( quote_data.agentEntityId || "" ) + .setInitialRatedDate( quote_data.initialRatedDate || 0 ) .setStartDate( quote_data.getStartDate || Math.round( new Date().getTime() / 1000 ) From b4ecb5a14c160bfb3973c32d8a5915619e15ec52 Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Thu, 16 Aug 2018 07:35:52 -0400 Subject: [PATCH 7/7] [DEV-3393] Made sure the entity id is a number --- src/quote/BaseQuote.js | 6 +++--- test/client/quote/ClientQuoteTest.js | 2 +- test/quote/BaseQuoteTest.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/quote/BaseQuote.js b/src/quote/BaseQuote.js index 6a6e6ba..05df67b 100644 --- a/src/quote/BaseQuote.js +++ b/src/quote/BaseQuote.js @@ -94,9 +94,9 @@ module.exports = Class( 'BaseQuote' ) /** * Id of agent entity that owns the quote - * @type {string} + * @type {number} */ - 'private _agentEntityId': '', + 'private _agentEntityId': 0, /** * Agency name @@ -305,7 +305,7 @@ module.exports = Class( 'BaseQuote' ) */ 'public setAgentEntityId': function( id ) { - this._agentEntityId = ( id ); + this._agentEntityId = +id; return this; }, diff --git a/test/client/quote/ClientQuoteTest.js b/test/client/quote/ClientQuoteTest.js index cb3ad46..3ad9260 100644 --- a/test/client/quote/ClientQuoteTest.js +++ b/test/client/quote/ClientQuoteTest.js @@ -33,7 +33,7 @@ describe( 'ClientQuote', () => const start_date = 12345; const agent_id = 90000; const agent_name = 'John Doe'; - const agent_entity_id = '12434300'; + const agent_entity_id = 12434300; const initial_rated_date = 1531507748; const quote = ClientQuote( base_quote, diff --git a/test/quote/BaseQuoteTest.js b/test/quote/BaseQuoteTest.js index 401e3d9..9c6b8cd 100644 --- a/test/quote/BaseQuoteTest.js +++ b/test/quote/BaseQuoteTest.js @@ -38,7 +38,7 @@ describe( 'BaseQuote', () => }, { property: 'agentEntityId', - value: 'AGT5432' + value: 12434300 }, ].forEach( testCase => {