update:增加文档模式
This commit is contained in:
81
server/test/tool-launch-none.e2e-spec.ts
Normal file
81
server/test/tool-launch-none.e2e-spec.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AccessMode, ToolStatus } from '@prisma/client';
|
||||
import { randomUUID } from 'crypto';
|
||||
import request from 'supertest';
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { PrismaService } from '../src/prisma/prisma.service';
|
||||
|
||||
describe('Tool launch none mode (e2e)', () => {
|
||||
let app: INestApplication;
|
||||
let prisma: PrismaService;
|
||||
let categoryId = '';
|
||||
let toolId = '';
|
||||
|
||||
beforeAll(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
prisma = app.get(PrismaService);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
categoryId = `cat_${randomUUID().replace(/-/g, '')}`;
|
||||
toolId = `tool_${randomUUID().replace(/-/g, '')}`;
|
||||
|
||||
await prisma.category.create({
|
||||
data: {
|
||||
id: categoryId,
|
||||
name: `Category ${toolId}`,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.tool.create({
|
||||
data: {
|
||||
id: toolId,
|
||||
name: 'Preview Tool',
|
||||
slug: `preview-${randomUUID().slice(0, 8)}`,
|
||||
categoryId,
|
||||
description: 'Preview only tool',
|
||||
accessMode: AccessMode.none,
|
||||
versionOverride: 'preview-1',
|
||||
status: ToolStatus.published,
|
||||
updatedAt: '2026-04-14',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await prisma.tool.deleteMany({
|
||||
where: {
|
||||
id: toolId,
|
||||
},
|
||||
});
|
||||
await prisma.category.deleteMany({
|
||||
where: {
|
||||
id: categoryId,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
function getHttpServer(): Parameters<typeof request>[0] {
|
||||
return app.getHttpServer() as Parameters<typeof request>[0];
|
||||
}
|
||||
|
||||
it('returns 409 when launching a none mode tool', async () => {
|
||||
await request(getHttpServer())
|
||||
.post(`/tools/${toolId}/launch`)
|
||||
.send({
|
||||
channel: 'official',
|
||||
clientVersion: 'web-1.0.0',
|
||||
})
|
||||
.expect(409);
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,8 @@ interface ToolDetailResponse {
|
||||
slug: string;
|
||||
name: string;
|
||||
description: string;
|
||||
accessMode: string;
|
||||
displayVersion: string | null;
|
||||
}
|
||||
|
||||
describe('Tools detail by slug (e2e)', () => {
|
||||
@@ -51,6 +53,7 @@ describe('Tools detail by slug (e2e)', () => {
|
||||
description: '# Manual\n\n## Install',
|
||||
accessMode: AccessMode.web,
|
||||
openUrl: 'https://example.com/tool',
|
||||
versionOverride: '2026.04',
|
||||
status: ToolStatus.published,
|
||||
updatedAt: '2026-04-11',
|
||||
},
|
||||
@@ -87,10 +90,46 @@ describe('Tools detail by slug (e2e)', () => {
|
||||
expect(body.slug).toBe(toolSlug);
|
||||
expect(body.name).toBe('Slug Detail Tool');
|
||||
expect(body.description).toContain('# Manual');
|
||||
expect(body.accessMode).toBe(AccessMode.web);
|
||||
expect(body.displayVersion).toBe('2026.04');
|
||||
});
|
||||
});
|
||||
|
||||
it('returns 404 for an unknown slug', async () => {
|
||||
await request(getHttpServer()).get('/tools/slug/missing-tool').expect(404);
|
||||
});
|
||||
|
||||
it('returns none mode tool detail with displayVersion', async () => {
|
||||
const noneToolId = `tool_${randomUUID().replace(/-/g, '')}`;
|
||||
const noneToolSlug = `none-tool-${randomUUID().slice(0, 8)}`;
|
||||
|
||||
await prisma.tool.create({
|
||||
data: {
|
||||
id: noneToolId,
|
||||
name: 'Preview Tool',
|
||||
slug: noneToolSlug,
|
||||
categoryId,
|
||||
description: '# Preview\n\n即将上线',
|
||||
accessMode: 'none' as AccessMode,
|
||||
versionOverride: 'preview-1',
|
||||
status: ToolStatus.published,
|
||||
updatedAt: '2026-04-11',
|
||||
},
|
||||
});
|
||||
|
||||
await request(getHttpServer())
|
||||
.get(`/tools/slug/${noneToolSlug}`)
|
||||
.expect(200)
|
||||
.expect(({ body }: { body: ToolDetailResponse }) => {
|
||||
expect(body.id).toBe(noneToolId);
|
||||
expect(body.accessMode).toBe('none');
|
||||
expect(body.displayVersion).toBe('preview-1');
|
||||
});
|
||||
|
||||
await prisma.tool.deleteMany({
|
||||
where: {
|
||||
id: noneToolId,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user