Skip to content

Commit f21b904

Browse files
author
Ågren
committed
Changed the unit tests
1 parent 6b2913b commit f21b904

2 files changed

Lines changed: 148 additions & 11 deletions

File tree

src/o365/spo/commands/file/file-copy.spec.ts

Lines changed: 147 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -636,19 +636,156 @@ describe(commands.FILE_COPY, () => {
636636
}
637637
});
638638

639-
it('should combine url with baseUrl that last char is /', () => {
640-
const actual = (command as any).urlCombine('https://contoso.com/', 'sites/abc');
641-
assert.equal(actual, 'https://contoso.com/sites/abc');
639+
it('should complete successfully where baseUrl has a trailing /', (done) => {
640+
let actual: string = '';
641+
const expected: string = JSON.stringify({
642+
exportObjectUris: [
643+
'https://contoso.sharepoint.com/sites/team-a/library/file1.pdf'
644+
],
645+
destinationUri: 'https://contoso.sharepoint.com/sites/team-b/library2',
646+
options: {
647+
'AllowSchemaMismatch': false,
648+
'IgnoreVersionHistory': true
649+
}
650+
});
651+
652+
sinon.stub(request, 'post').callsFake((opts) => {
653+
actual = JSON.stringify(opts.body);
654+
if (
655+
opts.body.exportObjectUris[0] === 'https://contoso.sharepoint.com/sites/team-a/library/file1.pdf' &&
656+
opts.body.destinationUri === 'https://contoso.sharepoint.com/sites/team-b/library2' &&
657+
opts.url === 'https://contoso.sharepoint.com/sites/team-a/_api/site/CreateCopyJobs'
658+
) {
659+
return Promise.resolve();
660+
661+
}
662+
return Promise.reject('Invalid request');
663+
664+
});
665+
stubAllGetRequests();
666+
667+
auth.site = new Site();
668+
auth.site.connected = true;
669+
auth.site.url = 'https://contoso.sharepoint.com';
670+
cmdInstance.action = command.action();
671+
672+
cmdInstance.action({
673+
options: {
674+
webUrl: 'https://contoso.sharepoint.com/sites/team-a/',
675+
sourceUrl: 'library/file1.pdf',
676+
targetUrl: 'sites/team-b/library2'
677+
}
678+
}, () => {
679+
try {
680+
assert.equal(actual, expected);
681+
done();
682+
}
683+
catch (e) {
684+
done(e);
685+
}
686+
});
642687
});
643688

644-
it('should combine url with relativeUrl that last char is /', () => {
645-
const actual = (command as any).urlCombine('https://contoso.com', 'sites/abc/');
646-
assert.equal(actual, 'https://contoso.com/sites/abc');
689+
it('should complete successfully where sourceUrl and targetUrl has a trailing /', (done) => {
690+
let actual: string = '';
691+
const expected: string = JSON.stringify({
692+
exportObjectUris: [
693+
'https://contoso.sharepoint.com/sites/team-a/library/file1.pdf'
694+
],
695+
destinationUri: 'https://contoso.sharepoint.com/sites/team-b/library2',
696+
options: {
697+
'AllowSchemaMismatch': false,
698+
'IgnoreVersionHistory': true
699+
}
700+
});
701+
702+
sinon.stub(request, 'post').callsFake((opts) => {
703+
actual = JSON.stringify(opts.body);
704+
if (
705+
opts.body.exportObjectUris[0] === 'https://contoso.sharepoint.com/sites/team-a/library/file1.pdf' &&
706+
opts.body.destinationUri === 'https://contoso.sharepoint.com/sites/team-b/library2' &&
707+
opts.url === 'https://contoso.sharepoint.com/sites/team-a/_api/site/CreateCopyJobs'
708+
) {
709+
return Promise.resolve();
710+
711+
}
712+
return Promise.reject('Invalid request');
713+
714+
});
715+
716+
stubAllGetRequests();
717+
718+
auth.site = new Site();
719+
auth.site.connected = true;
720+
auth.site.url = 'https://contoso.sharepoint.com';
721+
cmdInstance.action = command.action();
722+
723+
cmdInstance.action({
724+
options: {
725+
webUrl: 'https://contoso.sharepoint.com/sites/team-a/',
726+
sourceUrl: 'library/file1.pdf/',
727+
targetUrl: 'sites/team-b/library2/'
728+
}
729+
}, () => {
730+
try {
731+
assert.equal(actual, expected);
732+
done();
733+
}
734+
catch (e) {
735+
done(e);
736+
}
737+
});
647738
});
648739

649-
it('should combine url with relativeUrl that first char is /', () => {
650-
const actual = (command as any).urlCombine('https://contoso.com/', '/sites/abc/');
651-
assert.equal(actual, 'https://contoso.com/sites/abc');
740+
it('should complete successfully where sourceUrl and targetUrl has a beginning /', (done) => {
741+
let actual: string = '';
742+
const expected: string = JSON.stringify({
743+
exportObjectUris: [
744+
'https://contoso.sharepoint.com/sites/team-a/library/file1.pdf'
745+
],
746+
destinationUri: 'https://contoso.sharepoint.com/sites/team-b/library2',
747+
options: {
748+
'AllowSchemaMismatch': false,
749+
'IgnoreVersionHistory': true
750+
}
751+
});
752+
753+
sinon.stub(request, 'post').callsFake((opts) => {
754+
actual = JSON.stringify(opts.body);
755+
if (
756+
opts.body.exportObjectUris[0] === 'https://contoso.sharepoint.com/sites/team-a/library/file1.pdf' &&
757+
opts.body.destinationUri === 'https://contoso.sharepoint.com/sites/team-b/library2' &&
758+
opts.url === 'https://contoso.sharepoint.com/sites/team-a/_api/site/CreateCopyJobs'
759+
) {
760+
return Promise.resolve();
761+
762+
}
763+
return Promise.reject('Invalid request');
764+
765+
});
766+
767+
stubAllGetRequests();
768+
769+
auth.site = new Site();
770+
auth.site.connected = true;
771+
auth.site.url = 'https://contoso.sharepoint.com';
772+
cmdInstance.action = command.action();
773+
774+
cmdInstance.action({
775+
options: {
776+
webUrl: 'https://contoso.sharepoint.com/sites/team-a/',
777+
sourceUrl: '/library/file1.pdf/',
778+
targetUrl: '/sites/team-b/library2/'
779+
}
780+
}, () => {
781+
try {
782+
assert.equal(actual, expected);
783+
done();
784+
}
785+
catch (e) {
786+
done(e);
787+
}
788+
});
652789
});
653790

654791
it('supports debug mode', () => {
@@ -754,4 +891,4 @@ describe(commands.FILE_COPY, () => {
754891
}
755892
});
756893
});
757-
});
894+
});

src/o365/spo/commands/file/file-copy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class SpoFileCopyCommand extends SpoCommand {
118118
// all preconditions met, now create copy job
119119
const sourceAbsoluteUrl = this.urlCombine(webUrl, args.options.sourceUrl);
120120
const allowSchemaMismatch: boolean = args.options.allowSchemaMismatch || false;
121-
const requestUrl: string = `${webUrl}/_api/site/CreateCopyJobs`;
121+
const requestUrl: string = this.urlCombine(webUrl, '/_api/site/CreateCopyJobs');
122122
const requestOptions: any = {
123123
url: requestUrl,
124124
headers: Utils.getRequestHeaders({

0 commit comments

Comments
 (0)