Skip to content

Commit

Permalink
Merge with spo page add + missing test in spo file get
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodecleyre committed Oct 27, 2023
1 parent b159b8f commit e67ab1c
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 158 deletions.
78 changes: 78 additions & 0 deletions src/m365/spo/commands/file/file-get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,82 @@ describe(commands.FILE_GET, () => {
}));
});

it('retrieves and prints all details of file as ListItem object with url', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if ((opts.url as string).indexOf('?$expand=ListItemAllFields') > -1) {
return {
"ListItemAllFields": {
"FileSystemObjectType": 0,
"Id": 4,
"ServerRedirectedEmbedUri": "https://contoso.sharepoint.com/sites/project-x/_layouts/15/WopiFrame.aspx?sourcedoc={b2307a39-e878-458b-bc90-03bc578531d6}&action=interactivepreview",
"ServerRedirectedEmbedUrl": "https://contoso.sharepoint.com/sites/project-x/_layouts/15/WopiFrame.aspx?sourcedoc={b2307a39-e878-458b-bc90-03bc578531d6}&action=interactivepreview",
"ContentTypeId": "0x0101008E462E3ACE8DB844B3BEBF9473311889",
"ComplianceAssetId": null,
"Title": null,
"ID": 4,
"Created": "2018-02-05T09:42:36",
"AuthorId": 1,
"Modified": "2018-02-05T09:44:03",
"EditorId": 1,
"OData__CopySource": null,
"CheckoutUserId": null,
"OData__UIVersionString": "3.0",
"GUID": "2054f49e-0f76-46d4-ac55-50e1c057941c"
},
"CheckInComment": "",
"CheckOutType": 2,
"ContentTag": "{F09C4EFE-B8C0-4E89-A166-03418661B89B},9,12",
"CustomizedPageStatus": 0,
"ETag": "\"{F09C4EFE-B8C0-4E89-A166-03418661B89B},9\"",
"Exists": true,
"IrmEnabled": false,
"Length": "331673",
"Level": 1,
"LinkingUri": "https://contoso.sharepoint.com/sites/project-x/Documents/Test1.docx?d=wf09c4efeb8c04e89a16603418661b89b",
"LinkingUrl": "https://contoso.sharepoint.com/sites/project-x/Documents/Test1.docx?d=wf09c4efeb8c04e89a16603418661b89b",
"MajorVersion": 3,
"MinorVersion": 0,
"Name": "Opendag maart 2018.docx",
"ServerRelativeUrl": "/sites/project-x/Documents/Test1.docx",
"TimeCreated": "2018-02-05T08:42:36Z",
"TimeLastModified": "2018-02-05T08:44:03Z",
"Title": "",
"UIVersion": 1536,
"UIVersionLabel": "3.0",
"UniqueId": "b2307a39-e878-458b-bc90-03bc578531d6"
};
}

throw 'Invalid request';
});

await command.action(logger, {
options: {
debug: true,
url: '/sites/project-x/Documents/Test1.docx',
webUrl: 'https://contoso.sharepoint.com/sites/project-x',
asListItem: true
}
});
assert(loggerLogSpy.calledOnceWithExactly({
"FileSystemObjectType": 0,
"Id": 4,
"ServerRedirectedEmbedUri": "https://contoso.sharepoint.com/sites/project-x/_layouts/15/WopiFrame.aspx?sourcedoc={b2307a39-e878-458b-bc90-03bc578531d6}&action=interactivepreview",
"ServerRedirectedEmbedUrl": "https://contoso.sharepoint.com/sites/project-x/_layouts/15/WopiFrame.aspx?sourcedoc={b2307a39-e878-458b-bc90-03bc578531d6}&action=interactivepreview",
"ContentTypeId": "0x0101008E462E3ACE8DB844B3BEBF9473311889",
"ComplianceAssetId": null,
"Title": null,
"Created": "2018-02-05T09:42:36",
"AuthorId": 1,
"Modified": "2018-02-05T09:44:03",
"EditorId": 1,
"OData__CopySource": null,
"CheckoutUserId": null,
"OData__UIVersionString": "3.0",
"GUID": "2054f49e-0f76-46d4-ac55-50e1c057941c"
}));
});

it('retrieves and prints all details of file as ListItem object with permissions', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if ((opts.url as string).indexOf('?$expand=ListItemAllFields') > -1) {
Expand Down Expand Up @@ -423,6 +499,8 @@ describe(commands.FILE_GET, () => {
assert.strictEqual(getStub.lastCall.args[0].url, `https://contoso.sharepoint.com/sites/project-x/_api/web/GetFileByServerRelativePath(DecodedUrl=@f)?@f='%2Fsites%2Fproject-x%2FDocuments%2FTest1.docx'`);
});



it('uses correct API url when tenant root URL option is passed', async () => {
const getStub: any = sinon.stub(request, 'get').callsFake(async (opts) => {
if ((opts.url as string).indexOf('/_api/web/GetFileByServerRelativePath(') > -1) {
Expand Down
Loading

0 comments on commit e67ab1c

Please sign in to comment.