diff options
author | Mike Gerwitz <gerwitzm@lovullo.com> | 2017-02-03 16:50:40 -0500 |
---|---|---|
committer | Mike Gerwitz <gerwitzm@lovullo.com> | 2017-02-08 11:24:56 -0500 |
commit | ed217079200766837306ccb8d13abf49fa91da58 (patch) | |
tree | 8e2693a7ede5dfdb0bbc42a99c033218e265d311 /test | |
parent | e7700e8b69f9b57ba235e1e9b61bb0ef5d588d4b (diff) | |
download | liza-ed217079200766837306ccb8d13abf49fa91da58.tar.gz liza-ed217079200766837306ccb8d13abf49fa91da58.tar.bz2 liza-ed217079200766837306ccb8d13abf49fa91da58.zip |
DataValidator, ValidStateMonitor: Add #clearFailures argument
This allows clearing only the specified failures.
* src/validate/ValidStateMonitor.js
(clearFailures): Add `fields' argument. Make method more concise.
(_fixFailure): Handle clearing `_failures' record.
* src/validate/DataValidator.js
(clearFailures): Add `fields' argument.
* test/validate/ValidStateMonitorTest.js: Add test.
* test/validate/DataValidatorTest.js: Add test.
Diffstat (limited to 'test')
-rw-r--r-- | test/validate/DataValidatorTest.js | 11 | ||||
-rw-r--r-- | test/validate/ValidStateMonitorTest.js | 50 |
2 files changed, 56 insertions, 5 deletions
diff --git a/test/validate/DataValidatorTest.js b/test/validate/DataValidatorTest.js index 8ff4af9..b31a93e 100644 --- a/test/validate/DataValidatorTest.js +++ b/test/validate/DataValidatorTest.js @@ -217,7 +217,7 @@ describe( 'DataValidator', () => describe( '#clearFailures', () => { - it( 'marks all failures as fixed', () => + it( 'proxies to validator', () => { const bvalidator = createMockBucketValidator(); const vmonitor = ValidStateMonitor(); @@ -229,9 +229,14 @@ describe( 'DataValidator', () => bvalidator, vmonitor, dep_factory, createStubStore() ); - mock_vmonitor.expects( 'clearFailures' ).once(); + const failures = [ 'foo', 'bar' ]; - expect( sut.clearFailures() ) + mock_vmonitor + .expects( 'clearFailures' ) + .once() + .withExactArgs( failures ); + + expect( sut.clearFailures( failures ) ) .to.equal( sut ); mock_vmonitor.verify(); diff --git a/test/validate/ValidStateMonitorTest.js b/test/validate/ValidStateMonitorTest.js index 5c44cb4..b57ff07 100644 --- a/test/validate/ValidStateMonitorTest.js +++ b/test/validate/ValidStateMonitorTest.js @@ -596,7 +596,7 @@ describe( 'ValidStateMonitor', function() describe( '#clearFailures', () => { - it( 'clears all failures', () => + it( 'clears all failures when provided no arguments', () => { return new Promise( ( accept, reject ) => { @@ -608,7 +608,7 @@ describe( 'ValidStateMonitor', function() .on( 'fix', fixed => { expect( fixed ) - .to.deep.equal( { foo: [ undefined ] } ); + .to.deep.equal( { foo: [ null ] } ); expect( sut.hasFailures() ).to.be.false; @@ -620,6 +620,52 @@ describe( 'ValidStateMonitor', function() .catch( e => reject( e ) ); } ); } ); + + + it( 'clears only provided failures when provided array argument', () => + { + return new Promise( ( accept, reject ) => + { + mkstore( {} ).then( empty => + { + const sut = Sut(); + + return sut + .on( 'fix', fixed => + { + debugger; + // `bar' not cleared + expect( fixed ) + .to.deep.equal( { + foo: [ null ], + baz: [ , null ], + } ); + + // still has `bar' + expect( sut.hasFailures() ).to.be.true; + + accept( true ); + } ) + .update( empty, { + foo: mkfail( 'foo', [ 'bar1', 'bar2' ] ), + bar: mkfail( 'bar', [ 'baz' ] ), + baz: mkfail( 'baz', [ 'quux', 'quuux' ] ), + } ) + .then( sut => sut.clearFailures( { + foo: [ 0 ], + baz: [ 1 ], + } ) ); + } ) + .catch( e => reject( e ) ); + } ); + } ); + + + it( 'does not error on non-existent failure', () => + { + expect( () => Sut().clearFailures( [ 'foo', 'baz' ] ) ) + .to.not.throw( Error ); + } ); } ); } ); |