diff --git a/src/m365/entra/commands/resourcenamespace/resourcenamespace-list.spec.ts b/src/m365/entra/commands/resourcenamespace/resourcenamespace-list.spec.ts index 3c6fcf78dcc..53d95cdc55d 100644 --- a/src/m365/entra/commands/resourcenamespace/resourcenamespace-list.spec.ts +++ b/src/m365/entra/commands/resourcenamespace/resourcenamespace-list.spec.ts @@ -9,13 +9,17 @@ import { pid } from '../../../../utils/pid.js'; import { session } from '../../../../utils/session.js'; import { sinonUtil } from '../../../../utils/sinonUtil.js'; import commands from '../../commands.js'; -import command from './resourcenamespace-list.js'; +import command, { options } from './resourcenamespace-list.js'; +import { cli } from '../../../../cli/cli.js'; +import { CommandInfo } from '../../../../cli/CommandInfo.js'; describe(commands.RESOURCENAMESPACE_LIST, () => { let log: string[]; let logger: Logger; let loggerLogSpy: sinon.SinonSpy; + let commandInfo: CommandInfo; + let commandOptionsSchema: typeof options; before(() => { sinon.stub(auth, 'restoreAuth').resolves(); @@ -23,6 +27,8 @@ describe(commands.RESOURCENAMESPACE_LIST, () => { sinon.stub(pid, 'getProcessName').returns(''); sinon.stub(session, 'getId').returns(''); auth.connection.active = true; + commandInfo = cli.getCommandInfo(command); + commandOptionsSchema = commandInfo.command.getSchemaToParse() as typeof options; }); beforeEach(() => { @@ -64,6 +70,16 @@ describe(commands.RESOURCENAMESPACE_LIST, () => { assert.deepStrictEqual(command.defaultProperties(), ['id', 'name']); }); + 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 get a list of resource namespaces`, async () => { sinon.stub(request, 'get').callsFake(async (opts) => { if (opts.url === `https://graph.microsoft.com/beta/roleManagement/directory/resourceNamespaces`) { @@ -85,7 +101,7 @@ describe(commands.RESOURCENAMESPACE_LIST, () => { }); await command.action(logger, { - options: { verbose: true } + options: commandOptionsSchema.parse({ verbose: true }) }); assert( @@ -111,7 +127,7 @@ describe(commands.RESOURCENAMESPACE_LIST, () => { }); await assert.rejects( - command.action(logger, { options: {} } as any), + command.action(logger, { options: commandOptionsSchema.parse({}) }), new CommandError('An error has occurred') ); }); diff --git a/src/m365/entra/commands/resourcenamespace/resourcenamespace-list.ts b/src/m365/entra/commands/resourcenamespace/resourcenamespace-list.ts index 3ec0c0d04eb..8b160531dfc 100644 --- a/src/m365/entra/commands/resourcenamespace/resourcenamespace-list.ts +++ b/src/m365/entra/commands/resourcenamespace/resourcenamespace-list.ts @@ -2,6 +2,10 @@ import { Logger } from '../../../../cli/Logger.js'; import { odata } from '../../../../utils/odata.js'; import GraphCommand from '../../../base/GraphCommand.js'; import commands from '../../commands.js'; +import { z } from 'zod'; +import { globalOptionsZod } from '../../../../Command.js'; + +export const options = z.strictObject({ ...globalOptionsZod.shape }); class EntraResourcenamespaceListCommand extends GraphCommand { public get name(): string { @@ -12,6 +16,10 @@ class EntraResourcenamespaceListCommand extends GraphCommand { return 'Get a list of the RBAC resource namespaces and their properties'; } + public get schema(): z.ZodType | undefined { + return options; + } + public defaultProperties(): string[] | undefined { return ['id', 'name']; }