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

Removes trailing slashes from 'spo get' #5929

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/m365/spo/commands/spo-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ describe(commands.SET, () => {
assert.strictEqual(auth.connection.spoUrl, 'https://contoso.sharepoint.com');
});

it('trims trailing slashes from the URL', async () => {
await command.action(logger, { options: { url: 'https://contoso.sharepoint.com/' } });
assert.strictEqual(auth.connection.spoUrl, 'https://contoso.sharepoint.com');
});

it('throws error when trying to set SPO URL when not logged in to M365', async () => {
auth.connection.active = false;

Expand All @@ -88,17 +93,6 @@ describe(commands.SET, () => {
await assert.rejects(command.action(logger, { options: { url: 'https://contoso.sharepoint.com' } } as any), new CommandError('An error has occurred while setting the password'));
});

it('supports specifying url', () => {
const options = command.options;
let containsOption = false;
options.forEach(o => {
if (o.option.indexOf('--url') > -1) {
containsOption = true;
}
});
assert(containsOption);
});

it('fails validation if url is not a valid SharePoint URL', async () => {
const actual = await command.validate({ options: { url: 'abc' } }, commandInfo);
assert.notStrictEqual(actual, true);
Expand Down
8 changes: 7 additions & 1 deletion src/m365/spo/commands/spo-set.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import auth from '../../../Auth.js';
import { Logger } from '../../../cli/Logger.js';
import GlobalOptions from '../../../GlobalOptions.js';
import { urlUtil } from '../../../utils/urlUtil.js';
import { validation } from '../../../utils/validation.js';
import SpoCommand from '../../base/SpoCommand.js';
import commands from '../commands.js';
Expand All @@ -27,6 +28,7 @@ class SpoSetCommand extends SpoCommand {

this.#initOptions();
this.#initValidators();
this.#initTypes();
}

#initOptions(): void {
Expand All @@ -43,8 +45,12 @@ class SpoSetCommand extends SpoCommand {
);
}

#initTypes(): void {
this.types.string.push('url');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
auth.connection.spoUrl = args.options.url;
auth.connection.spoUrl = urlUtil.removeTrailingSlashes(args.options.url);

try {
await auth.storeConnectionInfo();
Expand Down