Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorCorey Vollmer <corey.vollmer@ryansg.com>2019-05-21 11:41:18 -0400
committerAndrew Fanton <andrew.fanton@ryansg.com>2019-05-21 14:03:05 -0400
commit14869d9041c4ed35f7cfd7d55a9edd56ea909c18 (patch)
tree343365b4fd61bf1f9161d427a8ae8bd864d6717b /test
parent1ab1ecc2d4c0c9230cec6fcfe42de9dfe4351bf6 (diff)
downloadliza-14869d9041c4ed35f7cfd7d55a9edd56ea909c18.tar.gz
liza-14869d9041c4ed35f7cfd7d55a9edd56ea909c18.tar.bz2
liza-14869d9041c4ed35f7cfd7d55a9edd56ea909c18.zip
[DEV-3514] Add more robust testing for BasicQuote
Also, updated README to include instructions on `npm install.`
Diffstat (limited to 'test')
-rw-r--r--test/quote/BaseQuoteTest.js210
1 files changed, 188 insertions, 22 deletions
diff --git a/test/quote/BaseQuoteTest.js b/test/quote/BaseQuoteTest.js
index 9c6b8cd..1607bb3 100644
--- a/test/quote/BaseQuoteTest.js
+++ b/test/quote/BaseQuoteTest.js
@@ -27,32 +27,198 @@ const { BaseQuote } = require( '../../' ).quote;
describe( 'BaseQuote', () =>
{
- [
- {
- property: 'startDate',
- value: 12345
- },
- {
- property: 'initialRatedDate',
- value: 12345
- },
+ describe( 'accessors & mutators', () =>
+ {
+ [
+ {
+ property: 'startDate',
+ default: 0,
+ value: 946684800
+ },
+ {
+ property: 'initialRatedDate',
+ default: 0,
+ value: 946684800
+ },
+ {
+ property: 'agentId',
+ default: 0,
+ value: 12345678
+ },
+ {
+ property: 'agentEntityId',
+ default: 0,
+ value: 12345678
+ },
+ {
+ property: 'agentName',
+ default: '',
+ value: 'name'
+ },
+ {
+ property: 'imported',
+ default: false,
+ value: true,
+ accessor: 'is'
+ },
+ {
+ property: 'bound',
+ default: false,
+ value: true,
+ accessor: 'is'
+ },
+ {
+ property: 'currentStepId',
+ default: 1,
+ value: 2
+ },
+ {
+ property: 'topVisitedStepId',
+ default: 1,
+ value: 2
+ },
+ {
+ property: 'topSavedStepId',
+ value: 1
+ },
+ {
+ property: 'error',
+ default: '',
+ value: 'ERROR'
+ }
+
+ ].forEach( testCase =>
{
- property: 'agentEntityId',
- value: 12434300
- },
- ].forEach( testCase =>
+ const quote = BaseQuote( 123, {} );
+ const property = testCase.property;
+ const title_cased = property.charAt( 0 ).toUpperCase() + property.slice( 1 );
+ const setter = ( testCase.mutator || 'set' ) + title_cased;
+ const getter = ( testCase.accessor || 'get' ) + title_cased;
+
+ it( property + ' can be mutated and accessed', () =>
+ {
+ expect( quote[getter].call( quote ) ).to.equal( testCase.default );
+ quote[setter].call( quote, testCase.value );
+ expect( quote[getter].call( quote ) ).to.equal( testCase.value );
+ } );
+ } );
+ } );
+
+ describe( 'locking mechanisms', () =>
{
- 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;
+ [
+ {
+ description: 'default values',
+ reason: '',
+ step: 0,
+ bound: false,
+ imported: false,
+ locks: false
+ },
+ {
+ description: 'quote with a reason',
+ reason: 'reason',
+ step: 0,
+ bound: false,
+ imported: false,
+ locks: true
+ },
+ {
+ description: 'quote with a lock on step #2',
+ reason: '',
+ step: 2,
+ bound: false,
+ imported: false,
+ locks: false
+ },
+ {
+ description: 'quote with a reason and a lock on step #2',
+ reason: 'reason',
+ step: 2,
+ bound: false,
+ imported: false,
+ locks: false
+ },
+ {
+ description: 'bound quote',
+ reason: { given: '', expected: 'Quote has been bound' },
+ step: 0,
+ bound: true,
+ imported: false,
+ locks: true
+ },
+ {
+ description: 'imported quote',
+ reason: '',
+ step: 0,
+ bound: false,
+ imported: true,
+ locks: true
+ },
+ {
+ description: 'bound and imported quote',
+ reason: { given: '', expected: 'Quote has been bound' },
+ step: 0,
+ bound: true,
+ imported: true,
+ locks: true
+ },
+ {
+ description: 'bound quote with a lock on step #2',
+ reason: { given: '', expected: 'Quote has been bound' },
+ step: { given: 2, expected: 0 },
+ bound: true,
+ imported: false,
+ locks: true
+ },
+ {
+ description: 'imported quote with a lock on step #2',
+ reason: '',
+ step: 2,
+ bound: false,
+ imported: true,
+ locks: false
+ }
- it( property + ' can be mutated and accessed', () =>
+ ].forEach( testCase =>
{
- expect( quote[getter].call( null ) ).to.be.undefined;
- quote[setter].call( null, testCase.value );
- expect( quote[getter].call( null ) ).to.equal( testCase.value );
+ const quote = BaseQuote( 123, {} );
+ const description = 'Locking is correct for ' + testCase.description;
+ const bound = !!testCase.bound;
+ const imported = !!testCase.imported;
+ const locks = !!testCase.locks;
+
+ const givenReason = ( testCase.reason.given !== undefined ) ?
+ '' + testCase.reason.given :
+ '' + testCase.reason;
+ const expectedReason = ( testCase.reason.expected !== undefined ) ?
+ '' + testCase.reason.expected :
+ '' + testCase.reason;
+
+ const givenStep = ( testCase.step.given !== undefined ) ?
+ +testCase.step.given :
+ +testCase.step;
+ const expectedStep = ( testCase.step.expected !== undefined ) ?
+ +testCase.step.expected :
+ +testCase.step;
+
+ it( description, () =>
+ {
+ expect( quote.getExplicitLockReason() ).to.equal( '' );
+ expect( quote.getExplicitLockStep() ).to.equal( 0 );
+
+ quote.setBound( bound )
+ .setImported( imported )
+ .setExplicitLock( givenReason, givenStep );
+
+ expect( quote.getExplicitLockReason() ).to.equal( expectedReason );
+ expect( quote.getExplicitLockStep() ).to.equal( expectedStep );
+ expect( quote.isLocked() ).to.equal( locks );
+
+ quote.clearExplicitLock();
+ expect( quote.getExplicitLockReason() ).to.equal( bound ? 'Quote has been bound' : '' );
+ expect( quote.getExplicitLockStep() ).to.equal( 0 );
+ } );
} );
} );
} );