feat(finale): deliberation jury identity resolution, rankable projects, score-revision path, session sync
- submitVote resolves the caller's JuryGroupMember participant row server-side (was comparing JuryGroupMember id to User id — every juror got FORBIDDEN) - getSessionWithVotes now includes category projects so the ranking form has data before finalize - liveVoting.vote accepts any finale-ordered project (revision during deliberation); timed window still applies to the live project - live.sendToScreens keeps LiveVotingSession.currentProjectId/status in sync Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
113
tests/unit/deliberation-jury-wiring.test.ts
Normal file
113
tests/unit/deliberation-jury-wiring.test.ts
Normal file
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* Deliberation jury wiring — regression for two launch blockers:
|
||||
* 1. submitVote compared the JuryGroupMember id against User.id (FORBIDDEN for
|
||||
* every legitimate juror). The server now resolves the caller's participant
|
||||
* row itself; the client never sends an identity.
|
||||
* 2. getSession had no project list before finalize (the ranking form rendered
|
||||
* empty). It now includes the round's projects filtered by session category.
|
||||
*/
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
||||
import { prisma, createCaller } from '../setup'
|
||||
import {
|
||||
createTestUser,
|
||||
createTestProgram,
|
||||
createTestCompetition,
|
||||
createTestRound,
|
||||
createTestProject,
|
||||
createTestProjectRoundState,
|
||||
cleanupTestData,
|
||||
uid,
|
||||
} from '../helpers'
|
||||
import { deliberationRouter } from '@/server/routers/deliberation'
|
||||
|
||||
let program: any
|
||||
let competition: any
|
||||
let delibRound: any
|
||||
let startup1: any
|
||||
let startup2: any
|
||||
let concept1: any
|
||||
let juror: any
|
||||
let outsiderJuror: any
|
||||
let admin: any
|
||||
let sessionId: string
|
||||
let adminCaller: ReturnType<typeof createCaller>
|
||||
let jurorCaller: ReturnType<typeof createCaller>
|
||||
|
||||
beforeAll(async () => {
|
||||
program = await createTestProgram()
|
||||
competition = await createTestCompetition(program.id)
|
||||
delibRound = await createTestRound(competition.id, {
|
||||
roundType: 'DELIBERATION',
|
||||
status: 'ROUND_ACTIVE',
|
||||
})
|
||||
startup1 = await createTestProject(program.id, { competitionCategory: 'STARTUP' })
|
||||
startup2 = await createTestProject(program.id, { competitionCategory: 'STARTUP' })
|
||||
concept1 = await createTestProject(program.id, { competitionCategory: 'BUSINESS_CONCEPT' })
|
||||
await createTestProjectRoundState(startup1.id, delibRound.id)
|
||||
await createTestProjectRoundState(startup2.id, delibRound.id)
|
||||
await createTestProjectRoundState(concept1.id, delibRound.id)
|
||||
|
||||
const juryGroup = await prisma.juryGroup.create({
|
||||
data: { competitionId: competition.id, name: 'Finals Jury', slug: uid('jg') },
|
||||
})
|
||||
juror = await createTestUser('JURY_MEMBER')
|
||||
outsiderJuror = await createTestUser('JURY_MEMBER')
|
||||
admin = await createTestUser('SUPER_ADMIN')
|
||||
const member = await prisma.juryGroupMember.create({
|
||||
data: { juryGroupId: juryGroup.id, userId: juror.id, role: 'MEMBER' },
|
||||
})
|
||||
|
||||
adminCaller = createCaller(deliberationRouter, admin)
|
||||
jurorCaller = createCaller(deliberationRouter, juror)
|
||||
|
||||
const session = await adminCaller.createSession({
|
||||
competitionId: competition.id,
|
||||
roundId: delibRound.id,
|
||||
category: 'STARTUP',
|
||||
mode: 'FULL_RANKING',
|
||||
tieBreakMethod: 'TIE_ADMIN_DECIDES',
|
||||
participantUserIds: [member.id], // JuryGroupMember IDs
|
||||
})
|
||||
sessionId = session.id
|
||||
await adminCaller.openVoting({ sessionId })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await cleanupTestData(program.id, [juror.id, outsiderJuror.id, admin.id])
|
||||
})
|
||||
|
||||
describe('getSession projects', () => {
|
||||
it('exposes the category projects before any results exist', async () => {
|
||||
const session = await jurorCaller.getSession({ sessionId })
|
||||
const ids = (session.projects ?? []).map((p: any) => p.id).sort()
|
||||
expect(ids).toEqual([startup1.id, startup2.id].sort())
|
||||
// off-category project excluded
|
||||
expect(ids).not.toContain(concept1.id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('submitVote identity resolution', () => {
|
||||
it('lets a participant juror vote without sending any identity', async () => {
|
||||
await jurorCaller.submitVote({ sessionId, projectId: startup1.id, rank: 1 })
|
||||
await jurorCaller.submitVote({ sessionId, projectId: startup2.id, rank: 2 })
|
||||
|
||||
const session = await jurorCaller.getSession({ sessionId })
|
||||
const myVotes = (session.votes ?? []).filter(
|
||||
(v: any) => v.juryMember?.user?.id === juror.id
|
||||
)
|
||||
expect(myVotes).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('rejects a juror who is not a participant', async () => {
|
||||
const outsiderCaller = createCaller(deliberationRouter, outsiderJuror)
|
||||
await expect(
|
||||
outsiderCaller.submitVote({ sessionId, projectId: startup1.id, rank: 1 })
|
||||
).rejects.toThrow(/participant/i)
|
||||
})
|
||||
|
||||
it('aggregates the resolved votes (sanity end-to-end)', async () => {
|
||||
const agg = await adminCaller.aggregate({ sessionId })
|
||||
expect(agg.rankings.length).toBeGreaterThan(0)
|
||||
expect(agg.rankings[0].projectId).toBe(startup1.id) // rank 1 → top Borda points
|
||||
})
|
||||
})
|
||||
@@ -148,6 +148,20 @@ describe('phase transitions', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('voting session sync', () => {
|
||||
it('sendToScreens points the voting session at the project and activates it', async () => {
|
||||
const session = await prisma.liveVotingSession.create({
|
||||
data: { roundId: round.id, status: 'NOT_STARTED' },
|
||||
})
|
||||
await adminCaller.sendToScreens({ roundId: round.id, projectId: p1.id })
|
||||
const updated = await prisma.liveVotingSession.findUniqueOrThrow({
|
||||
where: { id: session.id },
|
||||
})
|
||||
expect(updated.currentProjectId).toBe(p1.id)
|
||||
expect(updated.status).toBe('IN_PROGRESS')
|
||||
})
|
||||
})
|
||||
|
||||
describe('juror notes', () => {
|
||||
it('saveNote upserts one note per (round, project, juror)', async () => {
|
||||
await jurorCaller.saveNote({ roundId: round.id, projectId: p1.id, content: 'first draft' })
|
||||
|
||||
@@ -88,12 +88,56 @@ describe('vote comments', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('deliberation-time revision', () => {
|
||||
it('allows voting for an ordered project that is not currently presenting', async () => {
|
||||
const otherProject = await createTestProject(program.id, {
|
||||
competitionCategory: 'BUSINESS_CONCEPT',
|
||||
})
|
||||
await prisma.round.update({
|
||||
where: { id: round.id },
|
||||
data: { configJson: { projectOrder: [project.id, otherProject.id] } },
|
||||
})
|
||||
// otherProject is NOT currentProjectId — revision path must accept it
|
||||
const vote = await jurorCaller.vote({
|
||||
sessionId: session.id,
|
||||
projectId: otherProject.id,
|
||||
score: 6,
|
||||
comment: 'revised during deliberation',
|
||||
})
|
||||
expect(vote.projectId).toBe(otherProject.id)
|
||||
})
|
||||
|
||||
it('still rejects projects outside the finale order', async () => {
|
||||
const stranger = await createTestProject(program.id)
|
||||
await expect(
|
||||
jurorCaller.vote({ sessionId: session.id, projectId: stranger.id, score: 5 })
|
||||
).rejects.toThrow()
|
||||
})
|
||||
|
||||
it('allows revision while the session is PAUSED', async () => {
|
||||
await prisma.liveVotingSession.update({
|
||||
where: { id: session.id },
|
||||
data: { status: 'PAUSED' },
|
||||
})
|
||||
const vote = await jurorCaller.vote({
|
||||
sessionId: session.id,
|
||||
projectId: project.id,
|
||||
score: 10,
|
||||
})
|
||||
expect(vote.score).toBe(10)
|
||||
await prisma.liveVotingSession.update({
|
||||
where: { id: session.id },
|
||||
data: { status: 'IN_PROGRESS' },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getSessionForVotingByRound', () => {
|
||||
it('resolves the session from a roundId', async () => {
|
||||
const data = await jurorCaller.getSessionForVotingByRound({ roundId: round.id })
|
||||
expect(data?.session.id).toBe(session.id)
|
||||
expect(data?.currentProject?.id).toBe(project.id)
|
||||
expect(data?.userVote?.score).toBe(7)
|
||||
expect(data?.userVote?.score).toBe(10) // last revision in the PAUSED test
|
||||
})
|
||||
|
||||
it('returns null when the round has no session (creates nothing)', async () => {
|
||||
@@ -111,9 +155,9 @@ describe('getMyFinaleInputs', () => {
|
||||
})
|
||||
const inputs = await jurorCaller.getMyFinaleInputs({ roundId: round.id })
|
||||
expect(inputs.session?.id).toBe(session.id)
|
||||
expect(inputs.votes).toHaveLength(1)
|
||||
expect(inputs.votes[0].projectId).toBe(project.id)
|
||||
expect(inputs.votes[0].comment).toBe('Revised after Q&A')
|
||||
expect(inputs.votes).toHaveLength(2) // original + deliberation-time revision
|
||||
const mainVote = inputs.votes.find((v: any) => v.projectId === project.id)
|
||||
expect(mainVote?.comment).toBe('Revised after Q&A')
|
||||
expect(inputs.notes).toHaveLength(1)
|
||||
expect(inputs.notes[0].content).toBe('ceremony note')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user