94 lines
2.3 KiB
TypeScript
94 lines
2.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
vi.mock('@/lib/prisma', () => ({
|
|
prisma: {
|
|
story: {
|
|
findFirst: vi.fn(),
|
|
},
|
|
storyLog: {
|
|
create: vi.fn(),
|
|
},
|
|
},
|
|
}))
|
|
|
|
vi.mock('@/lib/api-auth', () => ({
|
|
authenticateApiRequest: vi.fn(),
|
|
}))
|
|
|
|
import { prisma } from '@/lib/prisma'
|
|
import { authenticateApiRequest } from '@/lib/api-auth'
|
|
import { POST as postStoryLog } from '@/app/api/stories/[id]/log/route'
|
|
|
|
const mockPrisma = prisma as unknown as {
|
|
story: { findFirst: ReturnType<typeof vi.fn> }
|
|
storyLog: { create: 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}/log`, {
|
|
method: 'POST',
|
|
headers: { Authorization: 'Bearer test-token', 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(body),
|
|
}),
|
|
{ params: Promise.resolve({ id: storyId }) },
|
|
]
|
|
}
|
|
|
|
describe('POST /api/stories/:id/log', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
// TC-L-01
|
|
it.todo('returns 401 when no token provided')
|
|
|
|
// TC-L-03
|
|
it.todo('returns 403 for demo users')
|
|
|
|
// TC-L-04
|
|
it.todo('returns 404 when story is not found')
|
|
|
|
// TC-L-05
|
|
it.todo('returns 404 for another user\'s story')
|
|
|
|
// TC-L-06
|
|
it.todo('returns 400 when type field is missing')
|
|
|
|
// TC-L-07
|
|
it.todo('returns 400 for unknown type value')
|
|
|
|
describe('type: IMPLEMENTATION_PLAN', () => {
|
|
// TC-L-08
|
|
it.todo('returns 400 when content is missing')
|
|
|
|
// TC-L-09
|
|
it.todo('creates log entry and returns 201')
|
|
})
|
|
|
|
describe('type: TEST_RESULT', () => {
|
|
// TC-L-10
|
|
it.todo('returns 400 when status is missing')
|
|
|
|
// TC-L-11
|
|
it.todo('returns 400 for invalid status value')
|
|
|
|
// TC-L-12
|
|
it.todo('creates log entry with status PASSED and returns 201')
|
|
|
|
// TC-L-13
|
|
it.todo('creates log entry with status FAILED and returns 201')
|
|
})
|
|
|
|
describe('type: COMMIT', () => {
|
|
// TC-L-14
|
|
it.todo('returns 400 when commit_hash is missing')
|
|
|
|
// TC-L-15
|
|
it.todo('returns 400 when commit_message is missing')
|
|
|
|
// TC-L-16
|
|
it.todo('creates log entry with commit fields and returns 201')
|
|
})
|
|
})
|