feat: add props system and refactor asset library architecture
This commit is contained in:
@@ -40,6 +40,16 @@ const prismaMock = vi.hoisted(() => ({
|
||||
novelPromotionClip: {
|
||||
update: vi.fn(),
|
||||
},
|
||||
novelPromotionStoryboard: {
|
||||
findUnique: vi.fn(),
|
||||
update: vi.fn(),
|
||||
},
|
||||
novelPromotionPanel: {
|
||||
findUnique: vi.fn(),
|
||||
update: vi.fn(),
|
||||
create: vi.fn(),
|
||||
count: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/api-auth', () => {
|
||||
@@ -158,14 +168,18 @@ async function invokeRouteMethod(
|
||||
const req = buildMockRequest({
|
||||
path,
|
||||
method,
|
||||
...(method === 'GET' || method === 'DELETE' ? {} : { body: buildGenericBody() }),
|
||||
...(method === 'GET' ? {} : { body: buildGenericBody() }),
|
||||
})
|
||||
return await handler(req, { params: Promise.resolve(params) })
|
||||
}
|
||||
|
||||
describe('api contract - crud routes (behavior)', () => {
|
||||
const routes = ROUTE_CATALOG.filter(
|
||||
(entry) => entry.contractGroup === 'crud-asset-hub-routes' || entry.contractGroup === 'crud-novel-promotion-routes',
|
||||
(entry) => (
|
||||
entry.contractGroup === 'crud-assets-routes'
|
||||
|| entry.contractGroup === 'crud-asset-hub-routes'
|
||||
|| entry.contractGroup === 'crud-novel-promotion-routes'
|
||||
),
|
||||
)
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -223,9 +237,36 @@ describe('api contract - crud routes (behavior)', () => {
|
||||
id: 'clip-1',
|
||||
characters: JSON.stringify(['Alice']),
|
||||
location: 'Old Town',
|
||||
props: JSON.stringify(['Bronze Dagger']),
|
||||
content: 'clip content',
|
||||
screenplay: JSON.stringify({ scenes: [{ id: 1 }] }),
|
||||
})
|
||||
prismaMock.novelPromotionStoryboard.findUnique.mockResolvedValue({
|
||||
id: 'storyboard-1',
|
||||
projectId: 'project-1',
|
||||
})
|
||||
prismaMock.novelPromotionStoryboard.update.mockResolvedValue({
|
||||
id: 'storyboard-1',
|
||||
panelCount: 1,
|
||||
})
|
||||
prismaMock.novelPromotionPanel.findUnique.mockResolvedValue({
|
||||
id: 'panel-1',
|
||||
storyboardId: 'storyboard-1',
|
||||
panelIndex: 0,
|
||||
})
|
||||
prismaMock.novelPromotionPanel.update.mockResolvedValue({
|
||||
id: 'panel-1',
|
||||
storyboardId: 'storyboard-1',
|
||||
panelIndex: 0,
|
||||
props: JSON.stringify(['Bronze Dagger']),
|
||||
})
|
||||
prismaMock.novelPromotionPanel.create.mockResolvedValue({
|
||||
id: 'panel-2',
|
||||
storyboardId: 'storyboard-1',
|
||||
panelIndex: 1,
|
||||
props: JSON.stringify(['Bronze Dagger']),
|
||||
})
|
||||
prismaMock.novelPromotionPanel.count.mockResolvedValue(1)
|
||||
})
|
||||
|
||||
it('crud route group exists', () => {
|
||||
@@ -329,11 +370,9 @@ describe('api contract - crud routes (behavior)', () => {
|
||||
},
|
||||
})
|
||||
|
||||
const payload = await res.json() as { success: boolean; selectedIndex: number; imageUrl: string }
|
||||
const payload = await res.json() as { success: boolean }
|
||||
expect(payload).toEqual({
|
||||
success: true,
|
||||
selectedIndex: 1,
|
||||
imageUrl: 'https://signed.example/cos/char-1.png',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -374,6 +413,7 @@ describe('api contract - crud routes (behavior)', () => {
|
||||
body: {
|
||||
characters: JSON.stringify(['Alice']),
|
||||
location: 'Old Town',
|
||||
props: JSON.stringify(['Bronze Dagger']),
|
||||
content: 'clip content',
|
||||
screenplay: JSON.stringify({ scenes: [{ id: 1 }] }),
|
||||
},
|
||||
@@ -388,9 +428,42 @@ describe('api contract - crud routes (behavior)', () => {
|
||||
data: {
|
||||
characters: JSON.stringify(['Alice']),
|
||||
location: 'Old Town',
|
||||
props: JSON.stringify(['Bronze Dagger']),
|
||||
content: 'clip content',
|
||||
screenplay: JSON.stringify({ scenes: [{ id: 1 }] }),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('PUT /novel-promotion/[projectId]/panel writes provided props to prisma.novelPromotionPanel.update', async () => {
|
||||
authState.authenticated = true
|
||||
const mod = await import('@/app/api/novel-promotion/[projectId]/panel/route')
|
||||
const req = buildMockRequest({
|
||||
path: '/api/novel-promotion/project-1/panel',
|
||||
method: 'PUT',
|
||||
body: {
|
||||
storyboardId: 'storyboard-1',
|
||||
panelIndex: 0,
|
||||
location: 'Old Town',
|
||||
characters: JSON.stringify(['Alice']),
|
||||
props: JSON.stringify(['Bronze Dagger']),
|
||||
description: 'panel description',
|
||||
},
|
||||
})
|
||||
|
||||
const res = await mod.PUT(req, {
|
||||
params: Promise.resolve({ projectId: 'project-1' }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(prismaMock.novelPromotionPanel.update).toHaveBeenCalledWith({
|
||||
where: { id: 'panel-1' },
|
||||
data: {
|
||||
location: 'Old Town',
|
||||
characters: JSON.stringify(['Alice']),
|
||||
props: JSON.stringify(['Bronze Dagger']),
|
||||
description: 'panel description',
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -288,11 +288,12 @@ vi.mock('@/lib/prisma', () => ({
|
||||
prisma: prismaMock,
|
||||
}))
|
||||
|
||||
function toApiPath(routeFile: string): string {
|
||||
function toApiPath(routeFile: string, params?: Record<string, string>): string {
|
||||
return routeFile
|
||||
.replace(/^src\/app/, '')
|
||||
.replace(/\/route\.ts$/, '')
|
||||
.replace('[projectId]', 'project-1')
|
||||
.replace('[projectId]', params?.projectId || 'project-1')
|
||||
.replace('[assetId]', params?.assetId || 'asset-1')
|
||||
}
|
||||
|
||||
function toModuleImportPath(routeFile: string): string {
|
||||
@@ -321,6 +322,62 @@ const DIRECT_CASES: ReadonlyArray<DirectRouteCase> = [
|
||||
expectedTargetType: 'GlobalCharacterAppearance',
|
||||
expectedProjectId: 'global-asset-hub',
|
||||
},
|
||||
{
|
||||
routeFile: 'src/app/api/assets/[assetId]/generate/route.ts',
|
||||
body: {
|
||||
scope: 'global',
|
||||
kind: 'character',
|
||||
appearanceIndex: 0,
|
||||
artStyle: 'realistic',
|
||||
},
|
||||
params: { assetId: 'global-character-1' },
|
||||
expectedTaskType: TASK_TYPE.ASSET_HUB_IMAGE,
|
||||
expectedTargetType: 'GlobalCharacter',
|
||||
expectedProjectId: 'global-asset-hub',
|
||||
},
|
||||
{
|
||||
routeFile: 'src/app/api/assets/[assetId]/generate/route.ts',
|
||||
body: {
|
||||
scope: 'project',
|
||||
kind: 'character',
|
||||
projectId: 'project-1',
|
||||
appearanceId: 'appearance-1',
|
||||
},
|
||||
params: { assetId: 'character-1' },
|
||||
expectedTaskType: TASK_TYPE.IMAGE_CHARACTER,
|
||||
expectedTargetType: 'CharacterAppearance',
|
||||
expectedProjectId: 'project-1',
|
||||
},
|
||||
{
|
||||
routeFile: 'src/app/api/assets/[assetId]/modify-render/route.ts',
|
||||
body: {
|
||||
scope: 'global',
|
||||
kind: 'character',
|
||||
modifyPrompt: 'sharpen details',
|
||||
appearanceIndex: 0,
|
||||
imageIndex: 0,
|
||||
extraImageUrls: ['https://example.com/ref-a.png'],
|
||||
},
|
||||
params: { assetId: 'global-character-1' },
|
||||
expectedTaskType: TASK_TYPE.ASSET_HUB_MODIFY,
|
||||
expectedTargetType: 'GlobalCharacterAppearance',
|
||||
expectedProjectId: 'global-asset-hub',
|
||||
},
|
||||
{
|
||||
routeFile: 'src/app/api/assets/[assetId]/modify-render/route.ts',
|
||||
body: {
|
||||
scope: 'project',
|
||||
kind: 'character',
|
||||
projectId: 'project-1',
|
||||
appearanceId: 'appearance-1',
|
||||
modifyPrompt: 'enhance texture',
|
||||
extraImageUrls: ['https://example.com/ref-b.png'],
|
||||
},
|
||||
params: { assetId: 'character-1' },
|
||||
expectedTaskType: TASK_TYPE.MODIFY_ASSET_IMAGE,
|
||||
expectedTargetType: 'CharacterAppearance',
|
||||
expectedProjectId: 'project-1',
|
||||
},
|
||||
{
|
||||
routeFile: 'src/app/api/asset-hub/voice-design/route.ts',
|
||||
body: { voicePrompt: 'female calm narrator', previewText: '你好世界' },
|
||||
@@ -466,7 +523,7 @@ async function invokePostRoute(routeCase: DirectRouteCase): Promise<Response> {
|
||||
const mod = await import(modulePath)
|
||||
const post = mod.POST as (request: Request, context?: RouteContext) => Promise<Response>
|
||||
const req = buildMockRequest({
|
||||
path: toApiPath(routeCase.routeFile),
|
||||
path: toApiPath(routeCase.routeFile, routeCase.params),
|
||||
method: 'POST',
|
||||
body: routeCase.body,
|
||||
})
|
||||
@@ -486,7 +543,7 @@ describe('api contract - direct submit routes (behavior)', () => {
|
||||
})
|
||||
|
||||
it('keeps expected coverage size', () => {
|
||||
expect(DIRECT_CASES.length).toBe(16)
|
||||
expect(DIRECT_CASES.length).toBe(20)
|
||||
})
|
||||
|
||||
for (const routeCase of DIRECT_CASES) {
|
||||
|
||||
Reference in New Issue
Block a user