Skip to content

Commit 9689247

Browse files
committed
[src/{cli,core/types,service/emit/orchestrator}.ts] Prepare for new test generation for both Services and Admin UI
1 parent c21467a commit 9689247

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/cli.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ async function runGeneration(options: any) {
4646
enumStyle: options.enumStyle,
4747
generateServices: options.generateServices,
4848
admin: options.admin,
49+
// Commander sets `testsForService` to `false` if the `--no-` flag is used.
50+
// If the flag is absent, the property is `undefined`.
51+
generateServiceTests: options.testsForService,
52+
generateAdminTests: options.testsForAdmin,
4953
};
5054

5155
Object.keys(cliOptions).forEach(key => (cliOptions as any)[key] === undefined && delete (cliOptions as any)[key]);
@@ -59,6 +63,8 @@ async function runGeneration(options: any) {
5963
enumStyle: 'enum',
6064
generateServices: true,
6165
admin: false,
66+
generateServiceTests: true, // Default to true
67+
generateAdminTests: true, // Default to true
6268
...baseConfig.options,
6369
...cliOptions,
6470
},
@@ -108,6 +114,8 @@ program
108114
.addOption(new Option('--enumStyle <style>', 'Style for enums').choices(['enum', 'union']))
109115
.option('--admin', 'Generate an Angular Material admin UI')
110116
.addOption(new Option('--no-generate-services', 'Disable generation of Angular services'))
117+
.option('--no-tests-for-service', 'Disable generation of tests for Angular services')
118+
.option('--no-tests-for-admin', 'Disable generation of tests for the Angular admin UI')
111119
.action(runGeneration);
112120

113121
program

src/core/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,17 @@ export interface SwaggerSpec {
154154
/** Options that customize the output of the generated code. */
155155
export interface GeneratorConfigOptions {
156156
/** The TypeScript type to use for properties with `format: "date"` or `"date-time"`. */
157-
dateType: "string" | "Date";
157+
dateType: 'string' | 'Date';
158158
/** How to generate types for schemas with an `enum` list. */
159-
enumStyle: "enum" | "union";
159+
enumStyle: 'enum' | 'union';
160160
/** If true, generates Angular services for API operations. */
161161
generateServices?: boolean;
162162
/** If true, generates a complete admin UI module. */
163163
admin?: boolean;
164+
/** If true, generates tests for the Angular services. Defaults to true. */
165+
generateServiceTests?: boolean;
166+
/** If true, generates tests for the admin UI. Defaults to true. */
167+
generateAdminTests?: boolean;
164168
/** A record of static headers to be added to every generated service request. */
165169
customHeaders?: Record<string, string>;
166170
/** A callback to provide a custom method name for an operation. */

src/service/emit/orchestrator.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,18 @@ export async function emitClientLibrary(outputRoot: string, parser: SwaggerParse
6969
new ProviderGenerator(parser, project, tokenNames).generate(outputRoot);
7070

7171
console.log('✅ Utilities and providers generated.');
72+
// Stub for Service Test Generation
73+
if (config.options.generateServiceTests ?? true) {
74+
console.log('📝 Test generation for services is stubbed.');
75+
// Future implementation: new ServiceTestGenerator(parser, project, config).generate(outputRoot);
76+
}
7277

7378
if (config.options.admin) {
7479
await new AdminGenerator(parser, project, config).generate(outputRoot);
80+
if (config.options.generateAdminTests ?? true) {
81+
console.log('📝 Test generation for admin UI is stubbed.');
82+
// Future implementation: new AdminTestGenerator(parser, project, config).generate(outputRoot);
83+
}
7584
}
7685
}
7786

0 commit comments

Comments
 (0)