import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; import * as request from 'supertest'; import { AppModule } from '../../../src/app.module'; describe('SYS Module e2e', () => { let app: INestApplication; beforeAll(async () => { const moduleRef = await Test.createTestingModule({ imports: [AppModule], }).compile(); app = moduleRef.createNestApplication(); await app.init(); }); afterAll(async () => { await app.close(); }); // 租户隔离:前台按 siteId 查询配置 it('GET /api/config/:key should respect site isolation', async () => { const siteId = 0; // TODO: 准备测试数据后替换 const res = await request(app.getHttpServer()) .get('/api/config/some_key') .set('x-site-id', String(siteId)) .expect(200); expect(res.body).toBeDefined(); }); // 权限校验:无角色访问受限接口应被拒绝 it('GET /adminapi/sys/menu/list without token should be unauthorized', async () => { await request(app.getHttpServer()) .get('/adminapi/sys/menu/list') .expect(401); }); // 批量读取配置 it('GET /api/config?keys=a,b should return object', async () => { const res = await request(app.getHttpServer()) .get('/api/config') .query({ keys: 'a,b' }) .expect(200); expect(typeof res.body).toBe('object'); }); // 其他管理端受限接口 401 验证 it('GET /adminapi/sys/dict/types without token should be unauthorized', async () => { await request(app.getHttpServer()) .get('/adminapi/sys/dict/types') .expect(401); }); it('GET /adminapi/sys/area/list without token should be unauthorized', async () => { await request(app.getHttpServer()) .get('/adminapi/sys/area/list') .expect(401); }); // 前台公开接口 200 验证 it('GET /api/dict/demo/items should return 200 (even if empty)', async () => { const res = await request(app.getHttpServer()) .get('/api/dict/demo/items') .expect(200); expect(Array.isArray(res.body)).toBe(true); }); it('GET /api/area/tree should return 200 (even if empty)', async () => { const res = await request(app.getHttpServer()) .get('/api/area/tree') .expect(200); expect(Array.isArray(res.body)).toBe(true); }); });