feat: updade workspace
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import { PrismaService } from '../src/prisma/prisma.service.js';
|
||||
import { AppModule } from '../src/app.module.js';
|
||||
|
||||
export async function createTestApp(): Promise<{ app: INestApplication; prisma: PrismaService }> {
|
||||
const moduleRef = await Test.createTestingModule({ imports: [AppModule] }).compile();
|
||||
const app = moduleRef.createNestApplication();
|
||||
app.setGlobalPrefix('api/v1');
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
transform: true,
|
||||
}),
|
||||
);
|
||||
await app.init();
|
||||
return { app, prisma: app.get(PrismaService) };
|
||||
}
|
||||
|
||||
export async function loginToken(app: INestApplication, username = 'employee'): Promise<string> {
|
||||
const request = await import('supertest');
|
||||
const response = await request
|
||||
.default(app.getHttpServer())
|
||||
.post('/api/v1/auth/login')
|
||||
.send({ username, password: 'Password@123' })
|
||||
.expect(201);
|
||||
return response.body.data.token as string;
|
||||
}
|
||||
Reference in New Issue
Block a user