Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ 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();
sinon.stub(telemetry, 'trackEvent').resolves();
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(() => {
Expand Down Expand Up @@ -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`) {
Expand All @@ -85,7 +101,7 @@ describe(commands.RESOURCENAMESPACE_LIST, () => {
});

await command.action(logger, {
options: { verbose: true }
options: commandOptionsSchema.parse({ verbose: true })
});

assert(
Expand All @@ -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')
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'];
}
Expand Down