| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- import { INestApplication } from '@nestjs/common';
- import { Test } from '@nestjs/testing';
- import * as request from 'supertest';
- import { AppModule } from '../src/app.module';
- import { configureApp } from '../src/app.setup';
- describe('App (e2e)', () => {
- let app: INestApplication;
- beforeAll(async () => {
- const moduleRef = await Test.createTestingModule({
- imports: [AppModule],
- }).compile();
- app = moduleRef.createNestApplication();
- configureApp(app);
- await app.init();
- });
- afterAll(async () => {
- await app.close();
- });
- it('/api/v1/health (GET)', async () => {
- const response = await request(app.getHttpServer()).get('/api/v1/health').expect(200);
- expect(response.body).toEqual({
- ok: true,
- data: {
- status: 'ok',
- timestamp: expect.any(String),
- services: {
- database: expect.any(String),
- redis: expect.any(String),
- },
- },
- error: null,
- });
- });
- it('/api/v1/unknown (GET)', async () => {
- const response = await request(app.getHttpServer()).get('/api/v1/unknown').expect(404);
- expect(response.body).toEqual({
- ok: false,
- data: null,
- error: {
- code: 'HTTP_404',
- message: expect.any(String),
- },
- });
- });
- it('/api/v1/auth/stylist/login (POST) validates request body', async () => {
- const response = await request(app.getHttpServer())
- .post('/api/v1/auth/stylist/login')
- .send({ email: 'bad-email', password: '' })
- .expect(400);
- expect(response.body.ok).toBe(false);
- expect(response.body.data).toBeNull();
- expect(response.body.error.code).toBe('HTTP_400');
- });
- it('/api/v1/auth/stylist/login (POST) returns invalid credentials when no matching account exists', async () => {
- const response = await request(app.getHttpServer())
- .post('/api/v1/auth/stylist/login')
- .send({ email: 'missing-app-e2e@example.com', password: 'Passw0rd!' })
- .expect(401);
- expect(response.body).toEqual({
- ok: false,
- data: null,
- error: {
- code: 'AUTH_INVALID_CREDENTIALS',
- message: '邮箱或密码错误',
- },
- });
- });
- it('/api/v1/customers (GET) requires authentication', async () => {
- const response = await request(app.getHttpServer())
- .get('/api/v1/customers')
- .expect(401);
- expect(response.body).toEqual({
- ok: false,
- data: null,
- error: {
- code: 'AUTH_UNAUTHORIZED',
- message: '未登录或登录已失效',
- },
- });
- });
- it('/api/v1/templates (GET) returns an empty list envelope', async () => {
- const response = await request(app.getHttpServer())
- .get('/api/v1/templates')
- .expect(200);
- expect(response.body).toEqual({
- ok: true,
- data: {
- items: [],
- total: 0,
- },
- error: null,
- });
- });
- it('/api/v1/simulations (POST) validates create payload', async () => {
- await request(app.getHttpServer())
- .post('/api/v1/simulations')
- .send({})
- .expect(400);
- });
- });
|