Skip to content

Commit

Permalink
test: more nuts, flag validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 17, 2022
1 parent 629fb8d commit b15029d
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/commands/generate/metadata/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ export default class FieldGenerate extends SfCommand<FieldGenerateResult> {
char: 'l',
summary: messages.getMessage('flags.label.summary'),
required: true,
parse: (label) => labelValidation(label),
parse: async (label) => labelValidation(label),
}),
// this a dir and not an API name to support 1 object being in multiple package directories
object: Flags.directory({
char: 'o',
exists: true,
summary: messages.getMessage('flags.object.summary'),
description: messages.getMessage('flags.object.description'),
parse: (input) => isObjectsFolder(input),
parse: async (input) => isObjectsFolder(input),
}),
};

Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/metadata/platformevent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class ObjectGenerate extends SfCommand<PlatformEventGenerateResul
char: 'l',
summary: messages.getMessage('flags.label.summary'),
required: true,
parse: (label) => labelValidation(label),
parse: async (label) => labelValidation(label),
}),
};

Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/metadata/sobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class ObjectGenerate extends SfCommand<CustomObjectGenerateResult
char: 'l',
summary: messages.getMessage('flags.label.summary'),
required: true,
parse: (label) => labelValidation(label),
parse: async (label) => labelValidation(label),
}),
'use-default-features': Flags.boolean({
char: 'f',
Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/metadata/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class GenerateTab extends SfCommand<GenerateTabResult> {
char: 'd',
required: true,
exists: true,
parse: (input) => isTabsFolder(input),
parse: async (input) => isTabsFolder(input),
}),
icon: Flags.integer({
char: 'i',
Expand Down
24 changes: 22 additions & 2 deletions test/nuts/field.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { env } from '@salesforce/kit';
// import { expect } from 'chai';

describe('generate tab NUTs', () => {
describe('generate field NUTs', () => {
let session: TestSession;

before(async () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});
session = await TestSession.create({
project: {
name: 'field-nut',
},
});
});

after(async () => {
Expand All @@ -26,4 +30,20 @@ describe('generate tab NUTs', () => {
const command = 'generate metadata field --help';
execCmd(command, { ensureExitCode: 0, cli: 'sf' }).shellOutput.stdout;
});

describe('flag validation failures', () => {
it('short label', () => {
const command = 'generate metadata field --label yo';
execCmd(command, { ensureExitCode: 1, cli: 'sf' });
});
it('bad object dir', () => {
const command = `generate metadata field --label longEnough --object ${path.join(
'force-app',
'main',
'default',
'tabs'
)}`;
execCmd(command, { ensureExitCode: 1, cli: 'sf' });
});
});
});
2 changes: 1 addition & 1 deletion test/nuts/fs.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../../src/shared/fs';
import { SaveableCustomObject } from '../../src/shared/types';

describe('generate tab NUTs', () => {
describe('local fs NUTs', () => {
let session: TestSession;
let pkgDirs: string[];

Expand Down
17 changes: 14 additions & 3 deletions test/nuts/platformevent.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { env } from '@salesforce/kit';
// import { expect } from 'chai';

describe('generate tab NUTs', () => {
describe('generate platformevent NUTs', () => {
let session: TestSession;

before(async () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});
session = await TestSession.create({
project: {
name: 'platformevent-nut',
},
});
});

after(async () => {
Expand All @@ -24,6 +28,13 @@ describe('generate tab NUTs', () => {

it('help should not throw', () => {
const command = 'generate metadata platformevent --help';
execCmd(command, { ensureExitCode: 0, cli: 'sf' }).shellOutput.stdout;
execCmd(command, { ensureExitCode: 0, cli: 'sf' });
});

describe('flag validation failures', () => {
it('short label', () => {
const command = 'generate metadata platformevent --label yo';
execCmd(command, { ensureExitCode: 1, cli: 'sf' });
});
});
});
11 changes: 9 additions & 2 deletions test/nuts/sobject.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { env } from '@salesforce/kit';
// import { expect } from 'chai';

describe('generate tab NUTs', () => {
describe('generate sobject NUTs', () => {
let session: TestSession;

before(async () => {
Expand All @@ -24,6 +24,13 @@ describe('generate tab NUTs', () => {

it('help should not throw', () => {
const command = 'generate metadata sobject --help';
execCmd(command, { ensureExitCode: 0, cli: 'sf' }).shellOutput.stdout;
execCmd(command, { ensureExitCode: 0, cli: 'sf' });
});

describe('flag validation failures', () => {
it('short label', () => {
const command = 'generate metadata sobject --label yo';
execCmd(command, { ensureExitCode: 1, cli: 'sf' });
});
});
});
19 changes: 17 additions & 2 deletions test/nuts/tab.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ describe('generate tab NUTs', () => {

before(async () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});
session = await TestSession.create({
project: {
name: 'tab-nut',
},
});
});

after(async () => {
Expand All @@ -24,6 +28,17 @@ describe('generate tab NUTs', () => {

it('help should not throw', () => {
const command = 'generate metadata tab --help';
execCmd(command, { ensureExitCode: 0, cli: 'sf' }).shellOutput.stdout;
execCmd(command, { ensureExitCode: 0, cli: 'sf' });
});
describe('flag validation failures', () => {
it('invalid folder', () => {
const command = `generate metadata tab --object foo --icon 1 --directory ${path.join(
'force-app',
'main',
'default',
'objects'
)}`;
execCmd(command, { ensureExitCode: 1, cli: 'sf' });
});
});
});

0 comments on commit b15029d

Please sign in to comment.