1
0
Fork 0

[DEV-3514] Add more robust testing for BasicQuote

Also, updated README to include instructions on `npm install.`
master
Corey Vollmer 2019-05-21 11:41:18 -04:00 committed by Andrew Fanton
parent 1ab1ecc2d4
commit 14869d9041
2 changed files with 190 additions and 23 deletions

View File

@ -40,6 +40,7 @@ If `configure` is not available, see the section "Configuring" above.
```
$ ./configure # see --help for optional arguments
$ make # build
$ npm install # install js dependencies
$ make check # run test cases
```

View File

@ -27,32 +27,198 @@ const { BaseQuote } = require( '../../' ).quote;
describe( 'BaseQuote', () =>
{
[
{
property: 'startDate',
value: 12345
},
{
property: 'initialRatedDate',
value: 12345
},
{
property: 'agentEntityId',
value: 12434300
},
].forEach( testCase =>
describe( 'accessors & mutators', () =>
{
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;
[
{
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'
}
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 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', () =>
{
[
{
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
}
].forEach( testCase =>
{
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 );
} );
} );
} );
} );