Skip to content

Commit c2252c2

Browse files
committed
fix(OpenApiNestFactory): nullcheck and unit tests for client generator options
1 parent 52a6878 commit c2252c2

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/openapi-nest.factory.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { NestFactory } from '@nestjs/core';
2+
import { OpenApiNestFactory } from './openapi-nest.factory';
3+
import { OpenApiToolsModule } from './openapi-tools.module';
4+
import { OpenApiService } from './openapi.service';
5+
6+
describe('', () => {
7+
it('should configure OpenApiToolsModule and create an instance of it', async () => {
8+
// arrange
9+
const app = {
10+
get: jest.fn(),
11+
};
12+
const documentBuilder = {
13+
build: jest.fn().mockReturnValue({ info: { title: 'My API' } }),
14+
};
15+
const swaggerOptions = {};
16+
17+
const openApiToolsModule = {
18+
get: jest.fn().mockReturnValue({
19+
configure: jest.fn(),
20+
}),
21+
};
22+
23+
const createApplicationContextSpy = jest
24+
.spyOn(NestFactory, 'createApplicationContext')
25+
.mockResolvedValue(openApiToolsModule as any);
26+
27+
// act
28+
await OpenApiNestFactory.configure(
29+
app as any,
30+
documentBuilder as any,
31+
{
32+
clientGeneratorOptions: {
33+
type: 'typescript-axios',
34+
outputFolderPath: '',
35+
openApiFilePath: '',
36+
enabled: true,
37+
},
38+
},
39+
swaggerOptions,
40+
);
41+
42+
// assert
43+
expect(createApplicationContextSpy).toHaveBeenCalledWith(
44+
OpenApiToolsModule,
45+
);
46+
expect(openApiToolsModule.get).toHaveBeenCalledWith(OpenApiService);
47+
});
48+
});

src/openapi-nest.factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class OpenApiNestFactory {
5959
}
6060

6161
toolsOptions.clientGeneratorOptions = new AxiosClientGeneratorOptions({
62-
...toolsOptions.clientGeneratorOptions,
62+
...(toolsOptions?.clientGeneratorOptions || {}),
6363
outputFolderPath,
6464
});
6565
}

0 commit comments

Comments
 (0)