diff --git a/lib/gui/models/store.js b/lib/gui/models/store.js index ed89a2ff..bd22ad40 100644 --- a/lib/gui/models/store.js +++ b/lib/gui/models/store.js @@ -203,7 +203,7 @@ const storeReducer = (state, action) => { throw new Error('The errorCode value can\'t be set if the flashing passed validation'); } - if (action.data.errorCode && !_.isString(action.data.errorCode)) { + if (action.data.errorCode && !_.isString(action.data.errorCode) && !_.isNumber(action.data.errorCode)) { throw new Error(`Invalid results errorCode: ${action.data.errorCode}`); } diff --git a/tests/gui/models/flash-state.spec.js b/tests/gui/models/flash-state.spec.js index 35a23064..dd63a4ec 100644 --- a/tests/gui/models/flash-state.spec.js +++ b/tests/gui/models/flash-state.spec.js @@ -253,15 +253,39 @@ describe('Browser: FlashStateModel', function() { }).to.throw('Missing results'); }); - it('should throw if errorCode is defined but it is not a number', function() { + it('should be able to set a string error code', function() { + FlashStateModel.unsetFlashingFlag({ + passedValidation: false, + cancelled: false, + sourceChecksum: '1234', + errorCode: 'EBUSY' + }); + + m.chai.expect(FlashStateModel.getLastFlashErrorCode()).to.equal('EBUSY'); + }); + + it('should be able to set a number error code', function() { + FlashStateModel.unsetFlashingFlag({ + passedValidation: false, + cancelled: false, + sourceChecksum: '1234', + errorCode: 123 + }); + + m.chai.expect(FlashStateModel.getLastFlashErrorCode()).to.equal(123); + }); + + it('should throw if errorCode is not a number not a string', function() { m.chai.expect(function() { FlashStateModel.unsetFlashingFlag({ passedValidation: false, cancelled: false, sourceChecksum: '1234', - errorCode: 123 + errorCode: { + name: 'EBUSY' + } }); - }).to.throw('Invalid results errorCode: 123'); + }).to.throw('Invalid results errorCode: [object Object]'); }); it('should default passedValidation to false', function() {