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

Enhances command spo list remove #6378

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion docs/docs/cmd/spo/list/list-remove.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Removes the specified list
```sh
m365 spo list remove [options]
```

## Options

```md definition-list
Expand All @@ -22,6 +22,9 @@ m365 spo list remove [options]
`-t, --title [title]`
: Title of the list to remove. Specify either `id` or `title` but not both.

`--recycle`
: Recycle the list
milanholemans marked this conversation as resolved.
Show resolved Hide resolved

`-f, --force`
: Don't prompt for confirming removing the list.
```
Expand All @@ -42,6 +45,12 @@ Remove the list with a specific title located in a specific site.
m365 spo list remove --webUrl https://contoso.sharepoint.com/sites/project-x --title 'List 1'
```

Remove the list with a specific ID located in a specific site and send it to recycle bin
milanholemans marked this conversation as resolved.
Show resolved Hide resolved

```sh
m365 spo list remove --webUrl https://contoso.sharepoint.com/sites/project-x --id 0cd891ef-afce-4e55-b836-fce03286cccf --recycle
```

## Response

The command won't return a response on success.
49 changes: 49 additions & 0 deletions src/m365/spo/commands/list/list-remove.spec.ts
milanholemans marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,55 @@ describe(commands.LIST_REMOVE, () => {
assert(correctRequestIssued);
});

it('recycles the list when prompt confirmed', async () => {
sinon.stub(request, 'post').callsFake((opts) => {
requests.push(opts);

if ((opts.url as string).indexOf(`/recycle()`) > -1) {
if (opts.headers &&
opts.headers.accept &&
(opts.headers.accept as string).indexOf('application/json') === 0) {
return Promise.resolve();
}
}

return Promise.reject('Invalid request');
});

sinonUtil.restore(cli.promptForConfirmation);
sinon.stub(cli, 'promptForConfirmation').resolves(true);
await command.action(logger, { options: { id: 'b2307a39-e878-458b-bc90-03bc578531d6', webUrl: 'https://contoso.sharepoint.com', recycle: true } });
let correctRequestIssued = false;
requests.forEach(r => {
if (r.url.indexOf(`/recycle()`) > -1 &&
r.headers.accept &&
r.headers.accept.indexOf('application/json') === 0) {
correctRequestIssued = true;
}
});
milanholemans marked this conversation as resolved.
Show resolved Hide resolved

assert(correctRequestIssued);
});

it('uses correct API url when recycle option is passed', async () => {
milanholemans marked this conversation as resolved.
Show resolved Hide resolved
sinon.stub(request, 'post').callsFake((opts) => {
if ((opts.url as string).indexOf('/recycle()') > -1) {
return Promise.resolve('Correct Url');
}

return Promise.reject('Invalid request');
});

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

it('command correctly handles list get reject request', async () => {
const error = {
error: {
Expand Down
11 changes: 10 additions & 1 deletion src/m365/spo/commands/list/list-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Options extends GlobalOptions {
webUrl: string;
id?: string;
title?: string;
recycle?: boolean;
force?: boolean;
}

Expand All @@ -41,7 +42,8 @@ class SpoListRemoveCommand extends SpoCommand {
Object.assign(this.telemetryProperties, {
id: (!(!args.options.id)).toString(),
title: (!(!args.options.title)).toString(),
force: (!(!args.options.force)).toString()
force: (!(!args.options.force)).toString(),
recycle: (!(!args.options.recycle)).toString()
milanholemans marked this conversation as resolved.
Show resolved Hide resolved
});
});
}
Expand All @@ -57,6 +59,9 @@ class SpoListRemoveCommand extends SpoCommand {
{
option: '-t, --title [title]'
},
{
option: '--recycle'
milanholemans marked this conversation as resolved.
Show resolved Hide resolved
},
{
option: '-f, --force'
}
Expand Down Expand Up @@ -100,6 +105,10 @@ class SpoListRemoveCommand extends SpoCommand {
requestUrl = `${args.options.webUrl}/_api/web/lists/GetByTitle('${formatting.encodeQueryParameter(args.options.title as string)}')`;
}

if (args.options.recycle) {
requestUrl += `/recycle()`;
milanholemans marked this conversation as resolved.
Show resolved Hide resolved
}

const requestOptions: CliRequestOptions = {
url: requestUrl,
method: 'POST',
Expand Down