Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 18 additions & 2 deletions src/m365/commands/docs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import assert from 'assert';
import sinon from 'sinon';
import { z } from 'zod';
import { cli } from '../../cli/cli.js';
import { CommandInfo } from '../../cli/CommandInfo.js';
import { Logger } from '../../cli/Logger.js';
import { telemetry } from '../../telemetry.js';
import { app } from '../../utils/app.js';
Expand All @@ -16,11 +18,15 @@ describe(commands.DOCS, () => {
let logger: Logger;
let loggerLogSpy: sinon.SinonSpy;
let getSettingWithDefaultValueStub: sinon.SinonStub;
let commandInfo: CommandInfo;
let commandOptionsSchema: z.ZodTypeAny;

before(() => {
sinon.stub(telemetry, 'trackEvent').resolves();
sinon.stub(pid, 'getProcessName').callsFake(() => '');
sinon.stub(session, 'getId').callsFake(() => '');
commandInfo = cli.getCommandInfo(command);
commandOptionsSchema = commandInfo.command.getSchemaToParse()!;
});

beforeEach(() => {
Expand Down Expand Up @@ -59,8 +65,18 @@ describe(commands.DOCS, () => {
assert.notStrictEqual(command.description, null);
});

it('passes validation with no options', () => {
const actual = commandOptionsSchema.safeParse({});
assert.strictEqual(actual.success, true);
});

it('fails validation with unknown options', () => {
const actual = commandOptionsSchema.safeParse({ option: "value" });
assert.strictEqual(actual.success, false);
});

it('should log a message and return if autoOpenLinksInBrowser is false', async () => {
await command.action(logger, { options: {} });
await command.action(logger, { options: commandOptionsSchema.parse({}) });
assert(loggerLogSpy.calledWith(app.packageJson().homepage));
});

Expand All @@ -74,7 +90,7 @@ describe(commands.DOCS, () => {
}
throw 'Invalid url';
});
await command.action(logger, { options: {} });
await command.action(logger, { options: commandOptionsSchema.parse({}) });
assert(openStub.calledWith(app.packageJson().homepage));
});
});
8 changes: 8 additions & 0 deletions src/m365/commands/docs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { z } from 'zod';
import { cli } from '../../cli/cli.js';
import { Logger } from '../../cli/Logger.js';
import { globalOptionsZod } from '../../Command.js';
import { settingsNames } from '../../settingsNames.js';
import { app } from '../../utils/app.js';
import { browserUtil } from '../../utils/browserUtil.js';
import AnonymousCommand from '../base/AnonymousCommand.js';
import commands from './commands.js';

const options = globalOptionsZod.strict();

class DocsCommand extends AnonymousCommand {
public get name(): string {
return commands.DOCS;
Expand All @@ -15,6 +19,10 @@ class DocsCommand extends AnonymousCommand {
return 'Returns the CLI for Microsoft 365 docs webpage URL';
}

public get schema(): z.ZodTypeAny | undefined {
return options;
}

public async commandAction(logger: Logger): Promise<void> {
await logger.log(app.packageJson().homepage);

Expand Down