88 lines
3.7 KiB
TypeScript
88 lines
3.7 KiB
TypeScript
|
|
import { describe, it, expect, afterAll } from 'vitest'
|
||
|
|
import { prisma } from '../setup'
|
||
|
|
import {
|
||
|
|
createTestProgram,
|
||
|
|
createTestCompetition,
|
||
|
|
createTestRound,
|
||
|
|
createTestProject,
|
||
|
|
createTestProjectRoundState,
|
||
|
|
cleanupTestData,
|
||
|
|
uid,
|
||
|
|
} from '../helpers'
|
||
|
|
import { getFinalDocumentStatusForProject } from '@/server/services/final-documents'
|
||
|
|
|
||
|
|
const programIds: string[] = []
|
||
|
|
|
||
|
|
async function makeFinaleProgram(opts: { roundStatus?: 'ROUND_ACTIVE' | 'ROUND_DRAFT'; closeAt?: Date } = {}) {
|
||
|
|
const program = await createTestProgram()
|
||
|
|
programIds.push(program.id)
|
||
|
|
const comp = await createTestCompetition(program.id, { status: 'ACTIVE' })
|
||
|
|
const round = await createTestRound(comp.id, {
|
||
|
|
roundType: 'LIVE_FINAL',
|
||
|
|
status: opts.roundStatus ?? 'ROUND_ACTIVE',
|
||
|
|
sortOrder: 6,
|
||
|
|
windowCloseAt: opts.closeAt ?? new Date(Date.now() + 86_400_000),
|
||
|
|
})
|
||
|
|
const reqPlan = await prisma.fileRequirement.create({
|
||
|
|
data: { id: uid('req'), roundId: round.id, name: 'Final Business Plan', acceptedMimeTypes: ['application/pdf'], isRequired: true, sortOrder: 1 },
|
||
|
|
})
|
||
|
|
const reqVideo = await prisma.fileRequirement.create({
|
||
|
|
data: { id: uid('req'), roundId: round.id, name: '1-minute Video', acceptedMimeTypes: ['video/*'], isRequired: true, sortOrder: 2 },
|
||
|
|
})
|
||
|
|
return { program, comp, round, reqPlan, reqVideo }
|
||
|
|
}
|
||
|
|
|
||
|
|
describe('getFinalDocumentStatusForProject', () => {
|
||
|
|
afterAll(async () => {
|
||
|
|
for (const id of programIds) await cleanupTestData(id)
|
||
|
|
})
|
||
|
|
|
||
|
|
it('returns null when the project is not enrolled in the active LIVE_FINAL round', async () => {
|
||
|
|
const { program } = await makeFinaleProgram()
|
||
|
|
const orphan = await createTestProject(program.id)
|
||
|
|
const status = await getFinalDocumentStatusForProject(prisma, orphan.id)
|
||
|
|
expect(status).toBeNull()
|
||
|
|
})
|
||
|
|
|
||
|
|
it('returns per-requirement status with none uploaded', async () => {
|
||
|
|
const { program, round } = await makeFinaleProgram()
|
||
|
|
const project = await createTestProject(program.id)
|
||
|
|
await createTestProjectRoundState(project.id, round.id)
|
||
|
|
const status = await getFinalDocumentStatusForProject(prisma, project.id)
|
||
|
|
expect(status).not.toBeNull()
|
||
|
|
expect(status!.requirements).toHaveLength(2)
|
||
|
|
expect(status!.requirements.every((r) => !r.uploaded)).toBe(true)
|
||
|
|
expect(status!.allRequiredUploaded).toBe(false)
|
||
|
|
expect(status!.deadline?.toISOString()).toBe(round.windowCloseAt!.toISOString())
|
||
|
|
})
|
||
|
|
|
||
|
|
it('marks a requirement uploaded and flips allRequiredUploaded when all present', async () => {
|
||
|
|
const { program, round, reqPlan, reqVideo } = await makeFinaleProgram()
|
||
|
|
const project = await createTestProject(program.id)
|
||
|
|
await createTestProjectRoundState(project.id, round.id)
|
||
|
|
for (const [req, type, mime] of [
|
||
|
|
[reqPlan, 'BUSINESS_PLAN', 'application/pdf'],
|
||
|
|
[reqVideo, 'VIDEO', 'video/mp4'],
|
||
|
|
] as const) {
|
||
|
|
await prisma.projectFile.create({
|
||
|
|
data: {
|
||
|
|
id: uid('file'), projectId: project.id, roundId: round.id, requirementId: req.id,
|
||
|
|
fileType: type as any, fileName: `f-${req.id}`, mimeType: mime, size: 10,
|
||
|
|
bucket: 'b', objectKey: uid('key'),
|
||
|
|
},
|
||
|
|
})
|
||
|
|
}
|
||
|
|
const status = await getFinalDocumentStatusForProject(prisma, project.id)
|
||
|
|
expect(status!.requirements.every((r) => r.uploaded)).toBe(true)
|
||
|
|
expect(status!.allRequiredUploaded).toBe(true)
|
||
|
|
})
|
||
|
|
|
||
|
|
it('returns null when the LIVE_FINAL round is not active', async () => {
|
||
|
|
const { program, round } = await makeFinaleProgram({ roundStatus: 'ROUND_DRAFT' })
|
||
|
|
const project = await createTestProject(program.id)
|
||
|
|
await createTestProjectRoundState(project.id, round.id)
|
||
|
|
const status = await getFinalDocumentStatusForProject(prisma, project.id)
|
||
|
|
expect(status).toBeNull()
|
||
|
|
})
|
||
|
|
})
|