- 重构sys模块架构,严格按admin/api/core分层 - 对齐所有sys实体与数据库表结构 - 实现完整的adminapi控制器,匹配PHP/Java契约 - 修复依赖注入问题,确保服务正确注册 - 添加自动迁移工具和契约验证 - 完善多租户支持和审计功能 - 统一命名规范,与PHP业务逻辑保持一致
76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
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);
|
|
});
|
|
});
|