update first - 84

This commit is contained in:
thanhnv
2026-06-30 02:21:39 +09:00
commit 07ac1bdcdd
561 changed files with 88164 additions and 0 deletions
@@ -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;
}