Full pipeline/track/stage architecture replacing the legacy round system. Schema: 11 new models (Pipeline, Track, Stage, StageTransition, ProjectStageState, RoutingRule, Cohort, CohortProject, LiveProgressCursor, OverrideAction, AudienceVoter) + 8 new enums. Backend: 9 new routers (pipeline, stage, routing, stageFiltering, stageAssignment, cohort, live, decision, award) + 6 new services (stage-engine, routing-engine, stage-filtering, stage-assignment, stage-notifications, live-control). Frontend: Pipeline wizard (17 components), jury stage pages (7), applicant pipeline pages (3), public stage pages (2), admin pipeline pages (5), shared stage components (3), SSE route, live hook. Phase 6 refit: 23 routers/services migrated from roundId to stageId, all frontend components refitted. Deleted round.ts (985 lines), roundTemplate.ts, round-helpers.ts, round-settings.ts, round-type-settings.tsx, 10 legacy admin pages, 7 legacy jury pages, 3 legacy dialogs. Phase 7 validation: 36 tests (10 unit + 8 integration files) all passing, TypeScript 0 errors, Next.js build succeeds, 13 integrity checks, legacy symbol sweep clean, auto-seed on first Docker startup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
93 lines
2.9 KiB
TypeScript
93 lines
2.9 KiB
TypeScript
/**
|
|
* I-005: Assignment API — Preview vs Execute Parity
|
|
*/
|
|
|
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
|
import { prisma } from '../setup'
|
|
import {
|
|
createTestUser,
|
|
createTestProgram,
|
|
createTestPipeline,
|
|
createTestTrack,
|
|
createTestStage,
|
|
createTestProject,
|
|
createTestPSS,
|
|
cleanupTestData,
|
|
} from '../helpers'
|
|
import { previewStageAssignment, executeStageAssignment } from '@/server/services/stage-assignment'
|
|
|
|
let programId: string
|
|
let userIds: string[] = []
|
|
|
|
beforeAll(async () => {
|
|
const program = await createTestProgram({ name: 'Assignment Preview Test' })
|
|
programId = program.id
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await cleanupTestData(programId, userIds)
|
|
})
|
|
|
|
describe('I-005: Assignment Preview vs Execute Parity', () => {
|
|
it('preview and execute produce matching assignment pairs', async () => {
|
|
const admin = await createTestUser('SUPER_ADMIN')
|
|
userIds.push(admin.id)
|
|
|
|
const pipeline = await createTestPipeline(programId)
|
|
const track = await createTestTrack(pipeline.id)
|
|
const stage = await createTestStage(track.id, {
|
|
name: 'Assignment Stage',
|
|
stageType: 'EVALUATION',
|
|
status: 'STAGE_ACTIVE',
|
|
})
|
|
|
|
// Create 3 jurors
|
|
const juror1 = await createTestUser('JURY_MEMBER', { name: 'Juror Preview 1' })
|
|
const juror2 = await createTestUser('JURY_MEMBER', { name: 'Juror Preview 2' })
|
|
const juror3 = await createTestUser('JURY_MEMBER', { name: 'Juror Preview 3' })
|
|
userIds.push(juror1.id, juror2.id, juror3.id)
|
|
|
|
// Create 2 projects
|
|
const proj1 = await createTestProject(programId, { title: 'Preview P1' })
|
|
const proj2 = await createTestProject(programId, { title: 'Preview P2' })
|
|
await createTestPSS(proj1.id, track.id, stage.id, { state: 'PENDING' })
|
|
await createTestPSS(proj2.id, track.id, stage.id, { state: 'PENDING' })
|
|
|
|
const config = { requiredReviews: 2 }
|
|
|
|
// Step 1: Preview
|
|
const preview = await previewStageAssignment(stage.id, config, prisma)
|
|
|
|
expect(preview.assignments.length).toBeGreaterThan(0)
|
|
expect(preview.stats.totalProjects).toBe(2)
|
|
|
|
// Step 2: Execute with the same pairs from preview
|
|
const assignmentInputs = preview.assignments.map(a => ({
|
|
userId: a.userId,
|
|
projectId: a.projectId,
|
|
}))
|
|
|
|
const execResult = await executeStageAssignment(
|
|
stage.id, assignmentInputs, admin.id, prisma
|
|
)
|
|
|
|
expect(execResult.created).toBe(assignmentInputs.length)
|
|
expect(execResult.errors).toHaveLength(0)
|
|
|
|
// Step 3: Verify all assignments exist in database
|
|
const dbAssignments = await prisma.assignment.findMany({
|
|
where: { stageId: stage.id },
|
|
})
|
|
|
|
expect(dbAssignments.length).toBe(assignmentInputs.length)
|
|
|
|
// Verify each preview pair has a matching DB record
|
|
for (const input of assignmentInputs) {
|
|
const match = dbAssignments.find(
|
|
a => a.userId === input.userId && a.projectId === input.projectId
|
|
)
|
|
expect(match).toBeDefined()
|
|
}
|
|
})
|
|
})
|