Skip to content

Commit 8fd6d4e

Browse files
committed
Fixes spo file get unit tests, clarification on id in the descr
1 parent 4b0e372 commit 8fd6d4e

3 files changed

Lines changed: 21 additions & 23 deletions

File tree

docs/manual/docs/cmd/spo/file/file-get.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Option|Description
1515
`--help`|output usage information
1616
`-w, --webUrl <webUrl>`|The URL of the site where the file is located
1717
`-u, --url [url]`|The server-relative URL of the file to retrieve. Specify either `url` or `id` but not both
18-
`-i, --id [id]`|The ID of the file to retrieve. Specify either `url` or `id` but not both
18+
`-i, --id [id]`|The UniqueId (GUID) of the file to retrieve. Specify either `url` or `id` but not both
1919
`--asString`|Set to retrieve the contents of the specified file as string
2020
`--asListItem`|Set to retrieve the underlying list item
2121
`--asFile`|Set to save the file to the path specified in the path option
@@ -33,25 +33,25 @@ To get a file, you have to first connect to a SharePoint Online site using the [
3333

3434
## Examples
3535

36-
Get file properties for file with id _b2307a39-e878-458b-bc90-03bc578531d6_ located in site _https://contoso.sharepoint.com/sites/project-x_
36+
Get file properties for file with id (UniqueId) _b2307a39-e878-458b-bc90-03bc578531d6_ located in site _https://contoso.sharepoint.com/sites/project-x_
3737

3838
```sh
3939
spo file get --webUrl https://contoso.sharepoint.com/sites/project-x --id 'b2307a39-e878-458b-bc90-03bc578531d6'
4040
```
4141

42-
Get contents of the file with id _b2307a39-e878-458b-bc90-03bc578531d6_ located in site _https://contoso.sharepoint.com/sites/project-x_
42+
Get contents of the file with id (UniqueId) _b2307a39-e878-458b-bc90-03bc578531d6_ located in site _https://contoso.sharepoint.com/sites/project-x_
4343

4444
```sh
4545
spo file get --webUrl https://contoso.sharepoint.com/sites/project-x --id 'b2307a39-e878-458b-bc90-03bc578531d6' --asString
4646
```
4747

48-
Get list item properties for file with id _b2307a39-e878-458b-bc90-03bc578531d6_ located in site _https://contoso.sharepoint.com/sites/project-x_
48+
Get list item properties for file with id (UniqueId) _b2307a39-e878-458b-bc90-03bc578531d6_ located in site _https://contoso.sharepoint.com/sites/project-x_
4949

5050
```sh
5151
spo file get --webUrl https://contoso.sharepoint.com/sites/project-x --id 'b2307a39-e878-458b-bc90-03bc578531d6' --asListItem
5252
```
5353

54-
Save file with id _b2307a39-e878-458b-bc90-03bc578531d6_ located in site _https://contoso.sharepoint.com/sites/project-x_ to local file _/Users/user/documents/SavedAsTest1.docx_
54+
Save file with id (UniqueId) _b2307a39-e878-458b-bc90-03bc578531d6_ located in site _https://contoso.sharepoint.com/sites/project-x_ to local file _/Users/user/documents/SavedAsTest1.docx_
5555

5656
```sh
5757
spo file get --webUrl https://contoso.sharepoint.com/sites/project-x --id 'b2307a39-e878-458b-bc90-03bc578531d6' --asFile --path /Users/user/documents/SavedAsTest1.docx

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ describe(commands.FILE_GET, () => {
361361
it('uses correct API url when id option is passed', (done) => {
362362
stubAuth();
363363

364-
sinon.stub(request, 'get').callsFake((opts) => {
364+
const getStub: any = sinon.stub(request, 'get').callsFake((opts) => {
365365
if (opts.url.indexOf('/_api/web/GetFileById(') > -1) {
366366
return Promise.resolve('Correct Url')
367367
}
@@ -385,7 +385,8 @@ describe(commands.FILE_GET, () => {
385385
}, () => {
386386

387387
try {
388-
assert(1 === 1);
388+
assert.equal(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/project-x/_api/web/GetFileById(\'0CD891EF-AFCE-4E55-B836-FCE03286CCCF\')');
389+
assert.equal(getStub.lastCall.args[0].headers.authorization, 'Bearer ABC');
389390
done();
390391
}
391392
catch (e) {
@@ -403,7 +404,7 @@ describe(commands.FILE_GET, () => {
403404
it('uses correct API url when url option is passed', (done) => {
404405
stubAuth();
405406

406-
sinon.stub(request, 'get').callsFake((opts) => {
407+
const getStub: any = sinon.stub(request, 'get').callsFake((opts) => {
407408
if (opts.url.indexOf('/_api/web/GetFileByServerRelativeUrl(') > -1) {
408409
return Promise.resolve('Correct Url')
409410
}
@@ -425,7 +426,8 @@ describe(commands.FILE_GET, () => {
425426
}, () => {
426427

427428
try {
428-
assert(1 === 1);
429+
assert.equal(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/project-x/_api/web/GetFileByServerRelativeUrl(\'%2Fsites%2Fproject-x%2FDocuments%2FTest1.docx\')');
430+
assert.equal(getStub.lastCall.args[0].headers.authorization, 'Bearer ABC');
429431
done();
430432
}
431433
catch (e) {
@@ -440,15 +442,11 @@ describe(commands.FILE_GET, () => {
440442
});
441443
});
442444

443-
it('uses correct API url when url and id are both not passed', (done) => {
445+
it('should handle promise rejection', (done) => {
444446
stubAuth();
445-
447+
const expectedError: any = JSON.stringify({"odata.error":{"code":"-2130575338, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"Error: File Not Found."}}});
446448
sinon.stub(request, 'get').callsFake((opts) => {
447-
if (opts.url === '') {
448-
return Promise.resolve('Correct Url')
449-
}
450-
451-
return Promise.reject('Invalid request');
449+
return Promise.reject(expectedError);
452450
});
453451

454452
auth.site = new Site();
@@ -461,10 +459,10 @@ describe(commands.FILE_GET, () => {
461459
debug: false,
462460
webUrl: 'https://contoso.sharepoint.com/sites/project-x',
463461
}
464-
}, () => {
462+
}, (err: any) => {
465463

466464
try {
467-
assert(1 === 1);
465+
assert.equal(JSON.stringify(err.message), JSON.stringify(expectedError));
468466
done();
469467
}
470468
catch (e) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class SpoFileGetCommand extends SpoCommand {
149149
},
150150
{
151151
option: '-i, --id [id]',
152-
description: 'The ID of the file to retrieve. Specify either url or id but not both'
152+
description: 'The UniqueId (GUID) of the file to retrieve. Specify either url or id but not both'
153153
},
154154
{
155155
option: '--asString',
@@ -236,20 +236,20 @@ class SpoFileGetCommand extends SpoCommand {
236236
237237
Examples:
238238
239-
Get file properties for file with id ${chalk.grey('b2307a39-e878-458b-bc90-03bc578531d6')}
239+
Get file properties for file with id (UniqueId) ${chalk.grey('b2307a39-e878-458b-bc90-03bc578531d6')}
240240
located in site ${chalk.grey('https://contoso.sharepoint.com/sites/project-x')}
241241
${chalk.grey(config.delimiter)} ${commands.FILE_GET} --webUrl https://contoso.sharepoint.com/sites/project-x --id 'b2307a39-e878-458b-bc90-03bc578531d6'
242242
243-
Get contents of the file with id ${chalk.grey('b2307a39-e878-458b-bc90-03bc578531d6')}
243+
Get contents of the file with id (UniqueId) ${chalk.grey('b2307a39-e878-458b-bc90-03bc578531d6')}
244244
located in site ${chalk.grey('https://contoso.sharepoint.com/sites/project-x')}
245245
${chalk.grey(config.delimiter)} ${commands.FILE_GET} --webUrl https://contoso.sharepoint.com/sites/project-x --id 'b2307a39-e878-458b-bc90-03bc578531d6' --asString
246246
247-
Get list item properties for file with id
247+
Get list item properties for file with id (UniqueId)
248248
${chalk.grey('b2307a39-e878-458b-bc90-03bc578531d6')} located in site
249249
${chalk.grey('https://contoso.sharepoint.com/sites/project-x')}
250250
${chalk.grey(config.delimiter)} ${commands.FILE_GET} --webUrl https://contoso.sharepoint.com/sites/project-x --id 'b2307a39-e878-458b-bc90-03bc578531d6' --asListItem
251251
252-
Save file with id ${chalk.grey('b2307a39-e878-458b-bc90-03bc578531d6')} located
252+
Save file with id (UniqueId) ${chalk.grey('b2307a39-e878-458b-bc90-03bc578531d6')} located
253253
in site ${chalk.grey('https://contoso.sharepoint.com/sites/project-x')} to local file
254254
${chalk.grey('/Users/user/documents/SavedAsTest1.docx')}
255255
${chalk.grey(config.delimiter)} ${commands.FILE_GET} --webUrl https://contoso.sharepoint.com/sites/project-x --id 'b2307a39-e878-458b-bc90-03bc578531d6' --asFile --path /Users/user/documents/SavedAsTest1.docx

0 commit comments

Comments
 (0)