Files
MOPC-Portal/tests/unit/live-vote-comment.test.ts

127 lines
4.3 KiB
TypeScript
Raw Normal View History

/**
* Grand-finale juror voting extras:
* - optional overall comment stored with the LiveVote (and updatable)
* - getSessionForVotingByRound: the jury page only knows the roundId
* - getMyFinaleInputs: a juror's own finale votes + ceremony notes,
* resurfaced during deliberation
*/
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
import { prisma, createCaller } from '../setup'
import {
createTestUser,
createTestProgram,
createTestCompetition,
createTestRound,
createTestProject,
cleanupTestData,
uid,
} from '../helpers'
import { liveVotingRouter } from '@/server/routers/live-voting'
let program: any
let round: any
let emptyRound: any
let session: any
let project: any
let juror: any
let jurorCaller: ReturnType<typeof createCaller>
beforeAll(async () => {
program = await createTestProgram()
const competition = await createTestCompetition(program.id)
const juryGroup = await prisma.juryGroup.create({
data: { competitionId: competition.id, name: 'Finals Jury', slug: uid('jg') },
})
round = await createTestRound(competition.id, {
roundType: 'LIVE_FINAL',
status: 'ROUND_ACTIVE',
})
await prisma.round.update({ where: { id: round.id }, data: { juryGroupId: juryGroup.id } })
emptyRound = await createTestRound(competition.id, { roundType: 'LIVE_FINAL', sortOrder: 1 })
project = await createTestProject(program.id, { competitionCategory: 'STARTUP' })
juror = await createTestUser('JURY_MEMBER')
await prisma.juryGroupMember.create({
data: { juryGroupId: juryGroup.id, userId: juror.id, role: 'MEMBER' },
})
session = await prisma.liveVotingSession.create({
data: {
roundId: round.id,
status: 'IN_PROGRESS',
currentProjectId: project.id,
votingMode: 'simple',
},
})
jurorCaller = createCaller(liveVotingRouter, juror)
})
afterAll(async () => {
await cleanupTestData(program.id, [juror.id])
})
describe('vote comments', () => {
it('persists an optional comment with the vote', async () => {
const vote = await jurorCaller.vote({
sessionId: session.id,
projectId: project.id,
score: 8,
comment: 'Strong pitch, weak unit economics',
})
expect(vote.comment).toBe('Strong pitch, weak unit economics')
})
it('re-voting updates the comment and keeps it when omitted', async () => {
const updated = await jurorCaller.vote({
sessionId: session.id,
projectId: project.id,
score: 9,
comment: 'Revised after Q&A',
})
expect(updated.score).toBe(9)
expect(updated.comment).toBe('Revised after Q&A')
const again = await jurorCaller.vote({
sessionId: session.id,
projectId: project.id,
score: 7,
})
expect(again.comment).toBe('Revised after Q&A') // omitted comment is not erased
})
})
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)
})
it('returns null when the round has no session (creates nothing)', async () => {
const data = await jurorCaller.getSessionForVotingByRound({ roundId: emptyRound.id })
expect(data).toBeNull()
const count = await prisma.liveVotingSession.count({ where: { roundId: emptyRound.id } })
expect(count).toBe(0)
})
})
describe('getMyFinaleInputs', () => {
it('returns the callers votes and notes for the round', async () => {
await prisma.liveNote.create({
data: { roundId: round.id, projectId: project.id, userId: juror.id, content: 'ceremony note' },
})
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.notes).toHaveLength(1)
expect(inputs.notes[0].content).toBe('ceremony note')
})
it('is empty-safe for a round without a session', async () => {
const inputs = await jurorCaller.getMyFinaleInputs({ roundId: emptyRound.id })
expect(inputs.session).toBeNull()
expect(inputs.votes).toHaveLength(0)
})
})