dev/snippet (#130)
This commit is contained in:
22
test/helper/register-app.helper.ts
Normal file
22
test/helper/register-app.helper.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { ValidationPipe } from '@nestjs/common'
|
||||
import { NestFastifyApplication } from '@nestjs/platform-fastify'
|
||||
import { TestingModule } from '@nestjs/testing'
|
||||
import { fastifyApp } from '~/common/adapters/fastify.adapter'
|
||||
|
||||
export const setupApp = async (module: TestingModule) => {
|
||||
const app = module.createNestApplication<NestFastifyApplication>(fastifyApp)
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
errorHttpStatusCode: 422,
|
||||
forbidUnknownValues: true,
|
||||
enableDebugMessages: isDev,
|
||||
stopAtFirstError: true,
|
||||
}),
|
||||
)
|
||||
|
||||
await app.init()
|
||||
await app.getHttpAdapter().getInstance().ready()
|
||||
return app
|
||||
}
|
||||
5
test/helper/utils.helper.ts
Normal file
5
test/helper/utils.helper.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const firstOfMap = <K, V>(map: Map<K, V>) => [...map.entries()]?.[0]
|
||||
export const firstKeyOfMap = <K, V>(map: Map<K, V>) =>
|
||||
[...map.entries()]?.[0][0]
|
||||
export const firstValueOfMap = <K, V>(map: Map<K, V>) =>
|
||||
[...map.entries()]?.[0][1]
|
||||
Reference in New Issue
Block a user