@@ -453,19 +453,151 @@ describe(commands.FOLDER_COPY, () => {
453453 }
454454 } ) ;
455455
456- it ( 'should combine url with baseUrl that last char is /' , ( ) => {
457- const actual = ( command as any ) . urlCombine ( 'https://contoso.com/' , 'sites/abc' ) ;
458- assert . equal ( actual , 'https://contoso.com/sites/abc' ) ;
456+ it ( 'should complete successfully where baseUrl has a trailing /' , ( done ) => {
457+ let actual : string = '' ;
458+ const expected : string = JSON . stringify ( {
459+ exportObjectUris : [
460+ 'https://contoso.sharepoint.com/sites/team-a/library/folder1'
461+ ] ,
462+ destinationUri : 'https://contoso.sharepoint.com/sites/team-b/library2' ,
463+ options : {
464+ 'AllowSchemaMismatch' : false ,
465+ 'IgnoreVersionHistory' : true
466+ }
467+ } ) ;
468+
469+ sinon . stub ( request , 'post' ) . callsFake ( ( opts ) => {
470+ actual = JSON . stringify ( opts . body ) ;
471+ if (
472+ opts . body . exportObjectUris [ 0 ] === 'https://contoso.sharepoint.com/sites/team-a/library/folder1' &&
473+ opts . body . destinationUri === 'https://contoso.sharepoint.com/sites/team-b/library2' &&
474+ opts . url === 'https://contoso.sharepoint.com/sites/team-a/_api/site/CreateCopyJobs'
475+ ) {
476+ return Promise . resolve ( ) ;
477+
478+ }
479+ return Promise . reject ( 'Invalid request' ) ;
480+
481+ } ) ;
482+
483+ auth . site = new Site ( ) ;
484+ auth . site . connected = true ;
485+ auth . site . url = 'https://contoso.sharepoint.com' ;
486+ cmdInstance . action = command . action ( ) ;
487+
488+ cmdInstance . action ( {
489+ options : {
490+ webUrl : 'https://contoso.sharepoint.com/sites/team-a/' ,
491+ sourceUrl : 'library/folder1' ,
492+ targetUrl : 'sites/team-b/library2'
493+ }
494+ } , ( ) => {
495+ try {
496+ assert . equal ( actual , expected ) ;
497+ done ( ) ;
498+ }
499+ catch ( e ) {
500+ done ( e ) ;
501+ }
502+ } ) ;
459503 } ) ;
460504
461- it ( 'should combine url with relativeUrl that last char is /' , ( ) => {
462- const actual = ( command as any ) . urlCombine ( 'https://contoso.com' , 'sites/abc/' ) ;
463- assert . equal ( actual , 'https://contoso.com/sites/abc' ) ;
505+ it ( 'should complete successfully where sourceUrl and targetUrl has a trailing /' , ( done ) => {
506+ let actual : string = '' ;
507+ const expected : string = JSON . stringify ( {
508+ exportObjectUris : [
509+ 'https://contoso.sharepoint.com/sites/team-a/library/folder1'
510+ ] ,
511+ destinationUri : 'https://contoso.sharepoint.com/sites/team-b/library2' ,
512+ options : {
513+ 'AllowSchemaMismatch' : false ,
514+ 'IgnoreVersionHistory' : true
515+ }
516+ } ) ;
517+
518+ sinon . stub ( request , 'post' ) . callsFake ( ( opts ) => {
519+ actual = JSON . stringify ( opts . body ) ;
520+ if (
521+ opts . body . exportObjectUris [ 0 ] === 'https://contoso.sharepoint.com/sites/team-a/library/folder1' &&
522+ opts . body . destinationUri === 'https://contoso.sharepoint.com/sites/team-b/library2' &&
523+ opts . url === 'https://contoso.sharepoint.com/sites/team-a/_api/site/CreateCopyJobs'
524+ ) {
525+ return Promise . resolve ( ) ;
526+
527+ }
528+ return Promise . reject ( 'Invalid request' ) ;
529+
530+ } ) ;
531+
532+ auth . site = new Site ( ) ;
533+ auth . site . connected = true ;
534+ auth . site . url = 'https://contoso.sharepoint.com' ;
535+ cmdInstance . action = command . action ( ) ;
536+
537+ cmdInstance . action ( {
538+ options : {
539+ webUrl : 'https://contoso.sharepoint.com/sites/team-a/' ,
540+ sourceUrl : 'library/folder1/' ,
541+ targetUrl : 'sites/team-b/library2/'
542+ }
543+ } , ( ) => {
544+ try {
545+ assert . equal ( actual , expected ) ;
546+ done ( ) ;
547+ }
548+ catch ( e ) {
549+ done ( e ) ;
550+ }
551+ } ) ;
464552 } ) ;
465553
466- it ( 'should combine url with relativeUrl that first char is /' , ( ) => {
467- const actual = ( command as any ) . urlCombine ( 'https://contoso.com/' , '/sites/abc/' ) ;
468- assert . equal ( actual , 'https://contoso.com/sites/abc' ) ;
554+ it ( 'should complete successfully where sourceUrl and targetUrl has a beginning /' , ( done ) => {
555+ let actual : string = '' ;
556+ const expected : string = JSON . stringify ( {
557+ exportObjectUris : [
558+ 'https://contoso.sharepoint.com/sites/team-a/library/folder1'
559+ ] ,
560+ destinationUri : 'https://contoso.sharepoint.com/sites/team-b/library2' ,
561+ options : {
562+ 'AllowSchemaMismatch' : false ,
563+ 'IgnoreVersionHistory' : true
564+ }
565+ } ) ;
566+
567+ sinon . stub ( request , 'post' ) . callsFake ( ( opts ) => {
568+ actual = JSON . stringify ( opts . body ) ;
569+ if (
570+ opts . body . exportObjectUris [ 0 ] === 'https://contoso.sharepoint.com/sites/team-a/library/folder1' &&
571+ opts . body . destinationUri === 'https://contoso.sharepoint.com/sites/team-b/library2' &&
572+ opts . url === 'https://contoso.sharepoint.com/sites/team-a/_api/site/CreateCopyJobs'
573+ ) {
574+ return Promise . resolve ( ) ;
575+
576+ }
577+ return Promise . reject ( 'Invalid request' ) ;
578+
579+ } ) ;
580+
581+ auth . site = new Site ( ) ;
582+ auth . site . connected = true ;
583+ auth . site . url = 'https://contoso.sharepoint.com' ;
584+ cmdInstance . action = command . action ( ) ;
585+
586+ cmdInstance . action ( {
587+ options : {
588+ webUrl : 'https://contoso.sharepoint.com/sites/team-a/' ,
589+ sourceUrl : '/library/folder1/' ,
590+ targetUrl : '/sites/team-b/library2/'
591+ }
592+ } , ( ) => {
593+ try {
594+ assert . equal ( actual , expected ) ;
595+ done ( ) ;
596+ }
597+ catch ( e ) {
598+ done ( e ) ;
599+ }
600+ } ) ;
469601 } ) ;
470602
471603 it ( 'supports debug mode' , ( ) => {
0 commit comments