import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; import request from 'supertest'; import { AppModule } from '../src/app.module'; describe('M3 E2E Tests', () => { let app: INestApplication; beforeAll(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); app = moduleFixture.createNestApplication(); app.setGlobalPrefix('api', { exclude: ['admin-api/(.*)', 'internal/(.*)'] }); await app.init(); }); afterAll(async () => { await app.close(); }); async function loginAdmin(): Promise { const res = await request(app.getHttpServer()) .post('/admin-api/auth/login') .send({ email: 'admin@zhixi.app', password: 'admin123' }); return res.body?.data?.accessToken || ''; } // ══════════════════════════════════════════════ // M3-01: Learning Engine // ══════════════════════════════════════════════ describe('M3-01 Learning Engine', () => { let token: string; beforeAll(async () => { token = await loginAdmin(); }); it('POST /api/learning-sessions → 201 create session', async () => { const res = await request(app.getHttpServer()) .post('/api/learning-sessions') .send({ knowledgeItemId: 'ki-1', title: 'Test Session' }) .expect([200, 201]); expect(res.body.data).toHaveProperty('id'); }); it('GET /api/learning-sessions → 200 list sessions', async () => { const res = await request(app.getHttpServer()) .get('/api/learning-sessions') .expect(200); expect(Array.isArray(res.body.data)).toBe(true); }); it('POST /api/ai-analysis → 201 queue analysis', async () => { const res = await request(app.getHttpServer()) .post('/api/ai-analysis') .send({ questionText: 'What is this?', knowledgeItemContent: 'Test content', userAnswer: 'Test answer', sessionId: 's1' }) .expect([200, 201]); expect(res.body.data).toHaveProperty('jobId'); }); it('POST /api/ai-analysis/feynman → 201 queue feynman eval', async () => { const res = await request(app.getHttpServer()) .post('/api/ai-analysis/feynman') .send({ knowledgeItemTitle: 'Test', knowledgeItemContent: 'Content', userExplanation: 'Explanation', sessionId: 's1' }) .expect([200, 201]); expect(res.body.data).toHaveProperty('jobId'); }); it('GET /api/focus-items → 200 list focus items', async () => { const res = await request(app.getHttpServer()) .get('/api/focus-items') .expect(200); expect(Array.isArray(res.body.data)).toBe(true); }); it('GET /api/activity/summary → 200 learning summary', async () => { const res = await request(app.getHttpServer()) .get('/api/activity/summary') .expect(200); expect(res.body).toHaveProperty('success'); }); }); });