diff --git a/src/commands/generate/metadata/field.ts b/src/commands/generate/metadata/field.ts index e234a698..8c58febf 100644 --- a/src/commands/generate/metadata/field.ts +++ b/src/commands/generate/metadata/field.ts @@ -109,7 +109,7 @@ export default class FieldGenerate extends SfCommand { 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({ @@ -117,7 +117,7 @@ export default class FieldGenerate extends SfCommand { exists: true, summary: messages.getMessage('flags.object.summary'), description: messages.getMessage('flags.object.description'), - parse: (input) => isObjectsFolder(input), + parse: async (input) => isObjectsFolder(input), }), }; diff --git a/src/commands/generate/metadata/platformevent.ts b/src/commands/generate/metadata/platformevent.ts index 58538ad8..4f6fdf5e 100644 --- a/src/commands/generate/metadata/platformevent.ts +++ b/src/commands/generate/metadata/platformevent.ts @@ -40,7 +40,7 @@ export default class ObjectGenerate extends SfCommand labelValidation(label), + parse: async (label) => labelValidation(label), }), }; diff --git a/src/commands/generate/metadata/sobject.ts b/src/commands/generate/metadata/sobject.ts index 47ae4090..c54055e8 100644 --- a/src/commands/generate/metadata/sobject.ts +++ b/src/commands/generate/metadata/sobject.ts @@ -63,7 +63,7 @@ export default class ObjectGenerate extends SfCommand labelValidation(label), + parse: async (label) => labelValidation(label), }), 'use-default-features': Flags.boolean({ char: 'f', diff --git a/src/commands/generate/metadata/tab.ts b/src/commands/generate/metadata/tab.ts index 7addea85..959b0cc7 100644 --- a/src/commands/generate/metadata/tab.ts +++ b/src/commands/generate/metadata/tab.ts @@ -50,7 +50,7 @@ export default class GenerateTab extends SfCommand { char: 'd', required: true, exists: true, - parse: (input) => isTabsFolder(input), + parse: async (input) => isTabsFolder(input), }), icon: Flags.integer({ char: 'i', diff --git a/test/nuts/field.nut.ts b/test/nuts/field.nut.ts index 575395a3..7cff451a 100644 --- a/test/nuts/field.nut.ts +++ b/test/nuts/field.nut.ts @@ -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 () => { @@ -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' }); + }); + }); }); diff --git a/test/nuts/fs.nut.ts b/test/nuts/fs.nut.ts index 8820f622..c5acd932 100644 --- a/test/nuts/fs.nut.ts +++ b/test/nuts/fs.nut.ts @@ -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[]; diff --git a/test/nuts/platformevent.nut.ts b/test/nuts/platformevent.nut.ts index 51d93390..c004a265 100644 --- a/test/nuts/platformevent.nut.ts +++ b/test/nuts/platformevent.nut.ts @@ -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 () => { @@ -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' }); + }); }); }); diff --git a/test/nuts/sobject.nut.ts b/test/nuts/sobject.nut.ts index 7a30faab..ec6306e5 100644 --- a/test/nuts/sobject.nut.ts +++ b/test/nuts/sobject.nut.ts @@ -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 () => { @@ -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' }); + }); }); }); diff --git a/test/nuts/tab.nut.ts b/test/nuts/tab.nut.ts index c3b57daa..4f5ca44f 100644 --- a/test/nuts/tab.nut.ts +++ b/test/nuts/tab.nut.ts @@ -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 () => { @@ -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' }); + }); }); });