@@ -26,7 +26,9 @@ describe(commands.APP_GET, () => {
26
26
const appResponse = {
27
27
value : [
28
28
{
29
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952"
29
+ "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
30
+ "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
31
+ "displayName" : "My App"
30
32
}
31
33
]
32
34
} ;
@@ -64,8 +66,9 @@ describe(commands.APP_GET, () => {
64
66
fs . readFileSync ,
65
67
fs . writeFileSync ,
66
68
cli . getSettingWithDefaultValue ,
67
- cli . handleMultipleResultsFound ,
68
- entraApp . getAppRegistrationByAppId
69
+ entraApp . getAppRegistrationByAppId ,
70
+ entraApp . getAppRegistrationByAppName ,
71
+ entraApp . getAppRegistrationByObjectId
69
72
] ) ;
70
73
} ) ;
71
74
@@ -94,90 +97,25 @@ describe(commands.APP_GET, () => {
94
97
} ) ;
95
98
96
99
it ( 'handles error when the app with the specified the name not found' , async ( ) => {
97
- sinon . stub ( request , 'get' ) . callsFake ( async opts => {
98
- if ( opts . url === `https://graph.microsoft.com/v1.0/myorganization/applications?$filter=displayName eq 'My%20app'&$select=id` ) {
99
- return { value : [ ] } ;
100
- }
101
-
102
- throw `Invalid request ${ JSON . stringify ( opts ) } ` ;
103
- } ) ;
100
+ const error = `App with name 'My app' not found in Microsoft Entra ID` ;
101
+ sinon . stub ( entraApp , 'getAppRegistrationByAppName' ) . rejects ( new Error ( error ) ) ;
104
102
105
103
await assert . rejects ( command . action ( logger , {
106
104
options : {
107
105
name : 'My app'
108
106
}
109
- } ) , new CommandError ( `No Microsoft Entra application registration with name My app found` ) ) ;
107
+ } ) , new CommandError ( `App with name ' My app' not found in Microsoft Entra ID ` ) ) ;
110
108
} ) ;
111
109
112
110
it ( 'handles error when multiple apps with the specified name found' , async ( ) => {
113
- sinon . stub ( cli , 'getSettingWithDefaultValue' ) . callsFake ( ( settingName , defaultValue ) => {
114
- if ( settingName === settingsNames . prompt ) {
115
- return false ;
116
- }
117
-
118
- return defaultValue ;
119
- } ) ;
120
-
121
- sinon . stub ( request , 'get' ) . callsFake ( async opts => {
122
- if ( opts . url === `https://graph.microsoft.com/v1.0/myorganization/applications?$filter=displayName eq 'My%20app'&$select=id` ) {
123
- return {
124
- value : [
125
- { id : '9b1b1e42-794b-4c71-93ac-5ed92488b67f' } ,
126
- { id : '9b1b1e42-794b-4c71-93ac-5ed92488b67g' }
127
- ]
128
- } ;
129
- }
130
-
131
- throw `Invalid request ${ JSON . stringify ( opts ) } ` ;
132
- } ) ;
111
+ const error = `Multiple apps with name 'My app' found in Microsoft Entra ID. Found: 9b1b1e42-794b-4c71-93ac-5ed92488b67f, 9b1b1e42-794b-4c71-93ac-5ed92488b67g.` ;
112
+ sinon . stub ( entraApp , 'getAppRegistrationByAppName' ) . rejects ( new Error ( error ) ) ;
133
113
134
114
await assert . rejects ( command . action ( logger , {
135
115
options : {
136
116
name : 'My app'
137
117
}
138
- } ) , new CommandError ( `Multiple Microsoft Entra application registrations with name 'My app' found. Found: 9b1b1e42-794b-4c71-93ac-5ed92488b67f, 9b1b1e42-794b-4c71-93ac-5ed92488b67g.` ) ) ;
139
- } ) ;
140
-
141
- it ( 'handles selecting single result when multiple apps with the specified name found and cli is set to prompt' , async ( ) => {
142
- sinon . stub ( request , 'get' ) . callsFake ( async opts => {
143
- if ( opts . url === `https://graph.microsoft.com/v1.0/myorganization/applications?$filter=displayName eq 'My%20App'&$select=id` ) {
144
- return {
145
- value : [
146
- { id : '9b1b1e42-794b-4c71-93ac-5ed92488b67f' } ,
147
- { id : '9b1b1e42-794b-4c71-93ac-5ed92488b67g' }
148
- ]
149
- } ;
150
- }
151
-
152
- if ( opts . url === 'https://graph.microsoft.com/v1.0/myorganization/applications/9b1b1e42-794b-4c71-93ac-5ed92488b67f' ) {
153
- return {
154
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
155
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
156
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
157
- "displayName" : "My App" ,
158
- "description" : null
159
- } ;
160
- }
161
-
162
- throw `Invalid request ${ JSON . stringify ( opts ) } ` ;
163
- } ) ;
164
-
165
- sinon . stub ( cli , 'handleMultipleResultsFound' ) . resolves ( { id : '9b1b1e42-794b-4c71-93ac-5ed92488b67f' } ) ;
166
-
167
- await command . action ( logger , {
168
- options : {
169
- name : 'My App' ,
170
- debug : true
171
- }
172
- } ) ;
173
- const call : sinon . SinonSpyCall = loggerLogSpy . lastCall ;
174
- assert . deepEqual ( call . args [ 0 ] , {
175
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
176
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
177
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
178
- "displayName" : "My App" ,
179
- "description" : null
180
- } ) ;
118
+ } ) , new CommandError ( error ) ) ;
181
119
} ) ;
182
120
183
121
it ( 'handles error when retrieving information about app through name failed' , async ( ) => {
@@ -270,23 +208,13 @@ describe(commands.APP_GET, () => {
270
208
it ( `should get an Microsoft Entra app registration by its app (client) ID. Doesn't save the app info if not requested` , async ( ) => {
271
209
sinon . stub ( entraApp , 'getAppRegistrationByAppId' ) . resolves ( appResponse . value [ 0 ] ) ;
272
210
273
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
274
- if ( opts . url === "https://graph.microsoft.com/v1.0/myorganization/applications/340a4aa3-1af6-43ac-87d8-189819003952?$select=id,appId,displayName" ) {
275
- return {
276
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
277
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
278
- "displayName" : "My App"
279
- } ;
280
- }
281
-
282
- throw 'Invalid request' ;
283
- } ) ;
284
211
const fsWriteFileSyncSpy = sinon . spy ( fs , 'writeFileSync' ) ;
285
212
286
213
await command . action ( logger , {
287
214
options : {
288
215
appId : '9b1b1e42-794b-4c71-93ac-5ed92488b67f' ,
289
- properties : 'id,appId,displayName'
216
+ properties : 'id,appId,displayName' ,
217
+ verbose : true
290
218
}
291
219
} ) ;
292
220
const call : sinon . SinonSpyCall = loggerLogSpy . lastCall ;
@@ -297,38 +225,13 @@ describe(commands.APP_GET, () => {
297
225
} ) ;
298
226
299
227
it ( `should get an Microsoft Entra app registration by its name. Doesn't save the app info if not requested` , async ( ) => {
300
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
301
- if ( opts . url === `https://graph.microsoft.com/v1.0/myorganization/applications?$filter=displayName eq 'My%20App'&$select=id` ) {
302
- return {
303
- value : [
304
- {
305
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
306
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
307
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
308
- "displayName" : "My App" ,
309
- "description" : null
310
- }
311
- ]
312
- } ;
313
- }
314
-
315
- if ( ( opts . url as string ) . indexOf ( '/v1.0/myorganization/applications/' ) > - 1 ) {
316
- return {
317
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
318
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
319
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
320
- "displayName" : "My App" ,
321
- "description" : null
322
- } ;
323
- }
324
-
325
- throw 'Invalid request' ;
326
- } ) ;
228
+ sinon . stub ( entraApp , 'getAppRegistrationByAppName' ) . resolves ( appResponse . value [ 0 ] ) ;
327
229
const fsWriteFileSyncSpy = sinon . spy ( fs , 'writeFileSync' ) ;
328
230
329
231
await command . action ( logger , {
330
232
options : {
331
- name : 'My App'
233
+ name : 'My App' ,
234
+ verbose : true
332
235
}
333
236
} ) ;
334
237
const call : sinon . SinonSpyCall = loggerLogSpy . lastCall ;
@@ -339,24 +242,14 @@ describe(commands.APP_GET, () => {
339
242
} ) ;
340
243
341
244
it ( `should get an Microsoft Entra app registration by its object ID. Doesn't save the app info if not requested` , async ( ) => {
342
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
343
- if ( opts . url === `https://graph.microsoft.com/v1.0/myorganization/applications/340a4aa3-1af6-43ac-87d8-189819003952?$select=id,appId,displayName` ) {
344
- return {
345
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
346
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
347
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
348
- "displayName" : "My App" ,
349
- "description" : null
350
- } ;
351
- }
352
- throw 'Invalid request' ;
353
- } ) ;
245
+ sinon . stub ( entraApp , 'getAppRegistrationByObjectId' ) . resolves ( appResponse . value [ 0 ] ) ;
354
246
const fsWriteFileSyncSpy = sinon . spy ( fs , 'writeFileSync' ) ;
355
247
356
248
await command . action ( logger , {
357
249
options : {
358
250
objectId : '340a4aa3-1af6-43ac-87d8-189819003952' ,
359
- properties : 'id,appId,displayName'
251
+ properties : 'id,appId,displayName' ,
252
+ verbose : true
360
253
}
361
254
} ) ;
362
255
const call : sinon . SinonSpyCall = loggerLogSpy . lastCall ;
@@ -372,19 +265,6 @@ describe(commands.APP_GET, () => {
372
265
373
266
sinon . stub ( entraApp , 'getAppRegistrationByAppId' ) . resolves ( appResponse . value [ 0 ] ) ;
374
267
375
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
376
- if ( ( opts . url as string ) . indexOf ( '/v1.0/myorganization/applications/' ) > - 1 ) {
377
- return {
378
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
379
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
380
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
381
- "displayName" : "My App" ,
382
- "description" : null
383
- } ;
384
- }
385
-
386
- throw 'Invalid request' ;
387
- } ) ;
388
268
sinon . stub ( fs , 'existsSync' ) . returns ( false ) ;
389
269
sinon . stub ( fs , 'writeFileSync' ) . callsFake ( ( _ , contents ) => {
390
270
filePath = _ . toString ( ) ;
@@ -416,19 +296,6 @@ describe(commands.APP_GET, () => {
416
296
417
297
sinon . stub ( entraApp , 'getAppRegistrationByAppId' ) . resolves ( appResponse . value [ 0 ] ) ;
418
298
419
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
420
- if ( ( opts . url as string ) . indexOf ( '/v1.0/myorganization/applications/' ) > - 1 ) {
421
- return {
422
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
423
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
424
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
425
- "displayName" : "My App" ,
426
- "description" : null
427
- } ;
428
- }
429
-
430
- throw 'Invalid request' ;
431
- } ) ;
432
299
sinon . stub ( fs , 'existsSync' ) . returns ( true ) ;
433
300
sinon . stub ( fs , 'readFileSync' ) . returns ( '' ) ;
434
301
sinon . stub ( fs , 'writeFileSync' ) . callsFake ( ( _ , contents ) => {
@@ -460,20 +327,6 @@ describe(commands.APP_GET, () => {
460
327
let filePath : string | undefined ;
461
328
462
329
sinon . stub ( entraApp , 'getAppRegistrationByAppId' ) . resolves ( appResponse . value [ 0 ] ) ;
463
-
464
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
465
- if ( ( opts . url as string ) . indexOf ( '/v1.0/myorganization/applications/' ) > - 1 ) {
466
- return {
467
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
468
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
469
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
470
- "displayName" : "My App" ,
471
- "description" : null
472
- } ;
473
- }
474
-
475
- throw 'Invalid request' ;
476
- } ) ;
477
330
sinon . stub ( fs , 'existsSync' ) . returns ( true ) ;
478
331
sinon . stub ( fs , 'readFileSync' ) . returns ( JSON . stringify ( {
479
332
"apps" : [
@@ -517,20 +370,6 @@ describe(commands.APP_GET, () => {
517
370
let filePath : string | undefined ;
518
371
519
372
sinon . stub ( entraApp , 'getAppRegistrationByAppId' ) . resolves ( appResponse . value [ 0 ] ) ;
520
-
521
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
522
- if ( ( opts . url as string ) . indexOf ( '/v1.0/myorganization/applications/' ) > - 1 ) {
523
- return {
524
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
525
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
526
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
527
- "displayName" : "My App" ,
528
- "description" : null
529
- } ;
530
- }
531
-
532
- throw 'Invalid request' ;
533
- } ) ;
534
373
sinon . stub ( fs , 'existsSync' ) . returns ( true ) ;
535
374
sinon . stub ( fs , 'readFileSync' ) . returns ( JSON . stringify ( {
536
375
"apps" : [
@@ -572,20 +411,6 @@ describe(commands.APP_GET, () => {
572
411
573
412
it ( `doesn't save app info in the .m365rc.json file when there was error reading file contents` , async ( ) => {
574
413
sinon . stub ( entraApp , 'getAppRegistrationByAppId' ) . resolves ( appResponse . value [ 0 ] ) ;
575
-
576
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
577
- if ( ( opts . url as string ) . indexOf ( '/v1.0/myorganization/applications/' ) > - 1 ) {
578
- return {
579
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
580
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
581
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
582
- "displayName" : "My App" ,
583
- "description" : null
584
- } ;
585
- }
586
-
587
- throw 'Invalid request' ;
588
- } ) ;
589
414
sinon . stub ( fs , 'existsSync' ) . returns ( true ) ;
590
415
sinon . stub ( fs , 'readFileSync' ) . throws ( new Error ( 'An error has occurred' ) ) ;
591
416
const fsWriteFileSyncSpy = sinon . spy ( fs , 'writeFileSync' ) ;
@@ -601,20 +426,6 @@ describe(commands.APP_GET, () => {
601
426
602
427
it ( `doesn't save app info in the .m365rc.json file when file has invalid JSON` , async ( ) => {
603
428
sinon . stub ( entraApp , 'getAppRegistrationByAppId' ) . resolves ( appResponse . value [ 0 ] ) ;
604
-
605
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
606
- if ( ( opts . url as string ) . indexOf ( '/v1.0/myorganization/applications/' ) > - 1 ) {
607
- return {
608
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
609
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
610
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
611
- "displayName" : "My App" ,
612
- "description" : null
613
- } ;
614
- }
615
-
616
- throw 'Invalid request' ;
617
- } ) ;
618
429
sinon . stub ( fs , 'existsSync' ) . returns ( true ) ;
619
430
sinon . stub ( fs , 'readFileSync' ) . returns ( '{' ) ;
620
431
const fsWriteFileSyncSpy = sinon . spy ( fs , 'writeFileSync' ) ;
@@ -630,20 +441,6 @@ describe(commands.APP_GET, () => {
630
441
631
442
it ( `doesn't fail execution when error occurred while saving app info` , async ( ) => {
632
443
sinon . stub ( entraApp , 'getAppRegistrationByAppId' ) . resolves ( appResponse . value [ 0 ] ) ;
633
-
634
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
635
- if ( ( opts . url as string ) . indexOf ( '/v1.0/myorganization/applications/' ) > - 1 ) {
636
- return {
637
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
638
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
639
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
640
- "displayName" : "My App" ,
641
- "description" : null
642
- } ;
643
- }
644
-
645
- throw 'Invalid request' ;
646
- } ) ;
647
444
sinon . stub ( fs , 'existsSync' ) . returns ( false ) ;
648
445
sinon . stub ( fs , 'writeFileSync' ) . throws ( new Error ( 'Error occurred while saving app info' ) ) ;
649
446
0 commit comments