@@ -9,10 +9,10 @@ import { session } from '../../../../utils/session.js';
9
9
import { sinonUtil } from '../../../../utils/sinonUtil.js' ;
10
10
import commands from '../../commands.js' ;
11
11
import command from './container-list.js' ;
12
- import { spo } from '../../../../utils/spo.js' ;
13
12
import { CommandError } from '../../../../Command.js' ;
14
13
import { CommandInfo } from '../../../../cli/CommandInfo.js' ;
15
14
import { cli } from '../../../../cli/cli.js' ;
15
+ import { spe } from '../../../../utils/spe.js' ;
16
16
17
17
describe ( commands . CONTAINER_LIST , ( ) => {
18
18
let log : string [ ] ;
@@ -34,40 +34,12 @@ describe(commands.CONTAINER_LIST, () => {
34
34
"createdDateTime" : "2021-11-24T15:41:52.347Z"
35
35
} ] ;
36
36
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
-
64
37
before ( ( ) => {
65
38
sinon . stub ( auth , 'restoreAuth' ) . resolves ( ) ;
66
39
sinon . stub ( telemetry , 'trackEvent' ) . resolves ( ) ;
67
40
sinon . stub ( pid , 'getProcessName' ) . returns ( '' ) ;
68
41
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
+
71
43
auth . connection . active = true ;
72
44
auth . connection . spoUrl = 'https://contoso.sharepoint.com' ;
73
45
commandInfo = cli . getCommandInfo ( command ) ;
@@ -87,14 +59,15 @@ describe(commands.CONTAINER_LIST, () => {
87
59
}
88
60
} ;
89
61
loggerLogSpy = sinon . spy ( logger , 'log' ) ;
62
+
63
+ sinon . stub ( spe , 'getContainerTypeIdByName' ) . withArgs ( adminUrl , 'standard container' ) . resolves ( 'e2756c4d-fa33-4452-9c36-2325686e1082' ) ;
90
64
} ) ;
91
65
92
66
afterEach ( ( ) => {
93
67
sinonUtil . restore ( [
94
68
request . get ,
95
69
request . post ,
96
- spo . getSpoAdminUrl ,
97
- spo . getAllContainerTypes
70
+ spe . getContainerTypeIdByName
98
71
] ) ;
99
72
} ) ;
100
73
@@ -135,13 +108,11 @@ describe(commands.CONTAINER_LIST, () => {
135
108
throw 'Invalid request' ;
136
109
} ) ;
137
110
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 } } ) ;
139
112
assert ( loggerLogSpy . calledWith ( containersList ) ) ;
140
113
} ) ;
141
114
142
115
it ( 'retrieves list of container type by name' , async ( ) => {
143
- sinon . stub ( spo , 'getAllContainerTypes' ) . resolves ( containerTypedata ) ;
144
-
145
116
sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
146
117
if ( opts . url === 'https://graph.microsoft.com/v1.0/storage/fileStorage/containers?$filter=containerTypeId eq e2756c4d-fa33-4452-9c36-2325686e1082' ) {
147
118
return { "value" : containersList } ;
@@ -150,32 +121,19 @@ describe(commands.CONTAINER_LIST, () => {
150
121
throw 'Invalid request' ;
151
122
} ) ;
152
123
153
- await command . action ( logger , { options : { containerTypeName : "standard container" , debug : true } } ) ;
124
+ await command . action ( logger , { options : { containerTypeName : "standard container" , verbose : true } } ) ;
154
125
assert ( loggerLogSpy . calledWith ( containersList ) ) ;
155
126
} ) ;
156
127
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
-
172
128
it ( 'correctly handles error when retrieving containers' , async ( ) => {
173
129
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 ) ) ;
175
132
176
133
await assert . rejects ( command . action ( logger , {
177
134
options : {
178
- debug : true
135
+ containerTypeName : "nonexisting container" ,
136
+ verbose : true
179
137
}
180
138
} ) , new CommandError ( 'An error has occurred' ) ) ;
181
139
} ) ;
0 commit comments