@@ -34,6 +34,25 @@ describe('DeviceProtectionCommands', () => {
34
34
expect ( deviceProtectionCommands . _getDeviceString ) . to . have . been . calledOnce ;
35
35
expect ( result ) . to . eql ( expectedStatus ) ;
36
36
} ) ;
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
+ } ) ;
37
56
} ) ;
38
57
39
58
describe ( 'disableProtection' , ( ) => {
@@ -57,7 +76,7 @@ describe('DeviceProtectionCommands', () => {
57
76
expect ( deviceProtectionCommands . api . unprotectDevice ) . to . have . been . calledTwice ;
58
77
} ) ;
59
78
60
- it ( 'should disable protection on the device' , async ( ) => {
79
+ it ( 'should disable protection on the device and turns to an open device ' , async ( ) => {
61
80
sinon . stub ( deviceProtectionCommands , '_getDeviceProtection' )
62
81
. onFirstCall ( ) . resolves ( { protected : true , overridden : false } )
63
82
. onSecondCall ( ) . resolves ( { protected : true , overridden : false } ) ;
@@ -81,12 +100,11 @@ describe('DeviceProtectionCommands', () => {
81
100
expect ( deviceProtectionCommands . _markAsDevelopmentDevice ) . to . have . been . calledOnce ;
82
101
} ) ;
83
102
84
- it ( 'handles open devices' , async ( ) => {
103
+ it ( 'handles already open devices' , async ( ) => {
85
104
sinon . stub ( deviceProtectionCommands , '_getDeviceProtection' )
86
105
. onFirstCall ( ) . resolves ( { protected : false , overridden : false } ) ;
87
106
sinon . stub ( deviceProtectionCommands , '_getDeviceString' ) . resolves ( '[123456789abcdef] (Product 12345)' ) ;
88
107
89
- // Call the method
90
108
await deviceProtectionCommands . disableProtection ( ) ;
91
109
92
110
expect ( deviceProtectionCommands . _getDeviceProtection ) . to . have . been . calledOnce ;
@@ -195,6 +213,22 @@ describe('DeviceProtectionCommands', () => {
195
213
expect ( error ) . to . be . an . instanceOf ( Error ) ;
196
214
expect ( error . message ) . to . include ( 'Device protection feature is not supported on this device' ) ;
197
215
} ) ;
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
+ } ) ;
198
232
} ) ;
199
233
200
234
describe ( '_flashBootloader' , ( ) => {
0 commit comments