36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
// @vitest-environment node
|
|
import { describe, it, expect, vi } from 'vitest'
|
|
|
|
vi.mock('@/lib/auth/get-session', () => ({
|
|
getSession: async () => ({ sub: 'owner-1', role: 'capa_owner' }),
|
|
}))
|
|
vi.mock('@/lib/db/audit', () => ({ writeAuditLog: vi.fn() }))
|
|
vi.mock('@/lib/db/with-user', () => ({
|
|
withUser: async (_id: string, fn: (tx: unknown) => unknown) =>
|
|
fn({
|
|
select: () => ({ from: () => ({ where: () => ({ limit: async () => [{ ownerUserId: 'owner-1', status: 'in_progress' }] }) }) }),
|
|
update: () => ({ set: () => ({ where: async () => undefined }) }),
|
|
}),
|
|
}))
|
|
|
|
import { PATCH } from '@/app/api/capa/[id]/route'
|
|
|
|
const ctx = { params: Promise.resolve({ id: 'capa-1' }) }
|
|
const patch = (body: unknown) =>
|
|
new Request('http://localhost/api/capa/capa-1', {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(body),
|
|
})
|
|
|
|
describe('PATCH /api/capa/[id]', () => {
|
|
it('rejects pending_verification (must use /submit)', async () => {
|
|
const res = await PATCH(patch({ status: 'pending_verification' }) as never, ctx)
|
|
expect(res.status).toBe(403)
|
|
})
|
|
it('still allows in_progress', async () => {
|
|
const res = await PATCH(patch({ status: 'in_progress' }) as never, ctx)
|
|
expect(res.status).toBe(200)
|
|
})
|
|
})
|