Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extends 'spo list get' command with support for retrieving any default list in a given site #6447

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"Levert, Sebastien <[email protected]>",
"Lingstuyl, Martin <[email protected]>",
"Macháček, Martin <[email protected]>",
"Maestrini Tobias <tobias@bee365.ch>",
"Maestrini, Tobias <tobias[email protected]>",
"Maillot, Michaël <[email protected]>",
"Mastykarz, Waldek <[email protected]>",
"McDonnell, Kevin <[email protected]>",
Expand Down
22 changes: 21 additions & 1 deletion src/m365/spo/commands/list/list-get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1281,4 +1281,24 @@ describe(commands.LIST_GET, () => {
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', id: '0CD891EF-AFCE-4E55-B836-FCE03286CCCF' } }, commandInfo);
assert(actual);
});
});

it('retrieves the default list in the specified site by providing a webUrl', async () => {
const defaultSiteList = { ...listResponse, BaseTemplate: 101, ParentWebUrl: "/", ListItemEntityTypeFullName: "SP.Data.Shared_x0020_DocumentsItem" };

sinon.stub(request, 'get').resolves({
tmaestrini marked this conversation as resolved.
Show resolved Hide resolved
...defaultSiteList
});

await command.action(logger, {
options: {
webUrl: 'https://contoso.sharepoint.com'
}
});

assert(loggerLogSpy.calledWithMatch({
tmaestrini marked this conversation as resolved.
Show resolved Hide resolved
BaseTemplate: 101,
ParentWebUrl: "/",
ListItemEntityTypeFullName: "SP.Data.Shared_x0020_DocumentsItem"
}));
});
});
10 changes: 4 additions & 6 deletions src/m365/spo/commands/list/list-get.ts
tmaestrini marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SpoListGetCommand extends SpoCommand {
}

public get description(): string {
return 'Gets information about the specific list';
return 'Gets information about the specific list or returns information about the default list in a site';
tmaestrini marked this conversation as resolved.
Show resolved Hide resolved
}

constructor() {
Expand All @@ -44,7 +44,6 @@ class SpoListGetCommand extends SpoCommand {
this.#initTelemetry();
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -101,17 +100,16 @@ class SpoListGetCommand extends SpoCommand {
);
}

#initOptionSets(): void {
this.optionSets.push({ options: ['id', 'title', 'url'] });
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (this.verbose) {
await logger.logToStderr(`Retrieving information for list in site at ${args.options.webUrl}...`);
}

let requestUrl: string = `${args.options.webUrl}/_api/web/`;

if (!args.options.id && !args.options.title && !args.options.url) {
tmaestrini marked this conversation as resolved.
Show resolved Hide resolved
requestUrl += `DefaultDocumentLibrary`;
}
if (args.options.id) {
requestUrl += `lists(guid'${formatting.encodeQueryParameter(args.options.id)}')`;
}
Expand Down