feat(finale): per-project presentation/Q&A durations in m:ss + config-save merge fix
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m30s

- setProjectTiming stores per-project overrides in round config; phase starts
  resolve: explicit input > project override > round default
- Run Order rows get m:ss inputs per project; PhaseControls one-off overrides
  now also m:ss (shared parseClock: '7:30', '12:05', plain '7')
- CRITICAL: round.update now MERGES validated form config over the existing
  configJson — saving the Config tab was wiping projectOrder (would have
  destroyed a running ceremony) and the finals-docs upload toggle

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt
2026-06-10 20:14:49 +02:00
parent 9b56eb27fb
commit 2945a92193
8 changed files with 306 additions and 22 deletions

View File

@@ -175,6 +175,58 @@ describe('voting session sync', () => {
})
})
describe('per-project timing overrides', () => {
it('setProjectTiming stores per-project durations in round config', async () => {
await adminCaller.setProjectTiming({
roundId: round.id,
projectId: p1.id,
presentationSeconds: 480,
qaSeconds: 90,
})
const r = await prisma.round.findUniqueOrThrow({ where: { id: round.id } })
const overrides = (r.configJson as any).projectTimingOverrides
expect(overrides[p1.id]).toEqual({ presentationSeconds: 480, qaSeconds: 90 })
})
it('startPresentation/startQA use the project override over the config default', async () => {
await adminCaller.sendToScreens({ roundId: round.id, projectId: p1.id })
const pres = await adminCaller.startPresentation({ roundId: round.id })
expect(pres.phaseDurationSeconds).toBe(480) // override, not the 120s config default
const qa = await adminCaller.startQA({ roundId: round.id })
expect(qa.phaseDurationSeconds).toBe(90)
})
it('an explicit durationSeconds input still wins over the project override', async () => {
await adminCaller.sendToScreens({ roundId: round.id, projectId: p1.id })
const pres = await adminCaller.startPresentation({ roundId: round.id, durationSeconds: 33 })
expect(pres.phaseDurationSeconds).toBe(33)
})
it('projects without an override keep the config default', async () => {
await adminCaller.sendToScreens({ roundId: round.id, projectId: p2.id })
const pres = await adminCaller.startPresentation({ roundId: round.id })
expect(pres.phaseDurationSeconds).toBe(120)
})
it('clearing an override falls back to defaults', async () => {
await adminCaller.setProjectTiming({
roundId: round.id,
projectId: p1.id,
presentationSeconds: null,
qaSeconds: null,
})
await adminCaller.sendToScreens({ roundId: round.id, projectId: p1.id })
const pres = await adminCaller.startPresentation({ roundId: round.id })
expect(pres.phaseDurationSeconds).toBe(120)
})
it('getCursor exposes the overrides for the admin UI', async () => {
await adminCaller.setProjectTiming({ roundId: round.id, projectId: p2.id, qaSeconds: 240 })
const cursor = await adminCaller.getCursor({ roundId: round.id })
expect(cursor?.projectTimingOverrides?.[p2.id]?.qaSeconds).toBe(240)
})
})
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' })

View File

@@ -3,7 +3,7 @@
* derives the same countdown from cursor timestamps — no client-local clocks.
*/
import { describe, it, expect } from 'vitest'
import { elapsedMs, remainingSeconds, formatClock } from '@/lib/live-timer'
import { elapsedMs, remainingSeconds, formatClock, parseClock } from '@/lib/live-timer'
const t0 = new Date('2026-06-11T10:00:00Z')
const at = (s: number) => new Date(t0.getTime() + s * 1000)
@@ -72,4 +72,20 @@ describe('live-timer', () => {
expect(formatClock(0)).toBe('0:00')
expect(formatClock(-83)).toBe('+1:23')
})
it('parseClock accepts m:ss, mm:ss and plain minutes', () => {
expect(parseClock('7:30')).toBe(450)
expect(parseClock('12:05')).toBe(725)
expect(parseClock('0:45')).toBe(45)
expect(parseClock('7')).toBe(420) // plain minutes
expect(parseClock(' 3:00 ')).toBe(180) // tolerant of whitespace
})
it('parseClock rejects garbage', () => {
expect(parseClock('')).toBeNull()
expect(parseClock('abc')).toBeNull()
expect(parseClock('5:75')).toBeNull() // seconds must be 0-59
expect(parseClock('-2:00')).toBeNull()
expect(parseClock('1:2:3')).toBeNull()
})
})

View File

@@ -0,0 +1,58 @@
/**
* Regression: saving the round Config form must NOT wipe operational keys that
* live outside the form schema (ceremony projectOrder, per-project timing
* overrides, finals-docs upload toggle). Found live: a Config save mid-test
* destroyed the running ceremony's run order.
*/
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
import { prisma, createCaller } from '../setup'
import {
createTestUser,
createTestProgram,
createTestCompetition,
createTestRound,
cleanupTestData,
} from '../helpers'
import { roundRouter } from '@/server/routers/round'
let program: any
let round: any
let admin: any
let adminCaller: ReturnType<typeof createCaller>
beforeAll(async () => {
program = await createTestProgram()
const competition = await createTestCompetition(program.id)
round = await createTestRound(competition.id, {
roundType: 'LIVE_FINAL',
status: 'ROUND_ACTIVE',
configJson: {
presentationDurationMinutes: 5,
projectOrder: ['p-one', 'p-two'],
projectTimingOverrides: { 'p-one': { presentationSeconds: 480 } },
allowFinalistRevisedUploads: true,
},
})
admin = await createTestUser('SUPER_ADMIN')
adminCaller = createCaller(roundRouter, admin)
})
afterAll(async () => {
await cleanupTestData(program.id, [admin.id])
})
describe('round.update configJson merge', () => {
it('updates form fields without wiping operational keys', async () => {
await adminCaller.update({
id: round.id,
configJson: { presentationDurationMinutes: 10, qaDurationMinutes: 3 },
})
const updated = await prisma.round.findUniqueOrThrow({ where: { id: round.id } })
const cfg = updated.configJson as Record<string, unknown>
expect(cfg.presentationDurationMinutes).toBe(10) // form field applied
expect(cfg.qaDurationMinutes).toBe(3)
expect(cfg.projectOrder).toEqual(['p-one', 'p-two']) // ceremony state survives
expect((cfg.projectTimingOverrides as any)['p-one'].presentationSeconds).toBe(480)
expect(cfg.allowFinalistRevisedUploads).toBe(true) // finals-docs toggle survives
})
})