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
2 changes: 2 additions & 0 deletions src/m365/flow/commands/flow-disable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import request from '../../../request.js';
import { telemetry } from '../../../telemetry.js';
import { pid } from '../../../utils/pid.js';
import { session } from '../../../utils/session.js';
import { accessToken } from '../../../utils/accessToken.js';
import { sinonUtil } from '../../../utils/sinonUtil.js';
import commands from '../commands.js';
import command from './flow-disable.js';
Expand All @@ -20,6 +21,7 @@ describe(commands.DISABLE, () => {
sinon.stub(telemetry, 'trackEvent').resolves();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
sinon.stub(accessToken, 'assertAccessTokenType').returns();
auth.connection.active = true;
});

Expand Down
47 changes: 13 additions & 34 deletions src/m365/flow/commands/flow-disable.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { z } from 'zod';
import { Logger } from '../../../cli/Logger.js';
import GlobalOptions from '../../../GlobalOptions.js';
import { globalOptionsZod } from '../../../Command.js';
import request, { CliRequestOptions } from '../../../request.js';
import { formatting } from '../../../utils/formatting.js';
import PowerAutomateCommand from '../../base/PowerAutomateCommand.js';
import commands from '../commands.js';

export const options = z.strictObject({
...globalOptionsZod.shape,
name: z.string().alias('n'),
environmentName: z.string().alias('e'),
asAdmin: z.boolean().optional()
});

declare type Options = z.infer<typeof options>;

interface CommandArgs {
options: Options;
}

interface Options extends GlobalOptions {
name: string;
environmentName: string;
asAdmin: boolean;
}

class FlowDisableCommand extends PowerAutomateCommand {
public get name(): string {
return commands.DISABLE;
Expand All @@ -24,33 +28,8 @@ class FlowDisableCommand extends PowerAutomateCommand {
return 'Disables specified Microsoft Flow';
}

constructor() {
super();

this.#initTelemetry();
this.#initOptions();
}

#initTelemetry(): void {
this.telemetry.push((args: CommandArgs) => {
Object.assign(this.telemetryProperties, {
asAdmin: !!args.options.asAdmin
});
});
}

#initOptions(): void {
this.options.unshift(
{
option: '-n, --name <name>'
},
{
option: '-e, --environmentName <environmentName>'
},
{
option: '--asAdmin'
}
);
public get schema(): z.ZodType {
return options;
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
Expand Down
2 changes: 2 additions & 0 deletions src/m365/flow/commands/flow-enable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import request from '../../../request.js';
import { telemetry } from '../../../telemetry.js';
import { pid } from '../../../utils/pid.js';
import { session } from '../../../utils/session.js';
import { accessToken } from '../../../utils/accessToken.js';
import { sinonUtil } from '../../../utils/sinonUtil.js';
import commands from '../commands.js';
import command from './flow-enable.js';
Expand All @@ -20,6 +21,7 @@ describe(commands.ENABLE, () => {
sinon.stub(telemetry, 'trackEvent').resolves();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
sinon.stub(accessToken, 'assertAccessTokenType').returns();
auth.connection.active = true;
});

Expand Down
47 changes: 13 additions & 34 deletions src/m365/flow/commands/flow-enable.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { z } from 'zod';
import { Logger } from '../../../cli/Logger.js';
import GlobalOptions from '../../../GlobalOptions.js';
import { globalOptionsZod } from '../../../Command.js';
import request, { CliRequestOptions } from '../../../request.js';
import { formatting } from '../../../utils/formatting.js';
import PowerAutomateCommand from '../../base/PowerAutomateCommand.js';
import commands from '../commands.js';

export const options = z.strictObject({
...globalOptionsZod.shape,
name: z.string().alias('n'),
environmentName: z.string().alias('e'),
asAdmin: z.boolean().optional()
});

declare type Options = z.infer<typeof options>;

interface CommandArgs {
options: Options;
}

interface Options extends GlobalOptions {
name: string;
environmentName: string;
asAdmin: boolean;
}

class FlowEnableCommand extends PowerAutomateCommand {
public get name(): string {
return commands.ENABLE;
Expand All @@ -24,33 +28,8 @@ class FlowEnableCommand extends PowerAutomateCommand {
return 'Enables specified Microsoft Flow';
}

constructor() {
super();

this.#initTelemetry();
this.#initOptions();
}

#initTelemetry(): void {
this.telemetry.push((args: CommandArgs) => {
Object.assign(this.telemetryProperties, {
asAdmin: !!args.options.asAdmin
});
});
}

#initOptions(): void {
this.options.unshift(
{
option: '-n, --name <name>'
},
{
option: '-e, --environmentName <environmentName>'
},
{
option: '--asAdmin'
}
);
public get schema(): z.ZodType {
return options;
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
Expand Down
40 changes: 21 additions & 19 deletions src/m365/flow/commands/flow-export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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 './flow-export.js';
import command, { options } from './flow-export.js';
import { formatting } from '../../../utils/formatting.js';
import { accessToken } from '../../../utils/accessToken.js';

Expand All @@ -21,6 +21,7 @@ describe(commands.EXPORT, () => {
let logger: Logger;
let loggerLogSpy: sinon.SinonSpy;
let commandInfo: CommandInfo;
let commandOptionsSchema: typeof options;
let loggerLogToStderrSpy: sinon.SinonSpy;

const actualFilename = `20180916t000000zba9d7134cc81499e9884bf70642afac7_20180916042428.zip`;
Expand Down Expand Up @@ -120,6 +121,7 @@ describe(commands.EXPORT, () => {
sinon.stub(session, 'getId').returns('');
auth.connection.active = true;
commandInfo = cli.getCommandInfo(command);
commandOptionsSchema = commandInfo.command.getSchemaToParse() as typeof options;
sinon.stub(accessToken, 'assertAccessTokenType').returns();
});

Expand Down Expand Up @@ -292,49 +294,49 @@ describe(commands.EXPORT, () => {
});

it('fails validation if the id is not a GUID', async () => {
const actual = await command.validate({ options: { environmentName: foundEnvironmentId, name: 'abc' } }, commandInfo);
assert.notStrictEqual(actual, true);
const actual = commandOptionsSchema.safeParse({ environmentName: foundEnvironmentId, name: 'abc' });
assert.strictEqual(actual.success, false);
});

it('fails validation if format is specified as neither JSON nor ZIP', async () => {
const actual = await command.validate({ options: { environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'text' } }, commandInfo);
assert.notStrictEqual(actual, true);
const actual = commandOptionsSchema.safeParse({ environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'text' });
assert.strictEqual(actual.success, false);
});

it('fails validation if format is specified as JSON and packageCreatedBy parameter is specified', async () => {
const actual = await command.validate({ options: { environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'json', packageCreatedBy: 'abc' } }, commandInfo);
assert.notStrictEqual(actual, true);
const actual = commandOptionsSchema.safeParse({ environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'json', packageCreatedBy: 'abc' });
assert.strictEqual(actual.success, false);
});

it('fails validation if format is specified as JSON and packageDescription parameter is specified', async () => {
const actual = await command.validate({ options: { environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'json', packageDescription: 'abc' } }, commandInfo);
assert.notStrictEqual(actual, true);
const actual = commandOptionsSchema.safeParse({ environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'json', packageDescription: 'abc' });
assert.strictEqual(actual.success, false);
});

it('fails validation if format is specified as JSON and packageDisplayName parameter is specified', async () => {
const actual = await command.validate({ options: { environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'json', packageDisplayName: 'abc' } }, commandInfo);
assert.notStrictEqual(actual, true);
const actual = commandOptionsSchema.safeParse({ environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'json', packageDisplayName: 'abc' });
assert.strictEqual(actual.success, false);
});

it('fails validation if format is specified as JSON and packageSourceEnvironment parameter is specified', async () => {
const actual = await command.validate({ options: { environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'json', packageSourceEnvironment: 'abc' } }, commandInfo);
assert.notStrictEqual(actual, true);
const actual = commandOptionsSchema.safeParse({ environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'json', packageSourceEnvironment: 'abc' });
assert.strictEqual(actual.success, false);
});

it('fails validation if specified path doesn\'t exist', async () => {
sinon.stub(fs, 'existsSync').callsFake(() => false);
const actual = await command.validate({ options: { environmentName: foundEnvironmentId, name: `${foundFlowName}`, path: '/path/not/found.zip' } }, commandInfo);
const actual = commandOptionsSchema.safeParse({ environmentName: foundEnvironmentId, name: `${foundFlowName}`, path: '/path/not/found.zip' });
sinonUtil.restore(fs.existsSync);
assert.notStrictEqual(actual, true);
assert.strictEqual(actual.success, false);
});

it('passes validation when the id and environment specified', async () => {
const actual = await command.validate({ options: { environmentName: foundEnvironmentId, name: `${foundFlowName}` } }, commandInfo);
assert.strictEqual(actual, true);
const actual = commandOptionsSchema.safeParse({ environmentName: foundEnvironmentId, name: `${foundFlowName}` });
assert.strictEqual(actual.success, true);
});

it('passes validation when the id and environment specified and format set to JSON', async () => {
const actual = await command.validate({ options: { environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'json' } }, commandInfo);
assert.strictEqual(actual, true);
const actual = commandOptionsSchema.safeParse({ environmentName: foundEnvironmentId, name: `${foundFlowName}`, format: 'json' });
assert.strictEqual(actual.success, true);
});
});
Loading
Loading