Scrum4Me/__tests__/api/tasks.test.ts
Madhura68 46e795002f test(scaffold): add skeleton test files for all 7 API endpoints
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 18:24:25 +02:00

58 lines
1.5 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('@/lib/prisma', () => ({
prisma: {
task: {
findFirst: vi.fn(),
update: vi.fn(),
},
},
}))
vi.mock('@/lib/api-auth', () => ({
authenticateApiRequest: vi.fn(),
}))
import { prisma } from '@/lib/prisma'
import { authenticateApiRequest } from '@/lib/api-auth'
import { PATCH as patchTask } from '@/app/api/tasks/[id]/route'
const mockPrisma = prisma as unknown as {
task: { findFirst: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> }
}
const mockAuth = authenticateApiRequest as ReturnType<typeof vi.fn>
function makeRequest(body: unknown, taskId = 'task-1'): [Request, { params: Promise<{ id: string }> }] {
return [
new Request(`http://localhost/api/tasks/${taskId}`, {
method: 'PATCH',
headers: { Authorization: 'Bearer test-token', 'Content-Type': 'application/json' },
body: JSON.stringify(body),
}),
{ params: Promise.resolve({ id: taskId }) },
]
}
describe('PATCH /api/tasks/:id', () => {
beforeEach(() => {
vi.clearAllMocks()
})
// TC-T-06
it.todo('returns 400 for invalid status value')
// TC-T-07
it.todo('returns 400 when body has no recognized fields')
// TC-T-08
it.todo('updates status only and returns 200')
// TC-T-09
it.todo('updates implementation_plan only and returns 200')
// TC-T-10
it.todo('updates both status and implementation_plan and returns 200')
// TC-T-11
it.todo('allows update when user is a team member of the product')
})