teqo-backup/tests/unit/plazaStaffVoteTotal.unit.spec.ts
Francisco Ignácio Fontoura Solla b333609726 Deliver A9 plaza expectedVotes and register A9+ follow-up.
Add staff-only expectedVotes with migration, edit flow, and expectedVotes ?? pledge fallback across map, overview, and dashboard; document delivery and the A9+ loader dedup fill-in on the roadmap.
2026-07-21 11:02:11 -03:00

44 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
emptyPlazaPledgeAggregate,
resolvePlazaStaffVoteTotal,
rollupPlazaStaffVotes,
} from '@/utilities/votePledgeData'
describe('resolvePlazaStaffVoteTotal', () => {
it('falls back to pledge effective total when expectedVotes is null', () => {
expect(resolvePlazaStaffVoteTotal(null, 420)).toBe(420)
})
it('uses expectedVotes when set, ignoring pledge aggregate', () => {
expect(resolvePlazaStaffVoteTotal(1500, 420)).toBe(1500)
})
it('returns zero when both expectedVotes and pledges are empty', () => {
expect(resolvePlazaStaffVoteTotal(null, 0)).toBe(0)
})
})
describe('rollupPlazaStaffVotes', () => {
it('sums per-plaza staff totals and pledge metadata', () => {
const aggregates = new Map([
[1, { ...emptyPlazaPledgeAggregate, effectiveTotal: 100, declaredTotal: 80, pledgeCount: 2, missingEstimateCount: 1 }],
[2, { ...emptyPlazaPledgeAggregate, effectiveTotal: 50, declaredTotal: 50, pledgeCount: 1, missingEstimateCount: 0 }],
])
expect(
rollupPlazaStaffVotes(
[
{ id: 1, expectedVotes: null },
{ id: 2, expectedVotes: 200 },
],
aggregates,
),
).toEqual({
staffVoteTotal: 300,
declaredVotesTotal: 130,
pledgeCount: 3,
missingEstimateCount: 1,
})
})
})