Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitzm@lovullo.com>2017-01-26 16:03:00 -0500
committerMike Gerwitz <gerwitzm@lovullo.com>2017-01-29 22:44:27 -0500
commit2045c76f7e40878f2de308fb2579899a86fea80f (patch)
tree8491f925c7dec5f0ccec3ef6d2e5269d74e9efc1 /test
parent203b25f10e0d446ae9971bd157b8b2a7cfc4ddc0 (diff)
downloadliza-2045c76f7e40878f2de308fb2579899a86fea80f.tar.gz
liza-2045c76f7e40878f2de308fb2579899a86fea80f.tar.bz2
liza-2045c76f7e40878f2de308fb2579899a86fea80f.zip
Integrate Store into DataValidator, ValidStateMonitor
ValidStateMonitor now uses a Store in place of the original primitive object-based diff format. The original format is translated by DataValidator. The code is in a transitional state, and considering the amount of time we spend on various areas of this project, will likely stay this way for a while. * src/validate/DataValidator.js (__construct): Accept Store factory parameter. (_store_factory): Add field. (_createStores): Add method. (_validate): Handle Store. (updateFailures): Add method. (_populateStore): Add method. * test/validate/DataValidatorTest.js: Add tests. * src/validate/ValidStateMonitor.js (update): Enforce Store diff. Wait to process failures until fixes are calculated. (_checkFailureFix): Handle asynchronous, Promise-based diff. (_checkCauseFix): Extract logic from _checkCauseFix. * test/validate/ValidStateMonitorTest.js: Modify test cases to be Promise-based and handle async calls where appropriate. That was a friggin' expensive mess. DEV-2296
Diffstat (limited to 'test')
-rw-r--r--test/validate/DataValidatorTest.js53
-rw-r--r--test/validate/ValidStateMonitorTest.js605
2 files changed, 396 insertions, 262 deletions
diff --git a/test/validate/DataValidatorTest.js b/test/validate/DataValidatorTest.js
index a209486..62478ee 100644
--- a/test/validate/DataValidatorTest.js
+++ b/test/validate/DataValidatorTest.js
@@ -21,12 +21,13 @@
"use strict";
-const root = require( '../../' );
-const validate = root.validate;
-const Sut = validate.DataValidator;
-const chai = require( 'chai' );
-const expect = chai.expect;
-const sinon = require( 'sinon' );
+const root = require( '../../' );
+const validate = root.validate;
+const Sut = validate.DataValidator;
+const MemoryStore = root.store.MemoryStore;
+const chai = require( 'chai' );
+const expect = chai.expect;
+const sinon = require( 'sinon' );
const BucketDataValidator = validate.BucketDataValidator,
ValidStateMonitor = validate.ValidStateMonitor;
@@ -55,6 +56,7 @@ describe( 'DataValidator', () =>
const vmonitor = ValidStateMonitor();
const dep_factory = createMockDependencyFactory();
+ const getStore = createStubStore();
const mock_vmonitor = sinon.mock( vmonitor );
const mock_dep_factory = sinon.mock( dep_factory );
@@ -68,7 +70,7 @@ describe( 'DataValidator', () =>
mock_vmonitor.expects( 'update' )
.once()
- .withExactArgs( diff, expected_failures )
+ .withExactArgs( getStore(), expected_failures )
.returns( Promise.resolve( undefined ) );
mock_dep_factory.expects( 'createFieldFailure' )
@@ -76,19 +78,17 @@ describe( 'DataValidator', () =>
.withExactArgs( 'foo', 1, expected_value )
.returns( expected_failure );
- const retp = Sut( bvalidator, vmonitor, dep_factory )
- .validate( diff );
-
- // cleared on call to err in above mock validator
- expect( diff.foo ).to.deep.equal(
- [ 'a', undefined, 'c' ]
- );
-
- mock_vmonitor.verify();
- mock_dep_factory.verify();
+ return Sut( bvalidator, vmonitor, dep_factory, getStore )
+ .validate( diff )
+ .then( () =>
+ {
+ mock_vmonitor.verify();
+ mock_dep_factory.verify();
- // the promise
- return retp;
+ // cleared on call to err in above mock validator
+ return expect( getStore().get( 'foo' ) )
+ .to.eventually.deep.equal( [ 'a', undefined, 'c' ] );
+ } );
} );
@@ -106,6 +106,7 @@ describe( 'DataValidator', () =>
const vmonitor = ValidStateMonitor();
const dep_factory = createMockDependencyFactory();
+ const getStore = createStubStore();
const diff = { foo: [ 'a', 'b', 'c' ] };
const expected_failures = {
@@ -129,14 +130,14 @@ describe( 'DataValidator', () =>
sinon.mock( vmonitor )
.expects( 'update' )
.once()
- .withExactArgs( diff, expected_failures )
+ .withExactArgs( getStore(), expected_failures )
.returns( Promise.resolve( undefined ) );
sinon.mock( dep_factory )
.expects( 'createFieldFailure' )
.returns( expected_failure );
- return Sut( bvalidator, vmonitor, dep_factory )
+ return Sut( bvalidator, vmonitor, dep_factory, getStore )
.validate( diff, validatef );
} );
@@ -155,7 +156,7 @@ describe( 'DataValidator', () =>
.returns( Promise.reject( expected_e ) );
return expect(
- Sut( bvalidator, vmonitor, dep_factory )
+ Sut( bvalidator, vmonitor, dep_factory, createStubStore() )
.validate( {} )
).to.eventually.be.rejectedWith( expected_e );
} );
@@ -181,3 +182,11 @@ function createMockDependencyFactory( map )
createFieldFailure: () => {},
};
}
+
+
+function createStubStore()
+{
+ const store = MemoryStore();
+
+ return () => store;
+}
diff --git a/test/validate/ValidStateMonitorTest.js b/test/validate/ValidStateMonitorTest.js
index c129cdd..75dab73 100644
--- a/test/validate/ValidStateMonitorTest.js
+++ b/test/validate/ValidStateMonitorTest.js
@@ -19,17 +19,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-var root = require( '../../' ),
- Sut = root.validate.ValidStateMonitor,
- chai = require( 'chai' ),
- expect = chai.expect,
- Failure = root.validate.Failure,
- Field = root.field.BucketField;
+"use strict";
+
+const root = require( '../../' );
+const Sut = root.validate.ValidStateMonitor;
+const chai = require( 'chai' );
+const expect = chai.expect;
+const Failure = root.validate.Failure;
+const Field = root.field.BucketField;
+const MemoryStore = root.store.MemoryStore;
chai.use( require( 'chai-as-promised' ) );
-var nocall = function( type )
+const nocall = function( type )
{
return function()
{
@@ -37,7 +40,7 @@ var nocall = function( type )
};
};
-var mkfail = function( name, arr )
+const mkfail = function( name, arr )
{
return arr.map( function( value, i )
{
@@ -54,19 +57,25 @@ describe( 'ValidStateMonitor', function()
{
it( 'does nothing with no data or failures', function()
{
- return Sut()
- .on( 'failure', nocall( 'failure' ) )
- .on( 'fix', nocall( 'fix' ) )
- .update( {}, {} );
+ return mkstore( {} ).then( empty =>
+ {
+ return Sut()
+ .on( 'failure', nocall( 'failure' ) )
+ .on( 'fix', nocall( 'fix' ) )
+ .update( empty, {} );
+ } );
} );
it( 'does nothing with data but no failures', function()
{
- return Sut()
- .on( 'failure', nocall( 'failure' ) )
- .on( 'fix', nocall( 'fix' ) )
- .update( { foo: mkfail( 'foo', [ 'bar' ] ) }, {} );
+ return mkstore( { foo: mkfail( 'foo', [ 'bar' ] ) } ).then( store =>
+ {
+ return Sut()
+ .on( 'failure', nocall( 'failure' ) )
+ .on( 'fix', nocall( 'fix' ) )
+ .update( store, {} );
+ } );
} );
@@ -74,88 +83,118 @@ describe( 'ValidStateMonitor', function()
// need the data
describe( 'given failures', function()
{
- it( 'marks failures even when given no data', function( done )
+ it( 'marks failures even when given no data', function()
{
var fail = mkfail( 'foo', [ 'bar', 'baz' ] );
- Sut()
- .on( 'failure', function( failures )
+ return mkstore( {} ).then( empty =>
+ {
+ return new Promise( accept =>
{
- expect( failures )
- .to.deep.equal( { foo: [ fail[ 0 ], fail[ 1 ] ] } );
- done();
- } )
- .on( 'fix', nocall( 'fix' ) )
- .update( {}, { foo: fail } );
+ return Sut()
+ .on( 'failure', function( failures )
+ {
+ expect( failures )
+ .to.deep.equal(
+ { foo: [ fail[ 0 ], fail[ 1 ] ] }
+ );
+ accept();
+ } )
+ .on( 'fix', nocall( 'fix' ) )
+ .update( empty, { foo: fail } );
+ } );
+ } );
} );
- it( 'marks failures with index gaps', function( done )
+ it( 'marks failures with index gaps', function()
{
var fail = mkfail( 'foo', [ undefined, 'baz' ] );
- Sut()
- .on( 'failure', function( failures )
+ return mkstore( {} ).then( empty =>
+ {
+ return new Promise( accept =>
{
- expect( failures )
- .to.deep.equal( { foo: [ undefined, fail[ 1 ] ] } );
- done();
- } )
- .on( 'fix', nocall( 'fix' ) )
- .update( {}, { foo: fail } );
+ Sut()
+ .on( 'failure', function( failures )
+ {
+ expect( failures )
+ .to.deep.equal(
+ { foo: [ undefined, fail[ 1 ] ] }
+ );
+ accept();
+ } )
+ .on( 'fix', nocall( 'fix' ) )
+ .update( empty, { foo: fail } );
+ } );
+ } );
} );
- it( 'retains past failures when setting new', function( done )
+ it( 'retains past failures when setting new', function()
{
var sut = Sut(),
fail = mkfail( 'foo', [ 'bar', 'baz' ] );
- var test_first = function( failures )
+ return new Promise( ( accept, reject ) =>
{
- expect( failures )
- .to.deep.equal( { foo: [ undefined, fail[ 1 ] ] } );
+ var test_first = function( failures )
+ {
+ expect( failures )
+ .to.deep.equal( { foo: [ undefined, fail[ 1 ] ] } );
- sut.once( 'failure', test_second );
- };
+ sut.once( 'failure', test_second );
+ };
- var test_second = function( failures )
- {
- expect( failures )
- .to.deep.equal( { foo: [ fail[ 0 ], fail[ 1 ] ] } );
+ var test_second = function( failures )
+ {
+ expect( failures )
+ .to.deep.equal( { foo: [ fail[ 0 ], fail[ 1 ] ] } );
- done();
- };
+ accept();
+ };
- sut
- .once( 'failure', test_first )
- .on( 'fix', nocall( 'fix' ) )
- .update( {}, { foo: [ undefined, fail[ 1 ] ] } )
- .then( () =>
+ mkstore( {} ).then( empty =>
{
- return sut.update( {}, { foo: [ fail[ 0 ] ] } );
- } );
+ return sut
+ .once( 'failure', test_first )
+ .on( 'fix', nocall( 'fix' ) )
+ .update( empty, { foo: [ undefined, fail[ 1 ] ] } )
+ .then( () =>
+ {
+ return sut.update( empty, { foo: [ fail[ 0 ] ] } );
+ } );
+ } ).catch( e => reject( e ) );
+ } );
} );
// deprecated
- it( 'accepts failures as string for BC', function( done )
+ it( 'accepts failures as string for BC', function()
{
var fail = [ 'foo', 'bar' ];
- Sut()
- .on( 'failure', function( failures )
+ return new Promise( ( accept, reject ) =>
+ {
+ return mkstore( {} ).then( empty =>
{
- expect( failures )
- .to.deep.equal( { foo: fail } );
- done();
+ return Sut()
+ .on( 'failure', function( failures )
+ {
+ expect( failures )
+ .to.deep.equal( { foo: fail } );
+
+ accept();
+ } )
+ .on( 'fix', nocall( 'fix' ) )
+ .update( empty, { foo: fail } );
} )
- .on( 'fix', nocall( 'fix' ) )
- .update( {}, { foo: fail } );
+ .catch( e => reject( e ) );
+ } );
} );
- it( 'does not discard existing failures', function( done )
+ it( 'does not discard existing failures', function()
{
var sut = Sut();
@@ -176,79 +215,106 @@ describe( 'ValidStateMonitor', function()
// the second failure has fewer causes than the first;
// we need to make sure that it doesn't overwrite,
// leading to fewer caues
- sut
- .update( {}, { foo: [ fail1 ] } )
- .then( () =>
- {
- return sut.update( {}, { foo: [ fail2 ] } );
- } )
- .then( () =>
+ return new Promise( ( accept, reject ) =>
+ {
+ return mkstore( {} ).then( empty =>
{
return sut
- .once( 'fix', function( fixed )
+ .update( empty, { foo: [ fail1 ] } )
+ .then( () =>
{
- expect( fixed )
- .to.deep.equal( { foo: [ 'causefix1' ] } );
-
- // and then we should have no failures
- expect( sut.hasFailures() ).to.be.false;
-
- done();
+ return sut.update( empty, { foo: [ fail2 ] } );
} )
- .update(
- { foo: [ 'moo' ], cause1: [ 'causefix1' ] },
- {}
- );
- } );
+ .then( () =>
+ {
+ const update = {
+ foo: [ 'moo' ],
+ cause1: [ 'causefix1' ]
+ };
+
+ return mkstore( update ).then( store =>
+ {
+ return sut
+ .once( 'fix', function( fixed )
+ {
+ expect( fixed ).to.deep.equal(
+ { foo: [ 'causefix1' ] }
+ );
+
+ // and then we should have no failures
+ expect( sut.hasFailures() )
+ .to.be.false;
+
+ accept( true );
+ } )
+ .update( store, {} );
+ } );
+ } );
+ } )
+ .catch( e => reject( e ) );
+ } );
} );
} );
describe( 'given data with absence of failure', function()
{
- it( 'removes non-failures if field is present', function( done )
+ it( 'removes non-failures if field is present', function()
{
- var data = { foo: [ 'bardata', 'baz' ] },
- fail = mkfail( 'foo', [ 'bar', 'baz' ] );
-
- var sut = Sut();
+ const fail = mkfail( 'foo', [ 'bar', 'baz' ] );
+ const sut = Sut();
- sut
- .on( 'fix', function( fixed )
+ return new Promise( ( accept, reject ) =>
+ {
+ return mkstore( { foo: [ 'bardata', 'baz' ] } ).then( data =>
{
- expect( fixed )
- .to.deep.equal( { foo: [ 'bardata' ] } );
- done();
+ return sut
+ .on( 'fix', function( fixed )
+ {
+ expect( fixed )
+ .to.deep.equal( { foo: [ 'bardata' ] } );
+ accept();
+ } )
+ .update( data, { foo: [ fail[ 0 ], fail[ 1 ] ] } )
+ .then( () =>
+ {
+ return sut.update( data, {
+ foo: [ undefined, fail[ 1 ] ]
+ } );
+ } );
} )
- .update( data, { foo: [ fail[ 0 ], fail[ 1 ] ] } )
- .then( () =>
- {
- return sut.update( data, { foo: [ undefined, fail[ 1 ] ] } );
- } );
+ .catch( e => reject( e ) );
+ } );
} );
- it( 'keeps failures if field is missing', function( done )
+ it( 'keeps failures if field is missing', function()
{
- var data = { bar: [ 'baz', 'quux' ] },
- fail_foo = mkfail( 'foo', [ 'bar', 'baz' ] ),
- fail_bar = mkfail( 'bar', [ 'moo', 'cow' ] );
+ const fail_foo = mkfail( 'foo', [ 'bar', 'baz' ] );
+ const fail_bar = mkfail( 'bar', [ 'moo', 'cow' ] );
- Sut()
- .on( 'fix', function( fixed )
+ return new Promise( ( accept, reject ) =>
+ {
+ return mkstore( { bar: [ 'baz', 'quux' ] } ).then( data =>
{
- expect( fixed )
- .to.deep.equal( { bar: [ 'baz', 'quux' ] } );
- done();
- } )
- .update( data, {
- foo: fail_foo, // does not exist in data
- bar: fail_bar,
+ return Sut()
+ .on( 'fix', function( fixed )
+ {
+ expect( fixed )
+ .to.deep.equal( { bar: [ 'baz', 'quux' ] } );
+ accept();
+ } )
+ .update( data, {
+ foo: fail_foo, // does not exist in data
+ bar: fail_bar,
+ } )
+ .then( sut =>
+ {
+ return sut.update( data, {} );
+ } );
} )
- .then( sut =>
- {
- return sut.update( data, {} );
- } );
+ .catch( e => reject( e ) );
+ } );
} );
@@ -256,156 +322,199 @@ describe( 'ValidStateMonitor', function()
{
var called = 0;
- Sut()
- .on( 'failure', function()
- {
- called++;
- } )
- .update( {}, { foo: mkfail( 'foo', [ 'bar' ] ) } )
- .then( sut =>
- {
- return sut.update( {}, {} ); // do not trigger failure event
- } )
- .then( sut =>
- {
- expect( called ).to.equal( 1 );
- } );
+ return mkstore( {} ).then( empty =>
+ {
+ return Sut()
+ .on( 'failure', function()
+ {
+ called++;
+ } )
+ .update( empty, { foo: mkfail( 'foo', [ 'bar' ] ) } )
+ .then( sut =>
+ {
+ return sut.update( empty, {} ); // do not trigger failure event
+ } )
+ .then( sut =>
+ {
+ expect( called ).to.equal( 1 );
+ } );
+ } );
} );
describe( 'given a cause', function()
{
- it( 'considers when recognizing fix', function( done )
+ it( 'considers when recognizing fix', function()
{
// same index
- var data = { cause: [ 'bar' ] },
- field = Field( 'foo', 0 ),
- cause = Field( 'cause', 0 ),
- fail = Failure( field, 'reason', [ cause ] );
+ const field = Field( 'foo', 0 );
+ const cause = Field( 'cause', 0 );
+ const fail = Failure( field, 'reason', [ cause ] );
- Sut()
- .on( 'fix', function( fixed )
+ return new Promise( ( accept, reject ) =>
+ {
+ return mkstore( { cause: [ 'bar' ] } ).then( data =>
{
- expect( fixed )
- .to.deep.equal( { foo: [ 'bar' ] } );
-
- done();
+ return Sut()
+ .on( 'fix', function( fixed )
+ {
+ expect( fixed )
+ .to.deep.equal( { foo: [ 'bar' ] } );
+
+ accept();
+ } )
+ .update( data, { foo: [ fail ] } )
+ .then( sut =>
+ {
+ return sut.update( data, {} );
+ } );
} )
- .update( data, { foo: [ fail ] } )
- .then( sut =>
- {
- return sut.update( data, {} );
- } );
+ .catch( e => reject( e ) );
+ } );
} );
- it( 'considers different cause index', function( done )
+ it( 'considers different cause index', function()
{
// different index
- var data = { cause: [ undefined, 'bar' ] },
- field = Field( 'foo', 0 ),
- cause = Field( 'cause', 1 ),
- fail = Failure( field, 'reason', [ cause ] );
+ const update_data = { cause: [ undefined, 'bar' ] };
+ const field = Field( 'foo', 0 );
+ const cause = Field( 'cause', 1 );
+ const fail = Failure( field, 'reason', [ cause ] );
- Sut()
- .on( 'fix', function( fixed )
+ return new Promise( ( accept, reject ) =>
+ {
+ return mkstore( update_data ).then( data =>
{
- expect( fixed )
- .to.deep.equal( { foo: [ 'bar' ] } );
-
- done();
+ return Sut()
+ .on( 'fix', function( fixed )
+ {
+ expect( fixed )
+ .to.deep.equal( { foo: [ 'bar' ] } );
+
+ accept();
+ } )
+ .update( data, { foo: [ fail ] } )
+ .then( sut =>
+ {
+ return sut.update( data, {} );
+ } );
} )
- .update( data, { foo: [ fail ] } )
- .then( sut =>
- {
- return sut.update( data, {} );
- } );
+ .catch( e => reject( e ) );
+ } );
} );
- it( 'considers any number of causes', function( done )
+ it( 'considers any number of causes', function()
{
// different index
- var data = { cause_fix: [ undefined, 'bar' ] },
- field = Field( 'foo', 0 ),
- cause1 = Field( 'cause_no', 1 ),
- cause2 = Field( 'cause_fix', 1 ),
- fail = Failure(
- field,
- 'reason',
- [ cause1, cause2 ]
- );
-
- Sut()
- .on( 'fix', function( fixed )
+ const update_data = { cause_fix: [ undefined, 'bar' ] };
+ const field = Field( 'foo', 0 );
+ const cause1 = Field( 'cause_no', 1 );
+ const cause2 = Field( 'cause_fix', 1 );
+
+ const fail = Failure(
+ field,
+ 'reason',
+ [ cause1, cause2 ]
+ );
+
+ return new Promise( ( accept, reject ) =>
+ {
+ return mkstore( update_data ).then( data =>
{
- expect( fixed )
- .to.deep.equal( { foo: [ 'bar' ] } );
-
- done();
+ return Sut()
+ .on( 'fix', function( fixed )
+ {
+ expect( fixed )
+ .to.deep.equal( { foo: [ 'bar' ] } );
+
+ accept();
+ } )
+ .update( data, { foo: [ fail ] } )
+ .then( sut =>
+ {
+ return sut.update( data, {} );
+ } );
} )
- .update( data, { foo: [ fail ] } )
- .then( sut =>
- {
- return sut.update( data, {} );
- } );
+ .catch( e => reject( e ) );
+ } );
} );
it( 'recognizes non-fix', function()
{
// no cause data
- var data = { noncause: [ undefined, 'bar' ] },
- field = Field( 'foo', 0 ),
- cause1 = Field( 'cause', 1 ),
- cause2 = Field( 'cause', 2 ),
- fail = Failure(
- field,
- 'reason',
- [ cause1, cause2 ]
- );
-
- Sut()
- .on( 'fix', nocall )
- .update( data, { foo: [ fail ] } )
- .then( sut =>
- {
- return sut.update( data, {} );
- } );
+ const update_data = mkstore( { noncause: [ undefined, 'bar' ] } );
+ const field = Field( 'foo', 0 );
+ const cause1 = Field( 'cause', 1 );
+ const cause2 = Field( 'cause', 2 );
+
+ const fail = Failure(
+ field,
+ 'reason',
+ [ cause1, cause2 ]
+ );
+
+ return mkstore( update_data ).then( data =>
+ {
+ return Sut()
+ .on( 'fix', nocall )
+ .update( data, { foo: [ fail ] } )
+ .then( sut =>
+ {
+ return sut.update( data, {} );
+ } );
+ } );
} );
} );
} );
- it( 'can emit both failure and fix', function( done )
+ it( 'can emit both failure and fix', function()
{
- var data = { bar: [ 'baz', 'quux' ] },
- fail_foo = mkfail( 'foo', [ 'bar' ] );
-
- Sut()
- .update( data, {
- bar: mkfail( 'bar', [ 'moo', 'cow' ] ) // fail
- } )
- .then( sut =>
- {
- return sut.on( 'failure', function( failed )
- {
- expect( failed )
- .to.deep.equal( {
- foo: fail_foo,
- } );
+ var fail_foo = mkfail( 'foo', [ 'bar' ] );
+
+ return mkstore( { bar: [ 'baz', 'quux' ] } ).then( data =>
+ {
+ return Sut()
+ .update( data, {
+ bar: mkfail( 'bar', [ 'moo', 'cow' ] ) // fail
} )
- .on( 'fix', function( fixed )
+ .then( sut =>
{
- expect( fixed )
- .to.deep.equal( { bar: [ 'baz', 'quux' ] } );
- done();
- } )
- .update( data, {
- foo: fail_foo, // fail
- // fixes bar
+ return new Promise( ( accept, reject ) =>
+ {
+ sut.on( 'failure', function( failed )
+ {
+ expect( failed )
+ .to.deep.equal( {
+ foo: fail_foo,
+ } );
+ } )
+ .on( 'fix', function( fixed )
+ {
+ expect( fixed )
+ .to.deep.equal(
+ { bar: [ 'baz', 'quux' ] }
+ );
+
+ // note that the documentation for #update
+ // states that failure will always be
+ // emitted before fix
+ accept( true );
+ } )
+ .update( data, {
+ foo: fail_foo, // fail
+ // fixes bar
+ } )
+ .catch( e =>
+ {
+ reject( e );
+ } );
+ } );
} );
- } );
+ } );
} );
} );
@@ -425,14 +534,17 @@ describe( 'ValidStateMonitor', function()
{
var fail = mkfail( 'foo', [ 'fail' ] );
- return expect(
- Sut()
- .update( {}, { foo: fail } )
- .then( sut =>
- {
- return sut.getFailures()
- } )
- ).to.eventually.deep.equal( { foo: fail } );
+ return mkstore( {} ).then( empty =>
+ {
+ return expect(
+ Sut()
+ .update( empty, { foo: fail } )
+ .then( sut =>
+ {
+ return sut.getFailures()
+ } )
+ ).to.eventually.deep.equal( { foo: fail } );
+ } );
} );
} );
@@ -448,14 +560,27 @@ describe( 'ValidStateMonitor', function()
it( 'is true when failures exist', function()
{
- return expect(
- Sut()
- .update( {}, { foo: mkfail( 'foo', [ 'bar' ] ) } )
- .then( sut =>
- {
- return sut.hasFailures();
- } )
- ).to.eventually.be.true;
+ return mkstore( {} ).then( empty =>
+ {
+ return expect(
+ Sut()
+ .update( empty, { foo: mkfail( 'foo', [ 'bar' ] ) } )
+ .then( sut =>
+ {
+ return sut.hasFailures();
+ } )
+ ).to.eventually.be.true;
+ } );
} );
} );
} );
+
+
+function mkstore( data )
+{
+ let store = MemoryStore();
+
+ return Promise.all(
+ Object.keys( data ).map( key => store.add( key, data[ key ] ) )
+ ).then( () => store );
+}