Skip to content

Commit 1d92580

Browse files
committed
[tests] more coverage
1 parent fbdfd5b commit 1d92580

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/cli/binary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = ({ commandProcessor, root }) => {
1616
params: '<file>',
1717
options: {
1818
'saveTo': {
19-
description: 'Specify the bootloader file to add device protection to'
19+
description: 'Specify the filename for the protected binary'
2020
}
2121
},
2222
handler: (args) => {

src/cmd/device-protection.test.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ describe('DeviceProtectionCommands', () => {
3434
expect(deviceProtectionCommands._getDeviceString).to.have.been.calledOnce;
3535
expect(result).to.eql(expectedStatus);
3636
});
37+
38+
it('throws an error while getting the protection status of the device', async () => {
39+
const expectedStatus = {
40+
protected: true,
41+
overridden: false
42+
};
43+
44+
sinon.stub(deviceProtectionCommands, '_getDeviceProtection').rejects(new Error('random error'));
45+
46+
let error;
47+
try {
48+
await deviceProtectionCommands.getStatus();
49+
} catch (e) {
50+
error = e;
51+
}
52+
53+
expect(error).to.be.an.instanceOf(Error);
54+
expect(error.message).to.include('Unable to get device status: random error');
55+
});
3756
});
3857

3958
describe('disableProtection', () => {
@@ -57,7 +76,7 @@ describe('DeviceProtectionCommands', () => {
5776
expect(deviceProtectionCommands.api.unprotectDevice).to.have.been.calledTwice;
5877
});
5978

60-
it('should disable protection on the device', async () => {
79+
it('should disable protection on the device and turns to an open device', async () => {
6180
sinon.stub(deviceProtectionCommands, '_getDeviceProtection')
6281
.onFirstCall().resolves({ protected: true, overridden: false })
6382
.onSecondCall().resolves({ protected: true, overridden: false });
@@ -81,12 +100,11 @@ describe('DeviceProtectionCommands', () => {
81100
expect(deviceProtectionCommands._markAsDevelopmentDevice).to.have.been.calledOnce;
82101
});
83102

84-
it('handles open devices', async () => {
103+
it('handles already open devices', async () => {
85104
sinon.stub(deviceProtectionCommands, '_getDeviceProtection')
86105
.onFirstCall().resolves({ protected: false, overridden: false });
87106
sinon.stub(deviceProtectionCommands, '_getDeviceString').resolves('[123456789abcdef] (Product 12345)');
88107

89-
// Call the method
90108
await deviceProtectionCommands.disableProtection();
91109

92110
expect(deviceProtectionCommands._getDeviceProtection).to.have.been.calledOnce;
@@ -195,6 +213,22 @@ describe('DeviceProtectionCommands', () => {
195213
expect(error).to.be.an.instanceOf(Error);
196214
expect(error.message).to.include('Device protection feature is not supported on this device');
197215
});
216+
217+
it('throws a random error', async () => {
218+
deviceProtectionCommands.device = {
219+
getProtectionState: sinon.stub().rejects(new Error('random error'))
220+
};
221+
222+
let error;
223+
try {
224+
await deviceProtectionCommands._getDeviceProtection();
225+
} catch (_e) {
226+
error = _e;
227+
}
228+
229+
expect(error).to.be.an.instanceOf(Error);
230+
expect(error.message).to.include('random error');
231+
});
198232
});
199233

200234
describe('_flashBootloader', () => {

0 commit comments

Comments
 (0)