Skip to content

Commit ff4dd06

Browse files
major-winterdhmlau
authored andcommitted
fix: #10494 - lb4 controller fails with controllerType as BASIC
- 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 <[email protected]>
1 parent 70c7ee3 commit ff4dd06

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/cli/generators/controller/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ module.exports = class ControllerGenerator extends ArtifactGenerator {
8888

8989
if (this.options.controllerType) {
9090
Object.assign(this.artifactInfo, {
91-
controllerType: this.options.controllerType,
91+
controllerType:
92+
ControllerGenerator[this.options.controllerType.toUpperCase()],
9293
});
9394
return;
9495
}

packages/cli/test/integration/generators/controller.integration.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ const {expectFileToMatchSnapshot} = require('../../snapshots');
2424
const sandbox = new TestSandbox(path.resolve(__dirname, '../.sandbox'));
2525

2626
// CLI Inputs
27+
const defaultCLIInput = {
28+
name: 'productReview',
29+
};
2730
const basicCLIInput = {
2831
name: 'productReview',
32+
controllerType: 'ControllerGenerator.BASIC',
2933
};
3034
const restCLIInput = {
3135
name: 'productReview',
@@ -54,7 +58,7 @@ describe('lb4 controller', () => {
5458
.inDir(sandbox.path, () =>
5559
testUtils.givenLBProject(sandbox.path, {excludePackageJSON: true}),
5660
)
57-
.withPrompts(basicCLIInput),
61+
.withPrompts(defaultCLIInput),
5862
).to.be.rejectedWith(/No package.json found in/);
5963
});
6064

@@ -65,12 +69,21 @@ describe('lb4 controller', () => {
6569
.inDir(sandbox.path, () =>
6670
testUtils.givenLBProject(sandbox.path, {excludeLoopbackCore: true}),
6771
)
68-
.withPrompts(basicCLIInput),
72+
.withPrompts(defaultCLIInput),
6973
).to.be.rejectedWith(/No `@loopback\/core` package found/);
7074
});
7175

7276
describe('basic controller', () => {
7377
it('scaffolds correct file with input', async () => {
78+
await testUtils
79+
.executeGenerator(generator)
80+
.inDir(sandbox.path, () => testUtils.givenLBProject(sandbox.path))
81+
.withPrompts(defaultCLIInput);
82+
83+
checkBasicContents();
84+
});
85+
86+
it('scaffolds correct file with controllerType BASIC specified explicitly', async () => {
7487
await testUtils
7588
.executeGenerator(generator)
7689
.inDir(sandbox.path, () => testUtils.givenLBProject(sandbox.path))

0 commit comments

Comments
 (0)