Skip to content

Commit

Permalink
fix: loopbackio#10494 - lb4 controller fails with controllerType as B…
Browse files Browse the repository at this point in the history
…ASIC

- fix CLI execution with explicit --controllerType=BASIC option
- add a unit test that verifies the scaffold when explicity specifying the controller type as BASIC

Signed-off-by: TC <tuanchuhoang@gmail.com>
  • Loading branch information
major-winter authored and TC committed Aug 26, 2024
1 parent f285ad3 commit c50e1df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/cli/generators/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 15 additions & 2 deletions packages/cli/test/integration/generators/controller.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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/);
});

Expand All @@ -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))
Expand Down

0 comments on commit c50e1df

Please sign in to comment.