feat: add home page and refactor workspace entry UI

This commit is contained in:
saturn
2026-03-23 17:45:17 +08:00
parent a6ad11b9c4
commit 4e469074e0
48 changed files with 2970 additions and 453 deletions

View File

@@ -0,0 +1,67 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { buildMockRequest } from '../../../helpers/request'
const authMock = vi.hoisted(() => ({
requireProjectAuth: vi.fn(async () => ({
novelData: { id: 'np-1', projectId: 'project-1' },
})),
isErrorResponse: vi.fn((value: unknown) => value instanceof Response),
}))
const prismaMock = vi.hoisted(() => ({
novelPromotionEpisode: {
findFirst: vi.fn(async () => null),
create: vi.fn(async () => ({
id: 'episode-1',
novelPromotionProjectId: 'np-1',
episodeNumber: 1,
name: '第 1 集',
description: null,
novelText: '第一章内容',
})),
},
novelPromotionProject: {
update: vi.fn(async () => ({
id: 'np-1',
lastEpisodeId: 'episode-1',
})),
},
}))
vi.mock('@/lib/api-auth', () => authMock)
vi.mock('@/lib/prisma', () => ({ prisma: prismaMock }))
describe('api specific - novel promotion episode create text', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('persists novelText when creating the first episode from home launch', async () => {
const mod = await import('@/app/api/novel-promotion/[projectId]/episodes/route')
const req = buildMockRequest({
path: '/api/novel-promotion/project-1/episodes',
method: 'POST',
body: {
name: '第 1 集',
novelText: '第一章内容',
},
})
const res = await mod.POST(req, { params: Promise.resolve({ projectId: 'project-1' }) })
expect(res.status).toBe(201)
expect(prismaMock.novelPromotionEpisode.create).toHaveBeenCalledWith({
data: {
novelPromotionProjectId: 'np-1',
episodeNumber: 1,
name: '第 1 集',
description: null,
novelText: '第一章内容',
},
})
expect(prismaMock.novelPromotionProject.update).toHaveBeenCalledWith({
where: { id: 'np-1' },
data: { lastEpisodeId: 'episode-1' },
})
})
})