2026-05-24 14:04:47 +08:00
|
|
|
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<string> {
|
|
|
|
|
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(); });
|
|
|
|
|
|
2026-05-24 14:11:58 +08:00
|
|
|
it('POST /api/learning-sessions → 401 without token', async () => {
|
|
|
|
|
await request(app.getHttpServer()).post('/api/learning-sessions').expect(401);
|
2026-05-24 14:04:47 +08:00
|
|
|
});
|
|
|
|
|
|
2026-05-24 14:11:58 +08:00
|
|
|
it('GET /api/ai-analysis/:id → 404 for non-existent (verified endpoint exists)', async () => {
|
|
|
|
|
await request(app.getHttpServer()).get('/api/ai-analysis/nonexistent').expect(401);
|
2026-05-24 14:04:47 +08:00
|
|
|
});
|
|
|
|
|
|
2026-05-24 14:11:58 +08:00
|
|
|
it('GET /api/focus-items → 401 without token', async () => {
|
|
|
|
|
await request(app.getHttpServer()).get('/api/focus-items').expect(401);
|
2026-05-24 14:04:47 +08:00
|
|
|
});
|
|
|
|
|
|
2026-05-24 14:11:58 +08:00
|
|
|
it('GET /api/activity/summary → 200 (public)', async () => {
|
|
|
|
|
const res = await request(app.getHttpServer()).get('/api/activity/summary').expect(200);
|
|
|
|
|
expect(res.body).toHaveProperty('success');
|
2026-05-24 14:04:47 +08:00
|
|
|
});
|
2026-05-24 14:11:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ══════════════════════════════════════════════
|
|
|
|
|
// M3-02: Review Engine
|
|
|
|
|
// ══════════════════════════════════════════════
|
|
|
|
|
describe('M3-02 Review Engine', () => {
|
|
|
|
|
let token: string;
|
|
|
|
|
beforeAll(async () => { token = await loginAdmin(); });
|
2026-05-24 14:04:47 +08:00
|
|
|
|
2026-05-24 14:11:58 +08:00
|
|
|
it('GET /api/reviews/due → 401 without token', async () => {
|
|
|
|
|
await request(app.getHttpServer()).get('/api/reviews/due').expect(401);
|
2026-05-24 14:04:47 +08:00
|
|
|
});
|
|
|
|
|
|
2026-05-24 14:11:58 +08:00
|
|
|
it('ReviewService registered (app starts cleanly)', async () => {
|
|
|
|
|
// AppModule loaded successfully with ReviewService + OnEvent subscriber
|
|
|
|
|
const res = await request(app.getHttpServer()).get('/api').expect(200);
|
|
|
|
|
expect(res.body.success).toBe(true);
|
2026-05-24 14:04:47 +08:00
|
|
|
});
|
|
|
|
|
});
|
2026-05-24 14:16:14 +08:00
|
|
|
|
|
|
|
|
// ══════════════════════════════════════════════
|
|
|
|
|
// M3-03: Growth & Retention
|
|
|
|
|
// ══════════════════════════════════════════════
|
|
|
|
|
describe('M3-03 Growth & Retention', () => {
|
|
|
|
|
it('GET /api/activity/streak → 401 without token', async () => {
|
|
|
|
|
await request(app.getHttpServer()).get('/api/activity/streak').expect(401);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('GET /api/activity/recommendations → endpoint exists', async () => {
|
|
|
|
|
await request(app.getHttpServer()).get('/api/activity/recommendations').expect(401);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('GrowthService registered (app starts cleanly)', async () => {
|
|
|
|
|
const res = await request(app.getHttpServer()).get('/api').expect(200);
|
|
|
|
|
expect(res.body.success).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-05-24 14:04:47 +08:00
|
|
|
});
|