mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-24 07:17:18 +00:00
test: validate contents of flash state object (#526)
Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
parent
b0d13eee3b
commit
4708401260
@ -107,6 +107,34 @@ const storeReducer = (state, action) => {
|
||||
throw new Error('Can\'t set the flashing state when not flashing');
|
||||
}
|
||||
|
||||
if (!action.data.type) {
|
||||
throw new Error('Missing state type');
|
||||
}
|
||||
|
||||
if (!_.isString(action.data.type)) {
|
||||
throw new Error(`Invalid state type: ${action.data.type}`);
|
||||
}
|
||||
|
||||
if (!action.data.progress) {
|
||||
throw new Error('Missing state progress');
|
||||
}
|
||||
|
||||
if (!_.isNumber(action.data.progress)) {
|
||||
throw new Error(`Invalid state progress: ${action.data.progress}`);
|
||||
}
|
||||
|
||||
if (!action.data.eta) {
|
||||
throw new Error('Missing state eta');
|
||||
}
|
||||
|
||||
if (!_.isNumber(action.data.eta)) {
|
||||
throw new Error(`Invalid state eta: ${action.data.eta}`);
|
||||
}
|
||||
|
||||
if (!action.data.speed) {
|
||||
throw new Error('Missing state speed');
|
||||
}
|
||||
|
||||
return state.set('flashState', Immutable.fromJS(action.data));
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,86 @@ describe('Browser: ImageWriter', function() {
|
||||
}).to.throw('Can\'t set the flashing state when not flashing');
|
||||
});
|
||||
|
||||
it('should throw if type is missing', function() {
|
||||
ImageWriterService.setFlashing(true);
|
||||
m.chai.expect(function() {
|
||||
ImageWriterService.setProgressState({
|
||||
percentage: 50,
|
||||
eta: 15,
|
||||
speed: 100000000000
|
||||
});
|
||||
}).to.throw('Missing state type');
|
||||
});
|
||||
|
||||
it('should throw if type is not a string', function() {
|
||||
ImageWriterService.setFlashing(true);
|
||||
m.chai.expect(function() {
|
||||
ImageWriterService.setProgressState({
|
||||
type: 1234,
|
||||
percentage: 50,
|
||||
eta: 15,
|
||||
speed: 100000000000
|
||||
});
|
||||
}).to.throw('Invalid state type: 1234');
|
||||
});
|
||||
|
||||
it('should throw if progress is missing', function() {
|
||||
ImageWriterService.setFlashing(true);
|
||||
m.chai.expect(function() {
|
||||
ImageWriterService.setProgressState({
|
||||
type: 'write',
|
||||
eta: 15,
|
||||
speed: 100000000000
|
||||
});
|
||||
}).to.throw('Missing state progress');
|
||||
});
|
||||
|
||||
it('should throw if progress is not a number', function() {
|
||||
ImageWriterService.setFlashing(true);
|
||||
m.chai.expect(function() {
|
||||
ImageWriterService.setProgressState({
|
||||
type: 'write',
|
||||
percentage: '50',
|
||||
eta: 15,
|
||||
speed: 100000000000
|
||||
});
|
||||
}).to.throw('Invalid state progress: 50');
|
||||
});
|
||||
|
||||
it('should throw if eta is missing', function() {
|
||||
ImageWriterService.setFlashing(true);
|
||||
m.chai.expect(function() {
|
||||
ImageWriterService.setProgressState({
|
||||
type: 'write',
|
||||
percentage: 50,
|
||||
speed: 100000000000
|
||||
});
|
||||
}).to.throw('Missing state eta');
|
||||
});
|
||||
|
||||
it('should throw if eta is not a number', function() {
|
||||
ImageWriterService.setFlashing(true);
|
||||
m.chai.expect(function() {
|
||||
ImageWriterService.setProgressState({
|
||||
type: 'write',
|
||||
percentage: 50,
|
||||
eta: '15',
|
||||
speed: 100000000000
|
||||
});
|
||||
}).to.throw('Invalid state eta: 15');
|
||||
});
|
||||
|
||||
it('should throw if speed is missing', function() {
|
||||
ImageWriterService.setFlashing(true);
|
||||
m.chai.expect(function() {
|
||||
ImageWriterService.setProgressState({
|
||||
type: 'write',
|
||||
percentage: 50,
|
||||
eta: 15
|
||||
});
|
||||
}).to.throw('Missing state speed');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.setFlashing()', function() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user