Skip to content

Commit

Permalink
Removes trailing slashes from 'spo get'
Browse files Browse the repository at this point in the history
  • Loading branch information
milanholemans committed May 7, 2024
1 parent 5f64790 commit 6221f44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
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

0 comments on commit 6221f44

Please sign in to comment.