@dismissible/nestjs-api 0.0.2-canary.5daf195.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/config/.env.yaml +41 -0
  2. package/jest.config.ts +35 -0
  3. package/jest.e2e-config.ts +13 -0
  4. package/nest-cli.json +16 -0
  5. package/package.json +58 -0
  6. package/project.json +94 -0
  7. package/scripts/performance-test.config.json +29 -0
  8. package/scripts/performance-test.ts +845 -0
  9. package/src/app-test.factory.ts +39 -0
  10. package/src/app.module.ts +60 -0
  11. package/src/app.setup.ts +52 -0
  12. package/src/bootstrap.ts +29 -0
  13. package/src/config/app.config.spec.ts +117 -0
  14. package/src/config/app.config.ts +20 -0
  15. package/src/config/config.module.spec.ts +94 -0
  16. package/src/config/config.module.ts +50 -0
  17. package/src/config/default-app.config.spec.ts +74 -0
  18. package/src/config/default-app.config.ts +24 -0
  19. package/src/config/index.ts +2 -0
  20. package/src/cors/cors.config.spec.ts +162 -0
  21. package/src/cors/cors.config.ts +37 -0
  22. package/src/cors/index.ts +1 -0
  23. package/src/health/health.controller.spec.ts +24 -0
  24. package/src/health/health.controller.ts +16 -0
  25. package/src/health/health.module.ts +9 -0
  26. package/src/health/index.ts +2 -0
  27. package/src/helmet/helmet.config.spec.ts +197 -0
  28. package/src/helmet/helmet.config.ts +60 -0
  29. package/src/helmet/index.ts +1 -0
  30. package/src/index.ts +5 -0
  31. package/src/main.ts +3 -0
  32. package/src/server/index.ts +1 -0
  33. package/src/server/server.config.spec.ts +65 -0
  34. package/src/server/server.config.ts +8 -0
  35. package/src/swagger/index.ts +2 -0
  36. package/src/swagger/swagger.config.spec.ts +113 -0
  37. package/src/swagger/swagger.config.ts +12 -0
  38. package/src/swagger/swagger.factory.spec.ts +125 -0
  39. package/src/swagger/swagger.factory.ts +24 -0
  40. package/src/validation/index.ts +1 -0
  41. package/src/validation/validation.config.ts +47 -0
  42. package/test/config/.env.yaml +23 -0
  43. package/test/config-jwt-auth/.env.yaml +26 -0
  44. package/test/dismiss.e2e-spec.ts +61 -0
  45. package/test/full-cycle.e2e-spec.ts +55 -0
  46. package/test/get-or-create.e2e-spec.ts +51 -0
  47. package/test/jwt-auth.e2e-spec.ts +335 -0
  48. package/test/restore.e2e-spec.ts +61 -0
  49. package/tsconfig.app.json +13 -0
  50. package/tsconfig.e2e.json +12 -0
  51. package/tsconfig.json +13 -0
  52. package/tsconfig.spec.json +12 -0
@@ -0,0 +1,162 @@
1
+ import 'reflect-metadata';
2
+ import { plainToInstance } from 'class-transformer';
3
+ import { validate } from 'class-validator';
4
+ import { CorsConfig } from './cors.config';
5
+
6
+ describe('CorsConfig', () => {
7
+ describe('enabled', () => {
8
+ it('should transform string "true" to boolean true', () => {
9
+ const config = plainToInstance(CorsConfig, { enabled: 'true' });
10
+ expect(config.enabled).toBe(true);
11
+ });
12
+
13
+ it('should transform string "false" to boolean false', () => {
14
+ const config = plainToInstance(CorsConfig, { enabled: 'false' });
15
+ expect(config.enabled).toBe(false);
16
+ });
17
+
18
+ it('should keep boolean true as true', () => {
19
+ const config = plainToInstance(CorsConfig, { enabled: true });
20
+ expect(config.enabled).toBe(true);
21
+ });
22
+
23
+ it('should keep boolean false as false', () => {
24
+ const config = plainToInstance(CorsConfig, { enabled: false });
25
+ expect(config.enabled).toBe(false);
26
+ });
27
+ });
28
+
29
+ describe('origins', () => {
30
+ it('should transform comma-separated string to array', () => {
31
+ const config = plainToInstance(CorsConfig, {
32
+ enabled: true,
33
+ origins: 'http://localhost:3000,http://localhost:4000',
34
+ });
35
+ expect(config.origins).toEqual(['http://localhost:3000', 'http://localhost:4000']);
36
+ });
37
+
38
+ it('should trim whitespace from origins', () => {
39
+ const config = plainToInstance(CorsConfig, {
40
+ enabled: true,
41
+ origins: 'http://localhost:3000 , http://localhost:4000 ',
42
+ });
43
+ expect(config.origins).toEqual(['http://localhost:3000', 'http://localhost:4000']);
44
+ });
45
+
46
+ it('should handle single origin string', () => {
47
+ const config = plainToInstance(CorsConfig, {
48
+ enabled: true,
49
+ origins: 'http://localhost:3000',
50
+ });
51
+ expect(config.origins).toEqual(['http://localhost:3000']);
52
+ });
53
+
54
+ it('should keep array as array', () => {
55
+ const config = plainToInstance(CorsConfig, {
56
+ enabled: true,
57
+ origins: ['http://localhost:3000', 'http://localhost:4000'],
58
+ });
59
+ expect(config.origins).toEqual(['http://localhost:3000', 'http://localhost:4000']);
60
+ });
61
+ });
62
+
63
+ describe('methods', () => {
64
+ it('should transform comma-separated string to array', () => {
65
+ const config = plainToInstance(CorsConfig, {
66
+ enabled: true,
67
+ methods: 'GET,POST,DELETE',
68
+ });
69
+ expect(config.methods).toEqual(['GET', 'POST', 'DELETE']);
70
+ });
71
+
72
+ it('should trim whitespace from methods', () => {
73
+ const config = plainToInstance(CorsConfig, {
74
+ enabled: true,
75
+ methods: 'GET , POST , DELETE',
76
+ });
77
+ expect(config.methods).toEqual(['GET', 'POST', 'DELETE']);
78
+ });
79
+ });
80
+
81
+ describe('allowedHeaders', () => {
82
+ it('should transform comma-separated string to array', () => {
83
+ const config = plainToInstance(CorsConfig, {
84
+ enabled: true,
85
+ allowedHeaders: 'Content-Type,Authorization,x-request-id',
86
+ });
87
+ expect(config.allowedHeaders).toEqual(['Content-Type', 'Authorization', 'x-request-id']);
88
+ });
89
+
90
+ it('should trim whitespace from headers', () => {
91
+ const config = plainToInstance(CorsConfig, {
92
+ enabled: true,
93
+ allowedHeaders: 'Content-Type , Authorization , x-request-id',
94
+ });
95
+ expect(config.allowedHeaders).toEqual(['Content-Type', 'Authorization', 'x-request-id']);
96
+ });
97
+ });
98
+
99
+ describe('credentials', () => {
100
+ it('should transform string "true" to boolean true', () => {
101
+ const config = plainToInstance(CorsConfig, { enabled: true, credentials: 'true' });
102
+ expect(config.credentials).toBe(true);
103
+ });
104
+
105
+ it('should transform string "false" to boolean false', () => {
106
+ const config = plainToInstance(CorsConfig, { enabled: true, credentials: 'false' });
107
+ expect(config.credentials).toBe(false);
108
+ });
109
+
110
+ it('should keep boolean values unchanged', () => {
111
+ const configTrue = plainToInstance(CorsConfig, { enabled: true, credentials: true });
112
+ const configFalse = plainToInstance(CorsConfig, { enabled: true, credentials: false });
113
+ expect(configTrue.credentials).toBe(true);
114
+ expect(configFalse.credentials).toBe(false);
115
+ });
116
+ });
117
+
118
+ describe('maxAge', () => {
119
+ it('should transform string to number', () => {
120
+ const config = plainToInstance(CorsConfig, { enabled: true, maxAge: '86400' });
121
+ expect(config.maxAge).toBe(86400);
122
+ });
123
+
124
+ it('should keep number unchanged', () => {
125
+ const config = plainToInstance(CorsConfig, { enabled: true, maxAge: 3600 });
126
+ expect(config.maxAge).toBe(3600);
127
+ });
128
+ });
129
+
130
+ describe('validation', () => {
131
+ it('should pass validation with valid config', async () => {
132
+ const config = plainToInstance(CorsConfig, {
133
+ enabled: true,
134
+ origins: ['http://localhost:3000'],
135
+ methods: ['GET', 'POST'],
136
+ allowedHeaders: ['Content-Type'],
137
+ credentials: true,
138
+ maxAge: 86400,
139
+ });
140
+
141
+ const errors = await validate(config);
142
+ expect(errors).toHaveLength(0);
143
+ });
144
+
145
+ it('should pass validation with only required fields', async () => {
146
+ const config = plainToInstance(CorsConfig, {
147
+ enabled: true,
148
+ });
149
+
150
+ const errors = await validate(config);
151
+ expect(errors).toHaveLength(0);
152
+ });
153
+
154
+ it('should fail validation when enabled is missing', async () => {
155
+ const config = plainToInstance(CorsConfig, {});
156
+
157
+ const errors = await validate(config);
158
+ expect(errors.length).toBeGreaterThan(0);
159
+ expect(errors[0].property).toBe('enabled');
160
+ });
161
+ });
162
+ });
@@ -0,0 +1,37 @@
1
+ import { IsArray, IsBoolean, IsNumber, IsOptional, IsString } from 'class-validator';
2
+ import { Type } from 'class-transformer';
3
+ import { TransformBoolean, TransformCommaSeparated } from '@dismissible/nestjs-validation';
4
+
5
+ export class CorsConfig {
6
+ @IsBoolean()
7
+ @TransformBoolean()
8
+ public readonly enabled!: boolean;
9
+
10
+ @IsArray()
11
+ @IsString({ each: true })
12
+ @IsOptional()
13
+ @TransformCommaSeparated()
14
+ public readonly origins?: string[];
15
+
16
+ @IsArray()
17
+ @IsString({ each: true })
18
+ @IsOptional()
19
+ @TransformCommaSeparated()
20
+ public readonly methods?: string[];
21
+
22
+ @IsArray()
23
+ @IsString({ each: true })
24
+ @IsOptional()
25
+ @TransformCommaSeparated()
26
+ public readonly allowedHeaders?: string[];
27
+
28
+ @IsBoolean()
29
+ @IsOptional()
30
+ @TransformBoolean()
31
+ public readonly credentials?: boolean;
32
+
33
+ @IsNumber()
34
+ @IsOptional()
35
+ @Type(() => Number)
36
+ public readonly maxAge?: number;
37
+ }
@@ -0,0 +1 @@
1
+ export * from './cors.config';
@@ -0,0 +1,24 @@
1
+ import { HealthController } from './health.controller';
2
+
3
+ describe('HealthController', () => {
4
+ let controller: HealthController;
5
+
6
+ beforeEach(() => {
7
+ jest.useFakeTimers();
8
+ jest.setSystemTime(new Date('2024-01-20T15:30:00.000Z'));
9
+ controller = new HealthController();
10
+ });
11
+
12
+ afterEach(() => {
13
+ jest.useRealTimers();
14
+ });
15
+
16
+ describe('getHealth', () => {
17
+ it('should return the exact response from service', () => {
18
+ const result = controller.getHealth();
19
+
20
+ expect(result.status).toBe('ok');
21
+ expect(result.timestamp).toBe('2024-01-20T15:30:00.000Z');
22
+ });
23
+ });
24
+ });
@@ -0,0 +1,16 @@
1
+ import { Controller, Get, HttpCode, HttpStatus } from '@nestjs/common';
2
+
3
+ @Controller('health')
4
+ export class HealthController {
5
+ @Get()
6
+ @HttpCode(HttpStatus.OK)
7
+ getHealth(): {
8
+ status: string;
9
+ timestamp: string;
10
+ } {
11
+ return {
12
+ status: 'ok',
13
+ timestamp: new Date().toISOString(),
14
+ };
15
+ }
16
+ }
@@ -0,0 +1,9 @@
1
+ import { Module } from '@nestjs/common';
2
+ import { HealthController } from './health.controller';
3
+
4
+ @Module({
5
+ controllers: [HealthController],
6
+ providers: [],
7
+ exports: [],
8
+ })
9
+ export class HealthModule {}
@@ -0,0 +1,2 @@
1
+ export * from './health.module';
2
+ export * from './health.controller';
@@ -0,0 +1,197 @@
1
+ import 'reflect-metadata';
2
+ import { plainToInstance } from 'class-transformer';
3
+ import { validate } from 'class-validator';
4
+ import { HelmetConfig } from './helmet.config';
5
+
6
+ describe('HelmetConfig', () => {
7
+ describe('enabled', () => {
8
+ it('should transform string "true" to boolean true', () => {
9
+ const config = plainToInstance(HelmetConfig, { enabled: 'true' });
10
+ expect(config.enabled).toBe(true);
11
+ });
12
+
13
+ it('should transform string "false" to boolean false', () => {
14
+ const config = plainToInstance(HelmetConfig, { enabled: 'false' });
15
+ expect(config.enabled).toBe(false);
16
+ });
17
+
18
+ it('should keep boolean true as true', () => {
19
+ const config = plainToInstance(HelmetConfig, { enabled: true });
20
+ expect(config.enabled).toBe(true);
21
+ });
22
+
23
+ it('should keep boolean false as false', () => {
24
+ const config = plainToInstance(HelmetConfig, { enabled: false });
25
+ expect(config.enabled).toBe(false);
26
+ });
27
+ });
28
+
29
+ describe('contentSecurityPolicy', () => {
30
+ it('should transform string "true" to boolean true', () => {
31
+ const config = plainToInstance(HelmetConfig, {
32
+ enabled: true,
33
+ contentSecurityPolicy: 'true',
34
+ });
35
+ expect(config.contentSecurityPolicy).toBe(true);
36
+ });
37
+
38
+ it('should transform string "false" to boolean false', () => {
39
+ const config = plainToInstance(HelmetConfig, {
40
+ enabled: true,
41
+ contentSecurityPolicy: 'false',
42
+ });
43
+ expect(config.contentSecurityPolicy).toBe(false);
44
+ });
45
+
46
+ it('should keep boolean values unchanged', () => {
47
+ const configTrue = plainToInstance(HelmetConfig, {
48
+ enabled: true,
49
+ contentSecurityPolicy: true,
50
+ });
51
+ const configFalse = plainToInstance(HelmetConfig, {
52
+ enabled: true,
53
+ contentSecurityPolicy: false,
54
+ });
55
+ expect(configTrue.contentSecurityPolicy).toBe(true);
56
+ expect(configFalse.contentSecurityPolicy).toBe(false);
57
+ });
58
+ });
59
+
60
+ describe('crossOriginEmbedderPolicy', () => {
61
+ it('should transform string "true" to boolean true', () => {
62
+ const config = plainToInstance(HelmetConfig, {
63
+ enabled: true,
64
+ crossOriginEmbedderPolicy: 'true',
65
+ });
66
+ expect(config.crossOriginEmbedderPolicy).toBe(true);
67
+ });
68
+
69
+ it('should transform string "false" to boolean false', () => {
70
+ const config = plainToInstance(HelmetConfig, {
71
+ enabled: true,
72
+ crossOriginEmbedderPolicy: 'false',
73
+ });
74
+ expect(config.crossOriginEmbedderPolicy).toBe(false);
75
+ });
76
+
77
+ it('should keep boolean values unchanged', () => {
78
+ const configTrue = plainToInstance(HelmetConfig, {
79
+ enabled: true,
80
+ crossOriginEmbedderPolicy: true,
81
+ });
82
+ const configFalse = plainToInstance(HelmetConfig, {
83
+ enabled: true,
84
+ crossOriginEmbedderPolicy: false,
85
+ });
86
+ expect(configTrue.crossOriginEmbedderPolicy).toBe(true);
87
+ expect(configFalse.crossOriginEmbedderPolicy).toBe(false);
88
+ });
89
+ });
90
+
91
+ describe('hstsMaxAge', () => {
92
+ it('should transform string to number', () => {
93
+ const config = plainToInstance(HelmetConfig, { enabled: true, hstsMaxAge: '31536000' });
94
+ expect(config.hstsMaxAge).toBe(31536000);
95
+ });
96
+
97
+ it('should keep number unchanged', () => {
98
+ const config = plainToInstance(HelmetConfig, { enabled: true, hstsMaxAge: 86400 });
99
+ expect(config.hstsMaxAge).toBe(86400);
100
+ });
101
+ });
102
+
103
+ describe('hstsIncludeSubDomains', () => {
104
+ it('should transform string "true" to boolean true', () => {
105
+ const config = plainToInstance(HelmetConfig, {
106
+ enabled: true,
107
+ hstsIncludeSubDomains: 'true',
108
+ });
109
+ expect(config.hstsIncludeSubDomains).toBe(true);
110
+ });
111
+
112
+ it('should transform string "false" to boolean false', () => {
113
+ const config = plainToInstance(HelmetConfig, {
114
+ enabled: true,
115
+ hstsIncludeSubDomains: 'false',
116
+ });
117
+ expect(config.hstsIncludeSubDomains).toBe(false);
118
+ });
119
+
120
+ it('should keep boolean values unchanged', () => {
121
+ const configTrue = plainToInstance(HelmetConfig, {
122
+ enabled: true,
123
+ hstsIncludeSubDomains: true,
124
+ });
125
+ const configFalse = plainToInstance(HelmetConfig, {
126
+ enabled: true,
127
+ hstsIncludeSubDomains: false,
128
+ });
129
+ expect(configTrue.hstsIncludeSubDomains).toBe(true);
130
+ expect(configFalse.hstsIncludeSubDomains).toBe(false);
131
+ });
132
+ });
133
+
134
+ describe('hstsPreload', () => {
135
+ it('should transform string "true" to boolean true', () => {
136
+ const config = plainToInstance(HelmetConfig, {
137
+ enabled: true,
138
+ hstsPreload: 'true',
139
+ });
140
+ expect(config.hstsPreload).toBe(true);
141
+ });
142
+
143
+ it('should transform string "false" to boolean false', () => {
144
+ const config = plainToInstance(HelmetConfig, {
145
+ enabled: true,
146
+ hstsPreload: 'false',
147
+ });
148
+ expect(config.hstsPreload).toBe(false);
149
+ });
150
+
151
+ it('should keep boolean values unchanged', () => {
152
+ const configTrue = plainToInstance(HelmetConfig, {
153
+ enabled: true,
154
+ hstsPreload: true,
155
+ });
156
+ const configFalse = plainToInstance(HelmetConfig, {
157
+ enabled: true,
158
+ hstsPreload: false,
159
+ });
160
+ expect(configTrue.hstsPreload).toBe(true);
161
+ expect(configFalse.hstsPreload).toBe(false);
162
+ });
163
+ });
164
+
165
+ describe('validation', () => {
166
+ it('should pass validation with valid config', async () => {
167
+ const config = plainToInstance(HelmetConfig, {
168
+ enabled: true,
169
+ contentSecurityPolicy: true,
170
+ crossOriginEmbedderPolicy: true,
171
+ hstsMaxAge: 31536000,
172
+ hstsIncludeSubDomains: true,
173
+ hstsPreload: false,
174
+ });
175
+
176
+ const errors = await validate(config);
177
+ expect(errors).toHaveLength(0);
178
+ });
179
+
180
+ it('should pass validation with only required fields', async () => {
181
+ const config = plainToInstance(HelmetConfig, {
182
+ enabled: true,
183
+ });
184
+
185
+ const errors = await validate(config);
186
+ expect(errors).toHaveLength(0);
187
+ });
188
+
189
+ it('should fail validation when enabled is missing', async () => {
190
+ const config = plainToInstance(HelmetConfig, {});
191
+
192
+ const errors = await validate(config);
193
+ expect(errors.length).toBeGreaterThan(0);
194
+ expect(errors[0].property).toBe('enabled');
195
+ });
196
+ });
197
+ });
@@ -0,0 +1,60 @@
1
+ import { IsBoolean, IsNumber, IsOptional } from 'class-validator';
2
+ import { Type } from 'class-transformer';
3
+ import { TransformBoolean } from '@dismissible/nestjs-validation';
4
+
5
+ /**
6
+ * @see https://helmetjs.github.io/
7
+ */
8
+ export class HelmetConfig {
9
+ /**
10
+ * Whether to enable Helmet middleware
11
+ */
12
+ @IsBoolean()
13
+ @TransformBoolean()
14
+ public readonly enabled!: boolean;
15
+
16
+ /**
17
+ * Whether to enable Content-Security-Policy header.
18
+ * @default true
19
+ */
20
+ @IsBoolean()
21
+ @IsOptional()
22
+ @TransformBoolean()
23
+ public readonly contentSecurityPolicy?: boolean;
24
+
25
+ /**
26
+ * Whether to enable Cross-Origin-Embedder-Policy header.
27
+ * @default true
28
+ */
29
+ @IsBoolean()
30
+ @IsOptional()
31
+ @TransformBoolean()
32
+ public readonly crossOriginEmbedderPolicy?: boolean;
33
+
34
+ /**
35
+ * HSTS max-age in seconds.
36
+ * @default 31536000 (1 year)
37
+ */
38
+ @IsNumber()
39
+ @IsOptional()
40
+ @Type(() => Number)
41
+ public readonly hstsMaxAge?: number;
42
+
43
+ /**
44
+ * Whether to include subdomains in HSTS header.
45
+ * @default true
46
+ */
47
+ @IsBoolean()
48
+ @IsOptional()
49
+ @TransformBoolean()
50
+ public readonly hstsIncludeSubDomains?: boolean;
51
+
52
+ /**
53
+ * Whether to add HSTS preload directive.
54
+ * @default false
55
+ */
56
+ @IsBoolean()
57
+ @IsOptional()
58
+ @TransformBoolean()
59
+ public readonly hstsPreload?: boolean;
60
+ }
@@ -0,0 +1 @@
1
+ export * from './helmet.config';
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './config';
2
+ export * from './server';
3
+ export * from './bootstrap';
4
+ export * from './app.module';
5
+ export * from './app.setup';
package/src/main.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { bootstrap } from './bootstrap';
2
+
3
+ bootstrap();
@@ -0,0 +1 @@
1
+ export * from './server.config';
@@ -0,0 +1,65 @@
1
+ import 'reflect-metadata';
2
+ import { plainToInstance } from 'class-transformer';
3
+ import { validate } from 'class-validator';
4
+ import { ServerConfig } from './server.config';
5
+
6
+ describe('ServerConfig', () => {
7
+ describe('port', () => {
8
+ it('should transform string to number', () => {
9
+ const config = plainToInstance(ServerConfig, { port: '3001' });
10
+ expect(config.port).toBe(3001);
11
+ });
12
+
13
+ it('should keep number unchanged', () => {
14
+ const config = plainToInstance(ServerConfig, { port: 3001 });
15
+ expect(config.port).toBe(3001);
16
+ });
17
+
18
+ it('should handle different port numbers', () => {
19
+ const config = plainToInstance(ServerConfig, { port: '8080' });
20
+ expect(config.port).toBe(8080);
21
+ });
22
+ });
23
+
24
+ describe('validation', () => {
25
+ it('should pass validation with valid port number', async () => {
26
+ const config = plainToInstance(ServerConfig, { port: 3001 });
27
+ const errors = await validate(config);
28
+ expect(errors).toHaveLength(0);
29
+ });
30
+
31
+ it('should pass validation with string port that transforms to number', async () => {
32
+ const config = plainToInstance(ServerConfig, { port: '3001' });
33
+ const errors = await validate(config);
34
+ expect(errors).toHaveLength(0);
35
+ });
36
+
37
+ it('should fail validation when port is missing', async () => {
38
+ const config = plainToInstance(ServerConfig, {});
39
+ const errors = await validate(config);
40
+ expect(errors.length).toBeGreaterThan(0);
41
+ expect(errors[0].property).toBe('port');
42
+ });
43
+
44
+ it('should fail validation when port is not a number', async () => {
45
+ const config = plainToInstance(ServerConfig, { port: 'not-a-number' });
46
+ const errors = await validate(config);
47
+ expect(errors.length).toBeGreaterThan(0);
48
+ expect(errors[0].property).toBe('port');
49
+ });
50
+
51
+ it('should fail validation when port is null', async () => {
52
+ const config = plainToInstance(ServerConfig, { port: null });
53
+ const errors = await validate(config);
54
+ expect(errors.length).toBeGreaterThan(0);
55
+ expect(errors[0].property).toBe('port');
56
+ });
57
+
58
+ it('should fail validation when port is undefined', async () => {
59
+ const config = plainToInstance(ServerConfig, { port: undefined });
60
+ const errors = await validate(config);
61
+ expect(errors.length).toBeGreaterThan(0);
62
+ expect(errors[0].property).toBe('port');
63
+ });
64
+ });
65
+ });
@@ -0,0 +1,8 @@
1
+ import { IsNumber } from 'class-validator';
2
+ import { Type } from 'class-transformer';
3
+
4
+ export class ServerConfig {
5
+ @IsNumber()
6
+ @Type(() => Number)
7
+ public readonly port!: number;
8
+ }
@@ -0,0 +1,2 @@
1
+ export * from './swagger.factory';
2
+ export * from './swagger.config';