@@ -390,6 +390,94 @@ describe("Media library APIs", function () {
390390 } ) ;
391391 } ) ;
392392
393+ it ( 'Restore file version' , function ( done ) {
394+ var fileId = "fileId" ;
395+ var versionId = "versionId" ;
396+ const scope = nock ( 'https://api.imagekit.io' )
397+ . put ( `/v1/files/${ fileId } /versions/${ versionId } /restore` )
398+ . basicAuth ( { user : initializationParams . privateKey , pass : '' } )
399+ . reply ( function ( uri , requestBody ) {
400+ expect ( this . req . path ) . equal ( `/v1/files/${ fileId } /versions/${ versionId } /restore` )
401+ expect ( requestBody ) . to . be . empty ;
402+ done ( ) ;
403+ return [ 200 ]
404+ } ) ;
405+
406+ imagekit . restoreFileVersion ( {
407+ fileId,
408+ versionId,
409+ } )
410+ } ) ;
411+
412+ it ( 'Restore file version - missing fileId' , function ( done ) {
413+ imagekit . restoreFileVersion ( {
414+ fileId : null ,
415+ versionId : "versionId" ,
416+ } , function ( err , response ) {
417+ expect ( err ) . to . deep . equal ( {
418+ message : "Missing fileId parameter for this request" ,
419+ help : ""
420+ } )
421+ done ( ) ;
422+ } ) ;
423+ } ) ;
424+
425+ it ( 'Restore file version - missing versionId' , function ( done ) {
426+ imagekit . restoreFileVersion ( {
427+ fileId : "fileId" ,
428+ versionId : null
429+ } , function ( err , response ) {
430+ expect ( err ) . to . deep . equal ( {
431+ message : "Missing versionId parameter for this request" ,
432+ help : ""
433+ } )
434+ done ( ) ;
435+ } ) ;
436+ } ) ;
437+
438+ it ( 'Copy folder - default options' , function ( done ) {
439+ const scope = nock ( 'https://api.imagekit.io' )
440+ . post ( `/v1/bulkJobs/copyFolder` )
441+ . basicAuth ( { user : initializationParams . privateKey , pass : '' } )
442+ . reply ( function ( uri , requestBody ) {
443+ expect ( this . req . path ) . equal ( `/v1/bulkJobs/copyFolder` )
444+ expect ( requestBody ) . to . be . deep . equal ( {
445+ sourceFolderPath : "/source-folder" ,
446+ destinationPath : "/destination" ,
447+ includeFileVersions : false
448+ } )
449+ done ( ) ;
450+ return [ 200 ]
451+ } ) ;
452+
453+ imagekit . copyFolder ( {
454+ sourceFolderPath : "/source-folder" ,
455+ destinationPath : "/destination"
456+ } )
457+ } ) ;
458+
459+ it ( 'Copy folder' , function ( done ) {
460+ const scope = nock ( 'https://api.imagekit.io' )
461+ . post ( `/v1/bulkJobs/copyFolder` )
462+ . basicAuth ( { user : initializationParams . privateKey , pass : '' } )
463+ . reply ( function ( uri , requestBody ) {
464+ expect ( this . req . path ) . equal ( `/v1/bulkJobs/copyFolder` )
465+ expect ( requestBody ) . to . be . deep . equal ( {
466+ sourceFolderPath : "/source-folder" ,
467+ destinationPath : "/destination" ,
468+ includeFileVersions : true
469+ } )
470+ done ( ) ;
471+ return [ 200 ]
472+ } ) ;
473+
474+ imagekit . copyFolder ( {
475+ sourceFolderPath : "/source-folder" ,
476+ destinationPath : "/destination" ,
477+ includeFileVersions : true
478+ } )
479+ } ) ;
480+
393481 it ( 'Copy folder invalid sourceFolderPath' , function ( done ) {
394482 var destinationPath = "/" ;
395483 imagekit . copyFolder ( { sourceFolderPath : null , destinationPath } , function ( err , response ) {
@@ -423,6 +511,26 @@ describe("Media library APIs", function () {
423511 } ) ;
424512 } ) ;
425513
514+ it ( 'Move folder' , function ( done ) {
515+ const scope = nock ( 'https://api.imagekit.io' )
516+ . post ( `/v1/bulkJobs/moveFolder` )
517+ . basicAuth ( { user : initializationParams . privateKey , pass : '' } )
518+ . reply ( function ( uri , requestBody ) {
519+ expect ( this . req . path ) . equal ( `/v1/bulkJobs/moveFolder` )
520+ expect ( requestBody ) . to . be . deep . equal ( {
521+ sourceFolderPath : "/source-folder" ,
522+ destinationPath : "/destination"
523+ } )
524+ done ( ) ;
525+ return [ 200 ]
526+ } ) ;
527+
528+ imagekit . moveFolder ( {
529+ sourceFolderPath : "/source-folder" ,
530+ destinationPath : "/destination"
531+ } )
532+ } ) ;
533+
426534 it ( 'Move folder invalid destinationPath' , function ( done ) {
427535 var sourceFolderPath = "/" ;
428536 imagekit . moveFolder ( { sourceFolderPath, destinationPath : null } , function ( err , response ) {
@@ -445,6 +553,26 @@ describe("Media library APIs", function () {
445553 } ) ;
446554 } ) ;
447555
556+ it ( 'Create folder' , function ( done ) {
557+ const scope = nock ( 'https://api.imagekit.io' )
558+ . post ( `/v1/folder` )
559+ . basicAuth ( { user : initializationParams . privateKey , pass : '' } )
560+ . reply ( function ( uri , requestBody ) {
561+ expect ( this . req . path ) . equal ( `/v1/folder` )
562+ expect ( requestBody ) . to . be . deep . equal ( {
563+ folderName : "abc" ,
564+ parentFolderPath : "/path/to/folder"
565+ } )
566+ done ( ) ;
567+ return [ 200 ]
568+ } ) ;
569+
570+ imagekit . createFolder ( {
571+ folderName : "abc" ,
572+ parentFolderPath : "/path/to/folder"
573+ } )
574+ } ) ;
575+
448576 it ( 'Create folder invalid name' , function ( done ) {
449577 var folderName = "" ;
450578 var parentFolderPath = "" ;
@@ -469,6 +597,22 @@ describe("Media library APIs", function () {
469597 } ) ;
470598 } ) ;
471599
600+ it ( 'Delete folder' , function ( done ) {
601+ const scope = nock ( 'https://api.imagekit.io' )
602+ . delete ( `/v1/folder` )
603+ . basicAuth ( { user : initializationParams . privateKey , pass : '' } )
604+ . reply ( function ( uri , requestBody ) {
605+ expect ( this . req . path ) . equal ( `/v1/folder` )
606+ expect ( requestBody ) . to . be . deep . equal ( {
607+ folderPath : "/path/to/folder" ,
608+ } )
609+ done ( ) ;
610+ return [ 200 ]
611+ } ) ;
612+
613+ imagekit . deleteFolder ( "/path/to/folder" )
614+ } ) ;
615+
472616 it ( 'Delete folder invalid path' , function ( done ) {
473617 imagekit . deleteFolder ( null , function ( err , response ) {
474618 expect ( err ) . to . deep . equal ( {
@@ -992,6 +1136,48 @@ describe("Media library APIs", function () {
9921136 } , 50 ) ;
9931137 } ) ;
9941138
1139+ it ( 'Rename file' , function ( done ) {
1140+ const scope = nock ( 'https://api.imagekit.io' )
1141+ . post ( `/v1/files/rename` )
1142+ . basicAuth ( { user : initializationParams . privateKey , pass : '' } )
1143+ . reply ( 204 , dummyAPISuccessResponse )
1144+
1145+ var callback = sinon . spy ( ) ;
1146+
1147+ imagekit . renameFile ( {
1148+ filePath : "/xyz.jpg" ,
1149+ newFileName : "test.jpg"
1150+ } , callback ) ;
1151+
1152+ setTimeout ( function ( ) {
1153+ expect ( callback . calledOnce ) . to . be . true ;
1154+ sinon . assert . calledWith ( callback , null , dummyAPISuccessResponse ) ;
1155+ done ( ) ;
1156+ } , 50 ) ;
1157+ } ) ;
1158+
1159+ it ( 'Restore file version' , function ( done ) {
1160+ var fileId = "fileId" ;
1161+ var versionId = "versionId" ;
1162+ const scope = nock ( 'https://api.imagekit.io' )
1163+ . put ( `/v1/files/${ fileId } /versions/${ versionId } /restore` )
1164+ . basicAuth ( { user : initializationParams . privateKey , pass : '' } )
1165+ . reply ( 204 , dummyAPISuccessResponse )
1166+
1167+ var callback = sinon . spy ( ) ;
1168+
1169+ imagekit . restoreFileVersion ( {
1170+ fileId,
1171+ versionId
1172+ } , callback ) ;
1173+
1174+ setTimeout ( function ( ) {
1175+ expect ( callback . calledOnce ) . to . be . true ;
1176+ sinon . assert . calledWith ( callback , null , dummyAPISuccessResponse ) ;
1177+ done ( ) ;
1178+ } , 50 ) ;
1179+ } ) ;
1180+
9951181 it ( 'Copy folder' , function ( done ) {
9961182 var sourceFolderPath = "/folder2" ;
9971183 var destinationPath = "/folder1/" ;
@@ -1317,6 +1503,48 @@ describe("Media library APIs", function () {
13171503 } , 50 ) ;
13181504 } ) ;
13191505
1506+ it ( 'Rename file' , function ( done ) {
1507+ const scope = nock ( 'https://api.imagekit.io' )
1508+ . post ( `/v1/files/rename` )
1509+ . basicAuth ( { user : initializationParams . privateKey , pass : '' } )
1510+ . reply ( 500 , dummyAPIErrorResponse )
1511+
1512+ var callback = sinon . spy ( ) ;
1513+
1514+ imagekit . renameFile ( {
1515+ filePath : "/xyz.jpg" ,
1516+ newFileName : "test.jpg"
1517+ } , callback ) ;
1518+
1519+ setTimeout ( function ( ) {
1520+ expect ( callback . calledOnce ) . to . be . true ;
1521+ sinon . assert . calledWith ( callback , dummyAPIErrorResponse , null ) ;
1522+ done ( ) ;
1523+ } , 50 ) ;
1524+ } ) ;
1525+
1526+ it ( 'Restore file version' , function ( done ) {
1527+ var fileId = "fileId" ;
1528+ var versionId = "versionId" ;
1529+ const scope = nock ( 'https://api.imagekit.io' )
1530+ . put ( `/v1/files/${ fileId } /versions/${ versionId } /restore` )
1531+ . basicAuth ( { user : initializationParams . privateKey , pass : '' } )
1532+ . reply ( 500 , dummyAPIErrorResponse )
1533+
1534+ var callback = sinon . spy ( ) ;
1535+
1536+ imagekit . restoreFileVersion ( {
1537+ fileId,
1538+ versionId
1539+ } , callback ) ;
1540+
1541+ setTimeout ( function ( ) {
1542+ expect ( callback . calledOnce ) . to . be . true ;
1543+ sinon . assert . calledWith ( callback , dummyAPIErrorResponse , null ) ;
1544+ done ( ) ;
1545+ } , 50 ) ;
1546+ } ) ;
1547+
13201548 it ( 'Copy folder' , function ( done ) {
13211549 var sourceFolderPath = "/folder2" ;
13221550 var destinationPath = "/folder1/" ;
0 commit comments