@@ -9,10 +9,10 @@ import { session } from '../../../../utils/session.js';
99import { sinonUtil } from '../../../../utils/sinonUtil.js' ;
1010import commands from '../../commands.js' ;
1111import command from './container-list.js' ;
12- import { spo } from '../../../../utils/spo.js' ;
1312import { CommandError } from '../../../../Command.js' ;
1413import { CommandInfo } from '../../../../cli/CommandInfo.js' ;
1514import { cli } from '../../../../cli/cli.js' ;
15+ import { spe } from '../../../../utils/spe.js' ;
1616
1717describe ( commands . CONTAINER_LIST , ( ) => {
1818 let log : string [ ] ;
@@ -34,40 +34,12 @@ describe(commands.CONTAINER_LIST, () => {
3434 "createdDateTime" : "2021-11-24T15:41:52.347Z"
3535 } ] ;
3636
37- const containerTypedata = [ {
38- "AzureSubscriptionId" : "/Guid(f08575e2-36c4-407f-a891-eabae23f66bc)" ,
39- "ContainerTypeId" : "/Guid(e2756c4d-fa33-4452-9c36-2325686e1082)" ,
40- "CreationDate" : "3/11/2024 2:38:56 PM" ,
41- "DisplayName" : "standard container" ,
42- "ExpiryDate" : "3/11/2028 2:38:56 PM" ,
43- "IsBillingProfileRequired" : true ,
44- "OwningAppId" : "/Guid(1b3b8660-9a44-4a7c-9c02-657f3ff5d5ac)" ,
45- "OwningTenantId" : "/Guid(e1dd4023-a656-480a-8a0e-c1b1eec51e1d)" ,
46- "Region" : "West Europe" ,
47- "ResourceGroup" : "Standard group" ,
48- "SPContainerTypeBillingClassification" : "Standard"
49- } ,
50- {
51- "AzureSubscriptionId" : "/Guid(f08575e2-36c4-407f-a891-eabae23f66bc)" ,
52- "ContainerTypeId" : "/Guid(e2756c4d-fa33-4452-9c36-2325686e1082)" ,
53- "CreationDate" : "3/11/2024 2:38:56 PM" ,
54- "DisplayName" : "trial container" ,
55- "ExpiryDate" : "3/11/2028 2:38:56 PM" ,
56- "IsBillingProfileRequired" : true ,
57- "OwningAppId" : "/Guid(1b3b8660-9a44-4a7c-9c02-657f3ff5d5ac)" ,
58- "OwningTenantId" : "/Guid(e1dd4023-a656-480a-8a0e-c1b1eec51e1d)" ,
59- "Region" : "West Europe" ,
60- "ResourceGroup" : "Standard group" ,
61- "SPContainerTypeBillingClassification" : "Standard"
62- } ] ;
63-
6437 before ( ( ) => {
6538 sinon . stub ( auth , 'restoreAuth' ) . resolves ( ) ;
6639 sinon . stub ( telemetry , 'trackEvent' ) . resolves ( ) ;
6740 sinon . stub ( pid , 'getProcessName' ) . returns ( '' ) ;
6841 sinon . stub ( session , 'getId' ) . returns ( '' ) ;
69- sinon . stub ( spo , 'getSpoAdminUrl' ) . resolves ( adminUrl ) ;
70- sinon . stub ( spo , 'ensureFormDigest' ) . resolves ( { FormDigestValue : 'abc' , FormDigestTimeoutSeconds : 1800 , FormDigestExpiresAt : new Date ( ) , WebFullUrl : 'https://contoso.sharepoint.com' } ) ;
42+
7143 auth . connection . active = true ;
7244 auth . connection . spoUrl = 'https://contoso.sharepoint.com' ;
7345 commandInfo = cli . getCommandInfo ( command ) ;
@@ -87,14 +59,15 @@ describe(commands.CONTAINER_LIST, () => {
8759 }
8860 } ;
8961 loggerLogSpy = sinon . spy ( logger , 'log' ) ;
62+
63+ sinon . stub ( spe , 'getContainerTypeIdByName' ) . withArgs ( adminUrl , 'standard container' ) . resolves ( 'e2756c4d-fa33-4452-9c36-2325686e1082' ) ;
9064 } ) ;
9165
9266 afterEach ( ( ) => {
9367 sinonUtil . restore ( [
9468 request . get ,
9569 request . post ,
96- spo . getSpoAdminUrl ,
97- spo . getAllContainerTypes
70+ spe . getContainerTypeIdByName
9871 ] ) ;
9972 } ) ;
10073
@@ -135,13 +108,11 @@ describe(commands.CONTAINER_LIST, () => {
135108 throw 'Invalid request' ;
136109 } ) ;
137110
138- await command . action ( logger , { options : { containerTypeId : "e2756c4d-fa33-4452-9c36-2325686e1082" , debug : true } } ) ;
111+ await command . action ( logger , { options : { containerTypeId : "e2756c4d-fa33-4452-9c36-2325686e1082" , verbose : true } } ) ;
139112 assert ( loggerLogSpy . calledWith ( containersList ) ) ;
140113 } ) ;
141114
142115 it ( 'retrieves list of container type by name' , async ( ) => {
143- sinon . stub ( spo , 'getAllContainerTypes' ) . resolves ( containerTypedata ) ;
144-
145116 sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
146117 if ( opts . url === 'https://graph.microsoft.com/v1.0/storage/fileStorage/containers?$filter=containerTypeId eq e2756c4d-fa33-4452-9c36-2325686e1082' ) {
147118 return { "value" : containersList } ;
@@ -150,32 +121,19 @@ describe(commands.CONTAINER_LIST, () => {
150121 throw 'Invalid request' ;
151122 } ) ;
152123
153- await command . action ( logger , { options : { containerTypeName : "standard container" , debug : true } } ) ;
124+ await command . action ( logger , { options : { containerTypeName : "standard container" , verbose : true } } ) ;
154125 assert ( loggerLogSpy . calledWith ( containersList ) ) ;
155126 } ) ;
156127
157- it ( 'throws an error when service principal is not found' , async ( ) => {
158- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
159- if ( opts . url === 'https://graph.microsoft.com/v1.0/storage/fileStorage/containers?$filter=containerTypeId eq e2756c4d-fa33-4452-9c36-2325686e1086' ) {
160- return [ ] ;
161- }
162-
163- throw 'Invalid request' ;
164- } ) ;
165-
166- sinon . stub ( spo , 'getAllContainerTypes' ) . resolves ( containerTypedata ) ;
167-
168- await assert . rejects ( command . action ( logger , { options : { containerTypeName : "nonexisting container" , debug : true } } ) ,
169- new CommandError ( `Container type with name nonexisting container not found` ) ) ;
170- } ) ;
171-
172128 it ( 'correctly handles error when retrieving containers' , async ( ) => {
173129 const error = 'An error has occurred' ;
174- sinon . stub ( spo , 'getAllContainerTypes' ) . rejects ( new Error ( error ) ) ;
130+ sinonUtil . restore ( spe . getContainerTypeIdByName ) ;
131+ sinon . stub ( spe , 'getContainerTypeIdByName' ) . rejects ( new Error ( error ) ) ;
175132
176133 await assert . rejects ( command . action ( logger , {
177134 options : {
178- debug : true
135+ containerTypeName : "nonexisting container" ,
136+ verbose : true
179137 }
180138 } ) , new CommandError ( 'An error has occurred' ) ) ;
181139 } ) ;
0 commit comments