Skip to content

Commit 86ae3ec

Browse files
committed
feat(providers): ValidationProvider
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 5f1a1b3 commit 86ae3ec

File tree

9 files changed

+96
-12
lines changed

9 files changed

+96
-12
lines changed

src/app.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ConfigModule } from '@nestjs/config'
99
import DatabaseModule from './database/database.module'
1010
import MiddlewareModule from './middleware/middleware.module'
1111
import { Config } from './models'
12+
import { RxJSProvider, ValidationProvider } from './providers'
1213
import { DocsModule, HealthModule } from './subdomains'
1314

1415
/**
@@ -18,6 +19,7 @@ import { DocsModule, HealthModule } from './subdomains'
1819
*/
1920
@Global()
2021
@Module({
22+
exports: [RxJSProvider],
2123
imports: [
2224
ConfigModule.forRoot({
2325
cache:
@@ -34,7 +36,8 @@ import { DocsModule, HealthModule } from './subdomains'
3436
DocsModule,
3537
HealthModule,
3638
MiddlewareModule
37-
]
39+
],
40+
providers: [ValidationProvider, RxJSProvider]
3841
})
3942
class AppModule {}
4043

src/providers/__tests__/helmet-options.provider.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import { isObjectPlain } from '@flex-development/tutils'
88
import TestSubject from '../helmet-options.provider'
99

1010
describe('unit:providers/HelmetOptionsProvider', () => {
11-
it('should provide HELMET_OPTIONS', () => {
12-
expect(TestSubject).to.have.property('provide').deep.equal(HELMET_OPTIONS)
11+
describe('.provide', () => {
12+
it('should provide HELMET_OPTIONS', () => {
13+
expect(TestSubject).to.have.property('provide').deep.equal(HELMET_OPTIONS)
14+
})
1315
})
1416

15-
it('should use HelmetOptions object as value', () => {
16-
expect(TestSubject).to.have.property('useValue').satisfy(isObjectPlain)
17+
describe('.useValue', () => {
18+
it('should use HelmetOptions object', () => {
19+
expect(TestSubject).to.have.property('useValue').satisfy(isObjectPlain)
20+
})
1721
})
1822
})

src/providers/__tests__/rxjs.provider.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import * as rxjs from 'rxjs'
88
import TestSubject from '../rxjs.provider'
99

1010
describe('unit:providers/RxJSProvider', () => {
11-
it('should provide RXJS', () => {
12-
expect(TestSubject).to.have.property('provide').deep.equal(RXJS)
11+
describe('.provide', () => {
12+
it('should provide RXJS', () => {
13+
expect(TestSubject).to.have.property('provide').deep.equal(RXJS)
14+
})
1315
})
1416

15-
it('should use value rxjs', () => {
16-
expect(TestSubject).to.have.property('useValue').deep.equal(rxjs)
17+
describe('.useValue', () => {
18+
it('should use rxjs', () => {
19+
expect(TestSubject).to.have.property('useValue').deep.equal(rxjs)
20+
})
1721
})
1822
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @file Type Tests - ValidationProvider
3+
* @module sneusers/providers/tests/unit-d/ValidationProvider
4+
*/
5+
6+
import type { ValidationPipe, ValueProvider } from '@nestjs/common'
7+
import type TestSubject from '../validation.provider'
8+
9+
describe('unit-d:providers/ValidationProvider', () => {
10+
it('should equal type of ValueProvider<ValidationPipe>', () => {
11+
expectTypeOf<typeof TestSubject>().toEqualTypeOf<
12+
ValueProvider<ValidationPipe>
13+
>()
14+
})
15+
})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @file Unit Tests - ValidationProvider
3+
* @module sneusers/providers/tests/unit/ValidationProvider
4+
*/
5+
6+
import { ValidationPipe } from '@nestjs/common'
7+
import { APP_PIPE } from '@nestjs/core'
8+
import TestSubject from '../validation.provider'
9+
10+
describe('unit:providers/ValidationProvider', () => {
11+
describe('.provide', () => {
12+
it('should provide APP_PIPE', () => {
13+
expect(TestSubject).to.have.property('provide').deep.equal(APP_PIPE)
14+
})
15+
})
16+
17+
describe('.useValue', () => {
18+
it('should use ValidationPipe instance', () => {
19+
expect(TestSubject)
20+
.to.have.property('useValue')
21+
.be.instanceof(ValidationPipe)
22+
})
23+
})
24+
})

src/providers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66

77
export { default as HelmetOptionsProvider } from './helmet-options.provider'
88
export { default as RxJSProvider } from './rxjs.provider'
9+
export { default as ValidationProvider } from './validation.provider'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @file Providers - ValidationProvider
3+
* @module sneusers/providers/ValidationProvider
4+
*/
5+
6+
import type { ValueProvider } from '@nestjs/common'
7+
import { HttpStatus, ValidationPipe } from '@nestjs/common'
8+
import { APP_PIPE } from '@nestjs/core'
9+
10+
/**
11+
* Validation provider.
12+
*
13+
* @see https://docs.nestjs.com/techniques/validation
14+
*
15+
* @const {ValueProvider<ValidationPipe>} ValidationProvider
16+
*/
17+
const ValidationProvider: ValueProvider<ValidationPipe> = {
18+
provide: APP_PIPE,
19+
useValue: new ValidationPipe({
20+
enableDebugMessages: true,
21+
errorHttpStatusCode: HttpStatus.BAD_REQUEST,
22+
forbidUnknownValues: true,
23+
skipNullProperties: false,
24+
skipUndefinedProperties: false,
25+
stopAtFirstError: false,
26+
transform: true,
27+
transformOptions: { exposeUnsetFields: false },
28+
validateCustomDecorators: true,
29+
validationError: { target: false },
30+
whitelist: true
31+
})
32+
}
33+
34+
export default ValidationProvider

src/subdomains/docs/docs.module.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import type { IConfig } from '#src/interfaces'
7-
import { RxJSProvider } from '#src/providers'
87
import { HttpModule, type HttpModuleOptions } from '@nestjs/axios'
98
import { Module } from '@nestjs/common'
109
import { ConfigService } from '@nestjs/config'
@@ -27,8 +26,7 @@ import { DocsController } from './controllers'
2726
transitional: { clarifyTimeoutError: true, silentJSONParsing: false }
2827
})
2928
})
30-
],
31-
providers: [RxJSProvider]
29+
]
3230
})
3331
class DocsModule extends SwaggerModule {}
3432

tsconfig.typecheck.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"target": "es2022"
44
},
5+
"exclude": ["**/coverage", "**/dist", "**/node_modules", "./scratch.ts"],
56
"extends": "./tsconfig.json",
67
"include": [
78
"**/**.cts",

0 commit comments

Comments
 (0)