@@ -10,6 +10,7 @@ import { telemetry } from '../../../../telemetry.js';
1010import { pid } from '../../../../utils/pid.js' ;
1111import { session } from '../../../../utils/session.js' ;
1212import { sinonUtil } from '../../../../utils/sinonUtil.js' ;
13+ import { formatting } from '../../../../utils/formatting.js' ;
1314import { z } from 'zod' ;
1415import commands from '../../commands.js' ;
1516import command from './file-unarchive.js' ;
@@ -20,6 +21,7 @@ describe(commands.FILE_UNARCHIVE, () => {
2021 let commandInfo : CommandInfo ;
2122 let commandOptionsSchema : z . ZodTypeAny ;
2223 let confirmationPromptStub : sinon . SinonStub ;
24+ let loggerLogSpy : sinon . SinonSpy ;
2325
2426 before ( ( ) => {
2527 sinon . stub ( auth , 'restoreAuth' ) . resolves ( ) ;
@@ -46,6 +48,7 @@ describe(commands.FILE_UNARCHIVE, () => {
4648 log . push ( msg ) ;
4749 }
4850 } ;
51+ loggerLogSpy = sinon . spy ( logger , 'log' ) ;
4952 confirmationPromptStub = sinon . stub ( cli , 'promptForConfirmation' ) . resolves ( false ) ;
5053 } ) ;
5154
@@ -130,6 +133,9 @@ describe(commands.FILE_UNARCHIVE, () => {
130133 } ) ;
131134
132135 it ( 'prompts before unarchiving file when confirmation argument not passed' , async ( ) => {
136+ sinon . stub ( request , 'get' ) . resolves ( { ListId : 'b2307a39-e878-458b-bc90-03bc578531d6' , ListItemAllFields : { Id : 1 } } ) ;
137+ sinon . stub ( request , 'post' ) . resolves ( ) ;
138+
133139 await command . action ( logger , {
134140 options : {
135141 webUrl : 'https://contoso.sharepoint.com' ,
@@ -140,6 +146,7 @@ describe(commands.FILE_UNARCHIVE, () => {
140146 } ) ;
141147
142148 it ( 'aborts unarchiving file when prompt not confirmed' , async ( ) => {
149+ const getStub = sinon . stub ( request , 'get' ) . resolves ( { ListId : 'b2307a39-e878-458b-bc90-03bc578531d6' , ListItemAllFields : { Id : 1 } } ) ;
143150 const postStub = sinon . stub ( request , 'post' ) . resolves ( ) ;
144151
145152 await command . action ( logger , {
@@ -149,12 +156,13 @@ describe(commands.FILE_UNARCHIVE, () => {
149156 }
150157 } ) ;
151158
159+ assert ( getStub . notCalled ) ;
152160 assert ( postStub . notCalled ) ;
153161 } ) ;
154162
155- it ( 'unarchives file by url when prompt confirmed ' , async ( ) => {
163+ it ( 'unarchives file by url' , async ( ) => {
156164 sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
157- if ( opts . url === `https://contoso.sharepoint.com/sites/test/_api/web/GetFileByServerRelativePath(DecodedUrl=@f) ?$select=ListId&$expand=ListItemAllFields&@f='%2Fsites%2Ftest%2FShared%20documents%2Fdocument.docx' ` ) {
165+ if ( opts . url === `https://contoso.sharepoint.com/sites/test/_api/web/GetFileByServerRelativePath(DecodedUrl=' ${ formatting . encodeQueryParameter ( '/sites/test/Shared documents/document.docx' ) } ') ?$select=ListId,ListItemAllFields/Id &$expand=ListItemAllFields` ) {
158166 return {
159167 ListId : 'b2307a39-e878-458b-bc90-03bc578531d6' ,
160168 ListItemAllFields : {
@@ -174,22 +182,20 @@ describe(commands.FILE_UNARCHIVE, () => {
174182 throw 'Invalid request' ;
175183 } ) ;
176184
177- sinonUtil . restore ( cli . promptForConfirmation ) ;
178- sinon . stub ( cli , 'promptForConfirmation' ) . resolves ( true ) ;
179-
180185 await command . action ( logger , {
181186 options : {
182187 webUrl : 'https://contoso.sharepoint.com/sites/test' ,
183- url : '/sites/test/Shared documents/document.docx'
188+ url : '/sites/test/Shared documents/document.docx' ,
189+ force : true
184190 }
185191 } ) ;
186192
187- assert . deepStrictEqual ( postStub . lastCall . args [ 0 ] . url , `https://contoso.sharepoint.com/sites/test/_api/Lists(guid'b2307a39-e878-458b-bc90-03bc578531d6')/items(1)/UnArchive` ) ;
193+ assert ( postStub . calledOnce ) ;
188194 } ) ;
189195
190- it ( 'unarchives file by id when prompt confirmed ' , async ( ) => {
196+ it ( 'unarchives file by id' , async ( ) => {
191197 sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
192- if ( opts . url === `https://contoso.sharepoint.com/sites/test/_api/web/GetFileById('00000000-0000-0000-0000-000000000000')?$select=ListId&$expand=ListItemAllFields` ) {
198+ if ( opts . url === `https://contoso.sharepoint.com/sites/test/_api/web/GetFileById('${ formatting . encodeQueryParameter ( ' 00000000-0000-0000-0000-000000000000') } ') ?$select=ListId,ListItemAllFields/Id &$expand=ListItemAllFields` ) {
193199 return {
194200 ListId : 'b2307a39-e878-458b-bc90-03bc578531d6' ,
195201 ListItemAllFields : {
@@ -210,22 +216,21 @@ describe(commands.FILE_UNARCHIVE, () => {
210216 throw 'Invalid request' ;
211217 } ) ;
212218
213- sinonUtil . restore ( cli . promptForConfirmation ) ;
214- sinon . stub ( cli , 'promptForConfirmation' ) . resolves ( true ) ;
215-
216219 await command . action ( logger , {
217220 options : {
218221 webUrl : 'https://contoso.sharepoint.com/sites/test' ,
219- id : '00000000-0000-0000-0000-000000000000'
222+ id : '00000000-0000-0000-0000-000000000000' ,
223+ verbose : true ,
224+ force : true
220225 }
221226 } ) ;
222227
223- assert . deepStrictEqual ( postStub . lastCall . args [ 0 ] . url , `https://contoso.sharepoint.com/sites/test/_api/Lists(guid'b2307a39-e878-458b-bc90-03bc578531d6')/items(1)/UnArchive` ) ;
228+ assert ( postStub . calledOnce ) ;
224229 } ) ;
225230
226- it ( 'unarchives file by url' , async ( ) => {
231+ it ( 'unarchives file using site-relative url' , async ( ) => {
227232 sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
228- if ( opts . url === `https://contoso.sharepoint.com/sites/test/_api/web/GetFileByServerRelativePath(DecodedUrl=@f) ?$select=ListId&$expand=ListItemAllFields&@f='%2Fsites%2Ftest%2FShared%20documents%2Fdocument.docx' ` ) {
233+ if ( opts . url === `https://contoso.sharepoint.com/sites/test/_api/web/GetFileByServerRelativePath(DecodedUrl=' ${ formatting . encodeQueryParameter ( '/sites/test/Shared Documents/document.docx' ) } ') ?$select=ListId,ListItemAllFields/Id &$expand=ListItemAllFields` ) {
229234 return {
230235 ListId : 'b2307a39-e878-458b-bc90-03bc578531d6' ,
231236 ListItemAllFields : {
@@ -248,47 +253,27 @@ describe(commands.FILE_UNARCHIVE, () => {
248253 await command . action ( logger , {
249254 options : {
250255 webUrl : 'https://contoso.sharepoint.com/sites/test' ,
251- url : '/sites/test/ Shared documents /document.docx' ,
256+ url : '/Shared Documents /document.docx' ,
252257 force : true
253258 }
254259 } ) ;
255260
256- assert . deepStrictEqual ( postStub . lastCall . args [ 0 ] . url , `https://contoso.sharepoint.com/sites/test/_api/Lists(guid'b2307a39-e878-458b-bc90-03bc578531d6')/items(1)/UnArchive` ) ;
261+ assert ( postStub . calledOnce ) ;
257262 } ) ;
258263
259- it ( 'unarchives file by id' , async ( ) => {
260- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
261- if ( opts . url === `https://contoso.sharepoint.com/sites/test/_api/web/GetFileById('00000000-0000-0000-0000-000000000000')?$select=ListId&$expand=ListItemAllFields` ) {
262- return {
263- ListId : 'b2307a39-e878-458b-bc90-03bc578531d6' ,
264- ListItemAllFields : {
265- Id : 1
266- }
267- } ;
268- }
269-
270- throw 'Invalid request' ;
271- }
272- ) ;
273-
274- const postStub = sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
275- if ( opts . url === `https://contoso.sharepoint.com/sites/test/_api/Lists(guid'b2307a39-e878-458b-bc90-03bc578531d6')/items(1)/UnArchive` ) {
276- return ;
277- }
278-
279- throw 'Invalid request' ;
280- } ) ;
264+ it ( 'outputs no result when unarchiving a file' , async ( ) => {
265+ sinon . stub ( request , 'get' ) . resolves ( { ListId : 'b2307a39-e878-458b-bc90-03bc578531d6' , ListItemAllFields : { Id : 1 } } ) ;
266+ sinon . stub ( request , 'post' ) . resolves ( ) ;
281267
282268 await command . action ( logger , {
283269 options : {
284270 webUrl : 'https://contoso.sharepoint.com/sites/test' ,
285- id : '00000000-0000-0000-0000-000000000000' ,
286- verbose : true ,
271+ url : '/sites/test/Shared documents/document.docx' ,
287272 force : true
288273 }
289274 } ) ;
290275
291- assert . deepStrictEqual ( postStub . lastCall . args [ 0 ] . url , `https://contoso.sharepoint.com/sites/test/_api/Lists(guid'b2307a39-e878-458b-bc90-03bc578531d6')/items(1)/UnArchive` ) ;
276+ assert ( loggerLogSpy . notCalled ) ;
292277 } ) ;
293278
294279 it ( 'handles error correctly' , async ( ) => {
0 commit comments