538de50bb1
- Prisma User 模型新增 username 字段(唯一索引) - 注册先查重复再创建,返回友好中文提示(非 500) - 登录支持用户名/手机号/邮箱三种方式 - 前端注册表单增加用户名输入框,预校验 2-20 位格式 - 新增 scripts/deploy.sh:一键构建并部署主站+镜像站+重启后端+重载 Nginx - 镜像站 www.yuzhiran.com.cn Nginx 配置与主站同步 - AI 助手架构升级:用户端/管理后台均采用完整 Tool Calling 架构 - 新增 UserAiAssistantService(18 工具)+ AiAssistantController - admin 助手新增 search + mark-all-notifications-read 工具 - 修复注册 500 错误:catch Prisma P2002 → BadRequestException - Baidu Analytics Script 注入 root layout
144 lines
3.9 KiB
TypeScript
Executable File
144 lines
3.9 KiB
TypeScript
Executable File
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { INestApplication, ValidationPipe } from '@nestjs/common';
|
|
import * as request from 'supertest';
|
|
import { AppModule } from '../src/app.module';
|
|
|
|
describe('API (e2e)', () => {
|
|
let app: INestApplication;
|
|
|
|
beforeAll(async () => {
|
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
imports: [AppModule],
|
|
}).compile();
|
|
|
|
app = moduleFixture.createNestApplication();
|
|
app.setGlobalPrefix('api/v1');
|
|
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
|
|
await app.init();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
|
|
describe('Auth', () => {
|
|
it('POST /api/v1/auth/register should validate input', () => {
|
|
return request(app.getHttpServer())
|
|
.post('/api/v1/auth/register')
|
|
.send({})
|
|
.expect(400);
|
|
});
|
|
});
|
|
|
|
describe('Courses', () => {
|
|
it('GET /api/v1/courses should return paginated results', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/courses')
|
|
.expect(200)
|
|
.expect((res) => {
|
|
expect(res.body).toHaveProperty('items');
|
|
expect(res.body).toHaveProperty('total');
|
|
expect(res.body).toHaveProperty('page');
|
|
expect(res.body).toHaveProperty('pageSize');
|
|
});
|
|
});
|
|
|
|
it('GET /api/v1/courses/:id should return 404 for non-existent', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/courses/99999')
|
|
.expect(200);
|
|
});
|
|
});
|
|
|
|
describe('Categories', () => {
|
|
it('GET /api/v1/categories should return list', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/categories')
|
|
.expect(200);
|
|
});
|
|
});
|
|
|
|
describe('Prompts', () => {
|
|
it('GET /api/v1/prompts should return paginated results', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/prompts')
|
|
.expect(200)
|
|
.expect((res) => {
|
|
expect(res.body).toHaveProperty('items');
|
|
expect(res.body).toHaveProperty('total');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Community', () => {
|
|
it('GET /api/v1/community/posts should return paginated results', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/community/posts')
|
|
.expect(200)
|
|
.expect((res) => {
|
|
expect(res.body).toHaveProperty('items');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Circles', () => {
|
|
it('GET /api/v1/circles should return list', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/circles')
|
|
.expect(200);
|
|
});
|
|
});
|
|
|
|
describe('Search', () => {
|
|
it('GET /api/v1/search should return results', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/search?q=AI')
|
|
.expect(200)
|
|
.expect((res) => {
|
|
expect(res.body).toHaveProperty('results');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Models', () => {
|
|
it('GET /api/v1/models should return list', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/models')
|
|
.expect(200);
|
|
});
|
|
});
|
|
|
|
describe('Tools', () => {
|
|
it('GET /api/v1/tools should return paginated results', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/tools')
|
|
.expect(200)
|
|
.expect((res) => {
|
|
expect(res.body).toHaveProperty('items');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Contents', () => {
|
|
it('GET /api/v1/contents should return paginated results', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/contents')
|
|
.expect(200);
|
|
});
|
|
});
|
|
|
|
describe('Protected endpoints', () => {
|
|
it('GET /api/v1/dashboard/stats should return 401 without token', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/dashboard/stats')
|
|
.expect(401);
|
|
});
|
|
|
|
it('GET /api/v1/orders should return 401 without token', () => {
|
|
return request(app.getHttpServer())
|
|
.get('/api/v1/orders')
|
|
.expect(401);
|
|
});
|
|
});
|
|
});
|