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
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:
@@ -7,7 +7,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
|||||||
import { Badge } from '@/components/ui/badge'
|
import { Badge } from '@/components/ui/badge'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { remainingSeconds, formatClock } from '@/lib/live-timer'
|
import { remainingSeconds, formatClock, parseClock } from '@/lib/live-timer'
|
||||||
import {
|
import {
|
||||||
Mic2,
|
Mic2,
|
||||||
MessageCircleQuestion,
|
MessageCircleQuestion,
|
||||||
@@ -65,10 +65,7 @@ export function PhaseControls({ roundId }: { roundId: string }) {
|
|||||||
openScoring.isPending ||
|
openScoring.isPending ||
|
||||||
sendToScreens.isPending
|
sendToScreens.isPending
|
||||||
|
|
||||||
const durationSeconds = (raw: string) => {
|
const durationSeconds = (raw: string) => parseClock(raw) ?? undefined
|
||||||
const min = parseFloat(raw)
|
|
||||||
return Number.isFinite(min) && min > 0 ? Math.round(min * 60) : undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextProject = (() => {
|
const nextProject = (() => {
|
||||||
const order = cursor.orderedProjects ?? []
|
const order = cursor.orderedProjects ?? []
|
||||||
@@ -197,26 +194,23 @@ export function PhaseControls({ roundId }: { roundId: string }) {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Duration overrides for the NEXT start */}
|
{/* One-off duration overrides for the NEXT start only (m:ss).
|
||||||
|
Per-project durations live in the Run Order list. */}
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label className="text-xs">Presentation (min, override)</Label>
|
<Label className="text-xs">Presentation override (m:ss, next start only)</Label>
|
||||||
<Input
|
<Input
|
||||||
type="number"
|
placeholder="e.g. 7:30"
|
||||||
min="0.5"
|
className="tabular-nums"
|
||||||
step="0.5"
|
|
||||||
placeholder="config default"
|
|
||||||
value={presentationMin}
|
value={presentationMin}
|
||||||
onChange={(e) => setPresentationMin(e.target.value)}
|
onChange={(e) => setPresentationMin(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label className="text-xs">Q&A (min, override)</Label>
|
<Label className="text-xs">Q&A override (m:ss, next start only)</Label>
|
||||||
<Input
|
<Input
|
||||||
type="number"
|
placeholder="e.g. 2:00"
|
||||||
min="0.5"
|
className="tabular-nums"
|
||||||
step="0.5"
|
|
||||||
placeholder="config default"
|
|
||||||
value={qaMin}
|
value={qaMin}
|
||||||
onChange={(e) => setQaMin(e.target.value)}
|
onChange={(e) => setQaMin(e.target.value)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
import { trpc } from '@/lib/trpc/client'
|
import { trpc } from '@/lib/trpc/client'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import { Badge } from '@/components/ui/badge'
|
import { Badge } from '@/components/ui/badge'
|
||||||
import { ArrowDown, ArrowUp, MonitorUp } from 'lucide-react'
|
import { Input } from '@/components/ui/input'
|
||||||
|
import { ArrowDown, ArrowUp, MonitorUp, Timer } from 'lucide-react'
|
||||||
|
import { formatClock, parseClock } from '@/lib/live-timer'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
|
|
||||||
const CATEGORY_LABEL: Record<string, string> = {
|
const CATEGORY_LABEL: Record<string, string> = {
|
||||||
@@ -20,11 +23,32 @@ const CATEGORY_LABEL: Record<string, string> = {
|
|||||||
export function RunOrderList({ roundId }: { roundId: string }) {
|
export function RunOrderList({ roundId }: { roundId: string }) {
|
||||||
const utils = trpc.useUtils()
|
const utils = trpc.useUtils()
|
||||||
const { data: cursor } = trpc.live.getCursor.useQuery({ roundId }, { refetchInterval: 5000 })
|
const { data: cursor } = trpc.live.getCursor.useQuery({ roundId }, { refetchInterval: 5000 })
|
||||||
|
// Local drafts for the per-project minute inputs (committed on blur)
|
||||||
|
const [timingDrafts, setTimingDrafts] = useState<Record<string, string>>({})
|
||||||
|
|
||||||
const reorderMutation = trpc.live.reorder.useMutation({
|
const reorderMutation = trpc.live.reorder.useMutation({
|
||||||
onSuccess: () => utils.live.getCursor.invalidate({ roundId }),
|
onSuccess: () => utils.live.getCursor.invalidate({ roundId }),
|
||||||
onError: (err) => toast.error(err.message),
|
onError: (err) => toast.error(err.message),
|
||||||
})
|
})
|
||||||
|
const timingMutation = trpc.live.setProjectTiming.useMutation({
|
||||||
|
onSuccess: () => {
|
||||||
|
utils.live.getCursor.invalidate({ roundId })
|
||||||
|
toast.success('Project timing saved')
|
||||||
|
},
|
||||||
|
onError: (err) => toast.error(err.message),
|
||||||
|
})
|
||||||
|
|
||||||
|
const commitTiming = (projectId: string, field: 'presentationSeconds' | 'qaSeconds', raw: string) => {
|
||||||
|
const trimmed = raw.trim()
|
||||||
|
const seconds = trimmed === '' ? null : parseClock(trimmed)
|
||||||
|
if (trimmed !== '' && seconds === null) {
|
||||||
|
toast.error('Use minutes:seconds, e.g. 7:30')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const current = cursor?.projectTimingOverrides?.[projectId]?.[field] ?? null
|
||||||
|
if (seconds === current) return
|
||||||
|
timingMutation.mutate({ roundId, projectId, [field]: seconds })
|
||||||
|
}
|
||||||
const sendMutation = trpc.live.sendToScreens.useMutation({
|
const sendMutation = trpc.live.sendToScreens.useMutation({
|
||||||
onSuccess: (_d, vars) => {
|
onSuccess: (_d, vars) => {
|
||||||
utils.live.getCursor.invalidate({ roundId })
|
utils.live.getCursor.invalidate({ roundId })
|
||||||
@@ -81,6 +105,9 @@ export function RunOrderList({ roundId }: { roundId: string }) {
|
|||||||
}
|
}
|
||||||
const project = projects[row.index]
|
const project = projects[row.index]
|
||||||
const isActive = project.id === cursor.activeProjectId
|
const isActive = project.id === cursor.activeProjectId
|
||||||
|
const override = cursor.projectTimingOverrides?.[project.id]
|
||||||
|
const presKey = `${project.id}:pres`
|
||||||
|
const qaKey = `${project.id}:qa`
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={project.id}
|
key={project.id}
|
||||||
@@ -96,6 +123,57 @@ export function RunOrderList({ roundId }: { roundId: string }) {
|
|||||||
{project.teamName && (
|
{project.teamName && (
|
||||||
<p className="truncate text-xs text-muted-foreground">{project.teamName}</p>
|
<p className="truncate text-xs text-muted-foreground">{project.teamName}</p>
|
||||||
)}
|
)}
|
||||||
|
{/* Per-project durations (m:ss) — empty = round default */}
|
||||||
|
<div className="mt-1 flex items-center gap-2">
|
||||||
|
<Timer className="h-3 w-3 shrink-0 text-muted-foreground" />
|
||||||
|
<label className="flex items-center gap-1 text-[11px] text-muted-foreground">
|
||||||
|
Pres
|
||||||
|
<Input
|
||||||
|
className="h-6 w-16 px-1.5 text-center text-xs tabular-nums"
|
||||||
|
placeholder="default"
|
||||||
|
value={
|
||||||
|
timingDrafts[presKey] ??
|
||||||
|
(override?.presentationSeconds != null
|
||||||
|
? formatClock(override.presentationSeconds)
|
||||||
|
: '')
|
||||||
|
}
|
||||||
|
onChange={(e) =>
|
||||||
|
setTimingDrafts((d) => ({ ...d, [presKey]: e.target.value }))
|
||||||
|
}
|
||||||
|
onBlur={(e) => {
|
||||||
|
commitTiming(project.id, 'presentationSeconds', e.target.value)
|
||||||
|
setTimingDrafts((d) => {
|
||||||
|
const next = { ...d }
|
||||||
|
delete next[presKey]
|
||||||
|
return next
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="flex items-center gap-1 text-[11px] text-muted-foreground">
|
||||||
|
Q&A
|
||||||
|
<Input
|
||||||
|
className="h-6 w-16 px-1.5 text-center text-xs tabular-nums"
|
||||||
|
placeholder="default"
|
||||||
|
value={
|
||||||
|
timingDrafts[qaKey] ??
|
||||||
|
(override?.qaSeconds != null ? formatClock(override.qaSeconds) : '')
|
||||||
|
}
|
||||||
|
onChange={(e) =>
|
||||||
|
setTimingDrafts((d) => ({ ...d, [qaKey]: e.target.value }))
|
||||||
|
}
|
||||||
|
onBlur={(e) => {
|
||||||
|
commitTiming(project.id, 'qaSeconds', e.target.value)
|
||||||
|
setTimingDrafts((d) => {
|
||||||
|
const next = { ...d }
|
||||||
|
delete next[qaKey]
|
||||||
|
return next
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<span className="text-[10px] text-muted-foreground/70">m:ss</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{isActive && (
|
{isActive && (
|
||||||
<Badge className="shrink-0 bg-[#de0f1e] hover:bg-[#de0f1e]">
|
<Badge className="shrink-0 bg-[#de0f1e] hover:bg-[#de0f1e]">
|
||||||
|
|||||||
@@ -34,3 +34,21 @@ export function formatClock(seconds: number): string {
|
|||||||
const s = abs % 60
|
const s = abs % 60
|
||||||
return `${over ? '+' : ''}${m}:${s.toString().padStart(2, '0')}`
|
return `${over ? '+' : ''}${m}:${s.toString().padStart(2, '0')}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse an admin duration input: `m:ss` / `mm:ss`, or plain minutes (`7`).
|
||||||
|
* Returns total seconds, or null for anything unparseable.
|
||||||
|
*/
|
||||||
|
export function parseClock(input: string): number | null {
|
||||||
|
const trimmed = input.trim()
|
||||||
|
if (!trimmed) return null
|
||||||
|
const colonMatch = /^(\d{1,3}):([0-5]\d)$/.exec(trimmed)
|
||||||
|
if (colonMatch) {
|
||||||
|
return parseInt(colonMatch[1], 10) * 60 + parseInt(colonMatch[2], 10)
|
||||||
|
}
|
||||||
|
const plainMatch = /^(\d{1,3})$/.exec(trimmed)
|
||||||
|
if (plainMatch) {
|
||||||
|
return parseInt(plainMatch[1], 10) * 60
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ function closedOutTiming(cursor: LiveProgressCursor, now: Date): Prisma.InputJso
|
|||||||
return [...log, entry] as unknown as Prisma.InputJsonValue
|
return [...log, entry] as unknown as Prisma.InputJsonValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProjectTimingOverride = { presentationSeconds?: number; qaSeconds?: number }
|
||||||
|
|
||||||
async function getRoundCeremonyConfig(prisma: PrismaClient, roundId: string) {
|
async function getRoundCeremonyConfig(prisma: PrismaClient, roundId: string) {
|
||||||
const round = await prisma.round.findUniqueOrThrow({ where: { id: roundId } })
|
const round = await prisma.round.findUniqueOrThrow({ where: { id: roundId } })
|
||||||
const cfg = (round.configJson as Record<string, unknown>) ?? {}
|
const cfg = (round.configJson as Record<string, unknown>) ?? {}
|
||||||
@@ -55,6 +57,7 @@ async function getRoundCeremonyConfig(prisma: PrismaClient, roundId: string) {
|
|||||||
: 300,
|
: 300,
|
||||||
qaSeconds: typeof cfg.qaDurationMinutes === 'number' ? cfg.qaDurationMinutes * 60 : 300,
|
qaSeconds: typeof cfg.qaDurationMinutes === 'number' ? cfg.qaDurationMinutes * 60 : 300,
|
||||||
projectOrder: (cfg.projectOrder as string[]) ?? [],
|
projectOrder: (cfg.projectOrder as string[]) ?? [],
|
||||||
|
timingOverrides: (cfg.projectTimingOverrides as Record<string, ProjectTimingOverride>) ?? {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,13 +481,15 @@ export const liveRouter = router({
|
|||||||
throw new TRPCError({ code: 'PRECONDITION_FAILED', message: 'No project is on screen' })
|
throw new TRPCError({ code: 'PRECONDITION_FAILED', message: 'No project is on screen' })
|
||||||
}
|
}
|
||||||
const cfg = await getRoundCeremonyConfig(ctx.prisma, input.roundId)
|
const cfg = await getRoundCeremonyConfig(ctx.prisma, input.roundId)
|
||||||
|
const projectOverride = cfg.timingOverrides[cursor.activeProjectId]
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const updated = await ctx.prisma.liveProgressCursor.update({
|
const updated = await ctx.prisma.liveProgressCursor.update({
|
||||||
where: { id: cursor.id },
|
where: { id: cursor.id },
|
||||||
data: {
|
data: {
|
||||||
projectPhase: 'PRESENTING',
|
projectPhase: 'PRESENTING',
|
||||||
phaseStartedAt: now,
|
phaseStartedAt: now,
|
||||||
phaseDurationSeconds: input.durationSeconds ?? cfg.presentationSeconds,
|
phaseDurationSeconds:
|
||||||
|
input.durationSeconds ?? projectOverride?.presentationSeconds ?? cfg.presentationSeconds,
|
||||||
phasePausedAt: null,
|
phasePausedAt: null,
|
||||||
phasePausedAccumMs: 0,
|
phasePausedAccumMs: 0,
|
||||||
...(closedOutTiming(cursor, now) !== undefined
|
...(closedOutTiming(cursor, now) !== undefined
|
||||||
@@ -528,13 +533,14 @@ export const liveRouter = router({
|
|||||||
throw new TRPCError({ code: 'PRECONDITION_FAILED', message: 'No project is on screen' })
|
throw new TRPCError({ code: 'PRECONDITION_FAILED', message: 'No project is on screen' })
|
||||||
}
|
}
|
||||||
const cfg = await getRoundCeremonyConfig(ctx.prisma, input.roundId)
|
const cfg = await getRoundCeremonyConfig(ctx.prisma, input.roundId)
|
||||||
|
const projectOverride = cfg.timingOverrides[cursor.activeProjectId]
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const updated = await ctx.prisma.liveProgressCursor.update({
|
const updated = await ctx.prisma.liveProgressCursor.update({
|
||||||
where: { id: cursor.id },
|
where: { id: cursor.id },
|
||||||
data: {
|
data: {
|
||||||
projectPhase: 'QA',
|
projectPhase: 'QA',
|
||||||
phaseStartedAt: now,
|
phaseStartedAt: now,
|
||||||
phaseDurationSeconds: input.durationSeconds ?? cfg.qaSeconds,
|
phaseDurationSeconds: input.durationSeconds ?? projectOverride?.qaSeconds ?? cfg.qaSeconds,
|
||||||
phasePausedAt: null,
|
phasePausedAt: null,
|
||||||
phasePausedAccumMs: 0,
|
phasePausedAccumMs: 0,
|
||||||
...(closedOutTiming(cursor, now) !== undefined
|
...(closedOutTiming(cursor, now) !== undefined
|
||||||
@@ -657,6 +663,59 @@ export const liveRouter = router({
|
|||||||
return updated
|
return updated
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-project presentation/Q&A durations. Precedence at phase start:
|
||||||
|
* explicit durationSeconds input > this override > round config default.
|
||||||
|
* Passing null clears a field.
|
||||||
|
*/
|
||||||
|
setProjectTiming: adminProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
roundId: z.string(),
|
||||||
|
projectId: z.string(),
|
||||||
|
presentationSeconds: z.number().int().min(10).max(7200).nullable().optional(),
|
||||||
|
qaSeconds: z.number().int().min(10).max(7200).nullable().optional(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const round = await ctx.prisma.round.findUniqueOrThrow({
|
||||||
|
where: { id: input.roundId },
|
||||||
|
})
|
||||||
|
const cfg = ((round.configJson as Record<string, unknown>) ?? {}) as Record<string, unknown>
|
||||||
|
const overrides = { ...((cfg.projectTimingOverrides as Record<string, ProjectTimingOverride>) ?? {}) }
|
||||||
|
const entry: ProjectTimingOverride = { ...(overrides[input.projectId] ?? {}) }
|
||||||
|
|
||||||
|
if (input.presentationSeconds !== undefined) {
|
||||||
|
if (input.presentationSeconds === null) delete entry.presentationSeconds
|
||||||
|
else entry.presentationSeconds = input.presentationSeconds
|
||||||
|
}
|
||||||
|
if (input.qaSeconds !== undefined) {
|
||||||
|
if (input.qaSeconds === null) delete entry.qaSeconds
|
||||||
|
else entry.qaSeconds = input.qaSeconds
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(entry).length === 0) delete overrides[input.projectId]
|
||||||
|
else overrides[input.projectId] = entry
|
||||||
|
|
||||||
|
await ctx.prisma.round.update({
|
||||||
|
where: { id: input.roundId },
|
||||||
|
data: {
|
||||||
|
configJson: { ...cfg, projectTimingOverrides: overrides } as Prisma.InputJsonValue,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await logAudit({
|
||||||
|
prisma: ctx.prisma,
|
||||||
|
userId: ctx.user.id,
|
||||||
|
action: 'LIVE_PROJECT_TIMING_SET',
|
||||||
|
entityType: 'Round',
|
||||||
|
entityId: input.roundId,
|
||||||
|
detailsJson: { projectId: input.projectId, ...entry },
|
||||||
|
ipAddress: ctx.ip,
|
||||||
|
userAgent: ctx.userAgent,
|
||||||
|
})
|
||||||
|
return { projectId: input.projectId, ...entry }
|
||||||
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force a static slide on the big screen (or clear it).
|
* Force a static slide on the big screen (or clear it).
|
||||||
*/
|
*/
|
||||||
@@ -817,6 +876,8 @@ export const liveRouter = router({
|
|||||||
activeProject,
|
activeProject,
|
||||||
projectOrder,
|
projectOrder,
|
||||||
orderedProjects,
|
orderedProjects,
|
||||||
|
projectTimingOverrides:
|
||||||
|
((config.projectTimingOverrides as Record<string, { presentationSeconds?: number; qaSeconds?: number }>) ?? {}),
|
||||||
totalProjects: projectOrder.length,
|
totalProjects: projectOrder.length,
|
||||||
openCohorts,
|
openCohorts,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,11 +159,18 @@ export const roundRouter = router({
|
|||||||
|
|
||||||
const existing = await ctx.prisma.round.findUniqueOrThrow({ where: { id } })
|
const existing = await ctx.prisma.round.findUniqueOrThrow({ where: { id } })
|
||||||
|
|
||||||
// If configJson provided, validate it against the round type
|
// If configJson provided, validate it against the round type, then MERGE
|
||||||
|
// over the existing config: the validator strips keys it doesn't know,
|
||||||
|
// but configJson also carries operational state written outside this
|
||||||
|
// form (ceremony projectOrder, projectTimingOverrides, finals-docs
|
||||||
|
// upload toggle). Replacing wholesale would wipe a running ceremony.
|
||||||
let validatedConfig: Prisma.InputJsonValue | undefined
|
let validatedConfig: Prisma.InputJsonValue | undefined
|
||||||
if (configJson) {
|
if (configJson) {
|
||||||
const parsed = validateRoundConfig(existing.roundType, configJson)
|
const parsed = validateRoundConfig(existing.roundType, configJson)
|
||||||
validatedConfig = parsed as unknown as Prisma.InputJsonValue
|
validatedConfig = {
|
||||||
|
...((existing.configJson as Record<string, unknown>) ?? {}),
|
||||||
|
...(parsed as Record<string, unknown>),
|
||||||
|
} as unknown as Prisma.InputJsonValue
|
||||||
}
|
}
|
||||||
|
|
||||||
const round = await ctx.prisma.round.update({
|
const round = await ctx.prisma.round.update({
|
||||||
|
|||||||
@@ -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', () => {
|
describe('juror notes', () => {
|
||||||
it('saveNote upserts one note per (round, project, juror)', async () => {
|
it('saveNote upserts one note per (round, project, juror)', async () => {
|
||||||
await jurorCaller.saveNote({ roundId: round.id, projectId: p1.id, content: 'first draft' })
|
await jurorCaller.saveNote({ roundId: round.id, projectId: p1.id, content: 'first draft' })
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* derives the same countdown from cursor timestamps — no client-local clocks.
|
* derives the same countdown from cursor timestamps — no client-local clocks.
|
||||||
*/
|
*/
|
||||||
import { describe, it, expect } from 'vitest'
|
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 t0 = new Date('2026-06-11T10:00:00Z')
|
||||||
const at = (s: number) => new Date(t0.getTime() + s * 1000)
|
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(0)).toBe('0:00')
|
||||||
expect(formatClock(-83)).toBe('+1:23')
|
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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
58
tests/unit/round-config-merge.test.ts
Normal file
58
tests/unit/round-config-merge.test.ts
Normal 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
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user