diff --git a/packages/cli/generators/controller/index.js b/packages/cli/generators/controller/index.js index 459257c1d731..b6bff3d4b128 100644 --- a/packages/cli/generators/controller/index.js +++ b/packages/cli/generators/controller/index.js @@ -88,7 +88,8 @@ module.exports = class ControllerGenerator extends ArtifactGenerator { if (this.options.controllerType) { Object.assign(this.artifactInfo, { - controllerType: this.options.controllerType, + controllerType: + ControllerGenerator[this.options.controllerType.toUpperCase()], }); return; } diff --git a/packages/cli/test/integration/generators/controller.integration.js b/packages/cli/test/integration/generators/controller.integration.js index 08bfbd923594..760b25c0fb41 100644 --- a/packages/cli/test/integration/generators/controller.integration.js +++ b/packages/cli/test/integration/generators/controller.integration.js @@ -24,8 +24,12 @@ const {expectFileToMatchSnapshot} = require('../../snapshots'); const sandbox = new TestSandbox(path.resolve(__dirname, '../.sandbox')); // CLI Inputs +const defaultCLIInput = { + name: 'productReview', +}; const basicCLIInput = { name: 'productReview', + controllerType: 'ControllerGenerator.BASIC', }; const restCLIInput = { name: 'productReview', @@ -54,7 +58,7 @@ describe('lb4 controller', () => { .inDir(sandbox.path, () => testUtils.givenLBProject(sandbox.path, {excludePackageJSON: true}), ) - .withPrompts(basicCLIInput), + .withPrompts(defaultCLIInput), ).to.be.rejectedWith(/No package.json found in/); }); @@ -65,12 +69,21 @@ describe('lb4 controller', () => { .inDir(sandbox.path, () => testUtils.givenLBProject(sandbox.path, {excludeLoopbackCore: true}), ) - .withPrompts(basicCLIInput), + .withPrompts(defaultCLIInput), ).to.be.rejectedWith(/No `@loopback\/core` package found/); }); describe('basic controller', () => { it('scaffolds correct file with input', async () => { + await testUtils + .executeGenerator(generator) + .inDir(sandbox.path, () => testUtils.givenLBProject(sandbox.path)) + .withPrompts(defaultCLIInput); + + checkBasicContents(); + }); + + it('scaffolds correct file with controllerType BASIC specified explicitly', async () => { await testUtils .executeGenerator(generator) .inDir(sandbox.path, () => testUtils.givenLBProject(sandbox.path))