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); }); });