61 lines
2.9 KiB
TypeScript
61 lines
2.9 KiB
TypeScript
import { afterAll, describe, expect, it } from 'vitest'
|
|
import { prisma } from '../setup'
|
|
import { createTestProgram, createTestProject, cleanupTestData, uid } from '../helpers'
|
|
import { resetOrCreatePendingConfirmation } from '../../src/server/services/finalist-enrollment'
|
|
|
|
describe('resetOrCreatePendingConfirmation', () => {
|
|
const programIds: string[] = []
|
|
afterAll(async () => {
|
|
for (const id of programIds) {
|
|
await prisma.attendingMember.deleteMany({ where: { confirmation: { project: { programId: id } } } })
|
|
await prisma.finalistConfirmation.deleteMany({ where: { project: { programId: id } } })
|
|
await cleanupTestData(id, [])
|
|
}
|
|
})
|
|
|
|
it('creates a fresh PENDING row when none exists', async () => {
|
|
const program = await createTestProgram({ name: `reinvite-new-${uid()}` })
|
|
programIds.push(program.id)
|
|
const project = await createTestProject(program.id, { competitionCategory: 'STARTUP' })
|
|
const res = await resetOrCreatePendingConfirmation(prisma, {
|
|
projectId: project.id, category: 'STARTUP', windowHours: 24,
|
|
})
|
|
const row = await prisma.finalistConfirmation.findUniqueOrThrow({ where: { id: res.id } })
|
|
expect(row.status).toBe('PENDING')
|
|
expect(res.alreadyConfirmed).toBe(false)
|
|
})
|
|
|
|
it('resets a DECLINED row to a fresh PENDING (no unique-constraint crash)', async () => {
|
|
const program = await createTestProgram({ name: `reinvite-declined-${uid()}` })
|
|
programIds.push(program.id)
|
|
const project = await createTestProject(program.id, { competitionCategory: 'STARTUP' })
|
|
await prisma.finalistConfirmation.create({
|
|
data: { projectId: project.id, category: 'STARTUP', status: 'DECLINED',
|
|
deadline: new Date(Date.now() - 1000), token: `tok_${uid()}`, declinedAt: new Date(),
|
|
declineReason: 'busy' },
|
|
})
|
|
const res = await resetOrCreatePendingConfirmation(prisma, {
|
|
projectId: project.id, category: 'STARTUP', windowHours: 24,
|
|
})
|
|
const row = await prisma.finalistConfirmation.findUniqueOrThrow({ where: { id: res.id } })
|
|
expect(row.status).toBe('PENDING')
|
|
expect(row.declinedAt).toBeNull()
|
|
expect(row.declineReason).toBeNull()
|
|
expect(res.alreadyConfirmed).toBe(false)
|
|
})
|
|
|
|
it('is a no-op flagged alreadyConfirmed when row is CONFIRMED', async () => {
|
|
const program = await createTestProgram({ name: `reinvite-confirmed-${uid()}` })
|
|
programIds.push(program.id)
|
|
const project = await createTestProject(program.id, { competitionCategory: 'STARTUP' })
|
|
await prisma.finalistConfirmation.create({
|
|
data: { projectId: project.id, category: 'STARTUP', status: 'CONFIRMED',
|
|
deadline: new Date(Date.now() + 1000), token: `tok_${uid()}`, confirmedAt: new Date() },
|
|
})
|
|
const res = await resetOrCreatePendingConfirmation(prisma, {
|
|
projectId: project.id, category: 'STARTUP', windowHours: 24,
|
|
})
|
|
expect(res.alreadyConfirmed).toBe(true)
|
|
})
|
|
})
|