@@ -23,43 +23,6 @@ describe(commands.HOMESITE_REMOVE, () => {
23
23
let commandInfo : CommandInfo ;
24
24
let commandOptionsSchema : z . ZodTypeAny ;
25
25
const siteId = '00000000-0000-0000-0000-000000000010' ;
26
- const homeSites = {
27
- "value" : [
28
- {
29
- "Audiences" : [
30
- {
31
-
32
- "Id" : "978b5280-4f80-47ea-a1db-b0d1d2fb1ba4" ,
33
- "Title" : "ColumnSearchable Members"
34
- } ,
35
- {
36
-
37
- "Id" : "21af775d-17b3-4637-94a4-2ba8625277cb" ,
38
- "Title" : "Contoso TeamR Members"
39
- }
40
- ] ,
41
- "IsInDraftMode" : false ,
42
- "IsVivaBackendSite" : false ,
43
- "SiteId" : "431d7819-4aaf-49a1-b664-b2fe9e609b63" ,
44
- "TargetedLicenseType" : 2 ,
45
- "Title" : "The Landing" ,
46
- "Url" : "https://contoso.sharepoint.com/sites/TheLanding" ,
47
- "VivaConnectionsDefaultStart" : true ,
48
- "WebId" : "626c1724-8ac8-45d5-af87-c07c752fab75"
49
- } ,
50
- {
51
- "Audiences" : [ ] ,
52
- "IsInDraftMode" : false ,
53
- "IsVivaBackendSite" : false ,
54
- "SiteId" : "45d4a135-40e4-4571-8340-61d17fdfd58a" ,
55
- "TargetedLicenseType" : 0 ,
56
- "Title" : "Contoso Electronics" ,
57
- "Url" : "https://contoso.sharepoint.com/sites/contosoportal" ,
58
- "VivaConnectionsDefaultStart" : true ,
59
- "WebId" : "9418e2a1-855c-4752-8dd4-48693f43b10a"
60
- }
61
- ]
62
- } ;
63
26
64
27
before ( ( ) => {
65
28
sinon . stub ( auth , 'restoreAuth' ) . resolves ( ) ;
@@ -143,17 +106,7 @@ describe(commands.HOMESITE_REMOVE, () => {
143
106
assert . strictEqual ( actual . success , false ) ;
144
107
} ) ;
145
108
146
- it ( 'removes the Home Site using legacy method when only one Home Site exists and prompt is confirmed' , async ( ) => {
147
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
148
- if ( opts . url === `https://contoso-admin.sharepoint.com/_api/SPO.Tenant/GetTargetedSitesDetails` ) {
149
- return { value : [ homeSites . value [ 0 ] ] } ;
150
- }
151
-
152
- throw 'Invalid request' ;
153
- } ) ;
154
-
155
- sinon . stub ( spo , 'getSiteAdminPropertiesByUrl' ) . resolves ( { SiteId : siteId } as any ) ;
156
-
109
+ it ( 'removes the Home Site when prompt confirmed' , async ( ) => {
157
110
let homeSiteRemoveCallIssued = false ;
158
111
159
112
sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
@@ -182,24 +135,14 @@ describe(commands.HOMESITE_REMOVE, () => {
182
135
assert ( homeSiteRemoveCallIssued ) ;
183
136
} ) ;
184
137
185
- it ( 'removes the first Home Site when multiple Home Sites exist and url is not specified' , async ( ) => {
186
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
187
- if ( opts . url === `https://contoso-admin.sharepoint.com/_api/SPO.Tenant/GetTargetedSitesDetails` ) {
188
- return homeSites ;
189
- }
190
-
191
- throw 'Invalid request' ;
192
- } ) ;
138
+ it ( 'removes the Home Site whithout confirm prompt' , async ( ) => {
139
+ let homeSiteRemoveCallIssued = false ;
193
140
194
- sinon . stub ( spo , 'getSiteAdminPropertiesByUrl' ) . resolves ( { SiteId : siteId } as any ) ;
141
+ sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
142
+ if ( opts . data === `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${ config . applicationName } " xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="28" ObjectPathId="27" /><Method Name="RemoveSPHSite" Id="29" ObjectPathId="27" /></Actions><ObjectPaths><Constructor Id="27" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>` ) {
195
143
196
- const postStub = sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
197
- if ( opts . url === `https://contoso-admin.sharepoint.com/_api/SPO.Tenant/RemoveTargetedSite` &&
198
- opts . data . siteId === siteId ) {
199
- return { } ;
200
- }
144
+ homeSiteRemoveCallIssued = true ;
201
145
202
- if ( opts . data === `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${ config . applicationName } " xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="28" ObjectPathId="27" /><Method Name="RemoveSPHSite" Id="29" ObjectPathId="27" /></Actions><ObjectPaths><Constructor Id="27" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>` ) {
203
146
return JSON . stringify (
204
147
[
205
148
{
@@ -215,36 +158,15 @@ describe(commands.HOMESITE_REMOVE, () => {
215
158
} ) ;
216
159
217
160
await command . action ( logger , { options : { force : true } } ) ;
218
- assert ( postStub . calledOnce ) ;
219
- assert . deepStrictEqual ( postStub . lastCall . args [ 0 ] . url , "https://contoso-admin.sharepoint.com/_api/SPO.Tenant/RemoveTargetedSite" ) ;
161
+ assert ( homeSiteRemoveCallIssued ) ;
220
162
} ) ;
221
163
222
164
it ( 'removes the Home Site specified by URL' , async ( ) => {
223
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
224
- if ( opts . url === `https://contoso-admin.sharepoint.com/_api/SPO.Tenant/GetTargetedSitesDetails` ) {
225
- return homeSites ;
226
- }
227
-
228
- throw 'Invalid request' ;
229
- } ) ;
230
-
231
165
sinon . stub ( spo , 'getSiteAdminPropertiesByUrl' ) . resolves ( { SiteId : siteId } as any ) ;
232
- const postStub = sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
233
- if ( opts . url === `https://contoso-admin.sharepoint.com/_api/SPO.Tenant/RemoveTargetedSite` &&
234
- opts . data ?. siteId === siteId ) {
235
- return { } ;
236
- }
237
166
238
- if ( opts . data === `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${ config . applicationName } " xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="28" ObjectPathId="27" /><Method Name="RemoveSPHSite" Id="29" ObjectPathId="27" /></Actions><ObjectPaths><Constructor Id="27" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>` ) {
239
- return JSON . stringify (
240
- [
241
- {
242
- "SchemaVersion" : "15.0.0.0" , "LibraryVersion" : "16.0.8929.1227" , "ErrorInfo" : null , "TraceCorrelationId" : "e4f2e59e-c0a9-0000-3dd0-1d8ef12cc742"
243
- } , 57 , {
244
- "IsNull" : false
245
- } , 58 , "The Home site has been removed."
246
- ]
247
- ) ;
167
+ const postStub = sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
168
+ if ( opts . url === `https://contoso-admin.sharepoint.com/_api/SPO.Tenant/RemoveTargetedSite` ) {
169
+ return ;
248
170
}
249
171
250
172
throw 'Invalid request' ;
@@ -255,19 +177,10 @@ describe(commands.HOMESITE_REMOVE, () => {
255
177
256
178
await command . action ( logger , { options : { url : 'https://contoso.sharepoint.com' } } ) ;
257
179
assert ( postStub . calledOnce ) ;
180
+ assert . deepStrictEqual ( postStub . lastCall . args [ 0 ] . data , { siteId } ) ;
258
181
} ) ;
259
182
260
183
it ( 'correctly handles error when removing the Home Site (debug)' , async ( ) => {
261
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
262
- if ( opts . url === `https://contoso-admin.sharepoint.com/_api/SPO.Tenant/GetTargetedSitesDetails` ) {
263
- return { value : [ homeSites . value [ 0 ] ] } ;
264
- }
265
-
266
- throw 'Invalid request' ;
267
- } ) ;
268
-
269
- sinon . stub ( spo , 'getSiteAdminPropertiesByUrl' ) . resolves ( { SiteId : siteId } as any ) ;
270
-
271
184
sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
272
185
if ( opts . data === `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${ config . applicationName } " xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="28" ObjectPathId="27" /><Method Name="RemoveSPHSite" Id="29" ObjectPathId="27" /></Actions><ObjectPaths><Constructor Id="27" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>` ) {
273
186
return JSON . stringify (
@@ -287,4 +200,23 @@ describe(commands.HOMESITE_REMOVE, () => {
287
200
await assert . rejects ( command . action ( logger , { options : { debug : true , force : true } } as any ) ,
288
201
new CommandError ( `The requested operation is part of an experimental feature that is not supported in the current environment.` ) ) ;
289
202
} ) ;
203
+
204
+ it ( 'correctly handles error when attempting to remove a site that is not a home site or Viva Connections' , async ( ) => {
205
+ sinon . stub ( request , 'post' ) . rejects ( {
206
+ error : {
207
+ "odata.error" : {
208
+ "code" : "-2146232832, Microsoft.SharePoint.SPException" ,
209
+ "message" : {
210
+ "lang" : "en-US" ,
211
+ "value" : "[Error ID: 03fc404e-0f70-4607-82e8-8fdb014e8658] The site with ID \"8e4686ed-b00c-4c5f-a0e2-4197081df5d5\" has not been added as a home site or Viva Connections. Check aka.ms/homesites for details."
212
+ }
213
+ }
214
+ }
215
+ } ) ;
216
+
217
+ await assert . rejects (
218
+ command . action ( logger , { options : { debug : true , force : true } } as any ) ,
219
+ new CommandError ( '[Error ID: 03fc404e-0f70-4607-82e8-8fdb014e8658] The site with ID \"8e4686ed-b00c-4c5f-a0e2-4197081df5d5\" has not been added as a home site or Viva Connections. Check aka.ms/homesites for details.' )
220
+ ) ;
221
+ } ) ;
290
222
} ) ;
0 commit comments