70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
vi.mock('@/lib/prisma', () => ({
|
|
prisma: {
|
|
story: {
|
|
findFirst: vi.fn(),
|
|
},
|
|
task: {
|
|
findMany: vi.fn(),
|
|
update: vi.fn(),
|
|
},
|
|
$transaction: vi.fn(),
|
|
},
|
|
}))
|
|
|
|
vi.mock('@/lib/api-auth', () => ({
|
|
authenticateApiRequest: vi.fn(),
|
|
}))
|
|
|
|
import { prisma } from '@/lib/prisma'
|
|
import { authenticateApiRequest } from '@/lib/api-auth'
|
|
import { PATCH as patchReorder } from '@/app/api/stories/[id]/tasks/reorder/route'
|
|
|
|
const mockPrisma = prisma as unknown as {
|
|
story: { findFirst: ReturnType<typeof vi.fn> }
|
|
task: { findMany: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> }
|
|
$transaction: ReturnType<typeof vi.fn>
|
|
}
|
|
const mockAuth = authenticateApiRequest as ReturnType<typeof vi.fn>
|
|
|
|
function makeRequest(body: unknown, storyId = 'story-1'): [Request, { params: Promise<{ id: string }> }] {
|
|
return [
|
|
new Request(`http://localhost/api/stories/${storyId}/tasks/reorder`, {
|
|
method: 'PATCH',
|
|
headers: { Authorization: 'Bearer test-token', 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(body),
|
|
}),
|
|
{ params: Promise.resolve({ id: storyId }) },
|
|
]
|
|
}
|
|
|
|
describe('PATCH /api/stories/:id/tasks/reorder', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
// TC-RO-01
|
|
it.todo('returns 401 when no token provided')
|
|
|
|
// TC-RO-03
|
|
it.todo('returns 403 for demo users')
|
|
|
|
// TC-RO-04
|
|
it.todo('returns 404 when story is not found')
|
|
|
|
// TC-RO-05
|
|
it.todo('returns 404 for another user\'s story')
|
|
|
|
// TC-RO-06
|
|
it.todo('returns 400 when task_ids is an empty array')
|
|
|
|
// TC-RO-07
|
|
it.todo('returns 400 when task_ids is not an array')
|
|
|
|
// TC-RO-08
|
|
it.todo('returns 400 when task_ids contains IDs from a different story')
|
|
|
|
// TC-RO-09
|
|
it.todo('reorders tasks and returns 200')
|
|
})
|