teqo/tests/unit/voteGoals.unit.spec.ts
Francisco Ignácio Fontoura Solla cf13c441aa Remodel /campanha around predefined Praças replacing electoral nuclei.
436 seeded Praças (municipality-based; per-TSE-zone in Salvador/Camaçari) become
the operational unit; roles renamed to coordinator/advisor/leader with advisors
scoped to administered Praças. Leadership is one record per person across many
Praças/organizations; vote pledges split leader-declared vs staff-estimated
(estimates never serialized to leaders). Adds organizations, demand workflow
with staff-only cost/receipts, action-plan results with deputy presence, manual
political trend, multi-candidate comparison and the diverging red/white/blue
map mode. Migration 20260721_020109_remodel_plazas deliberately resets the
campaign vertical in production (public site untouched); test suite ported to
the new model (unit 187 / int 306 / e2e 9 green).
2026-07-21 02:28:00 -03:00

54 lines
1.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { plazaStrategyUpdateSchema } from '@/lib/schemas/plaza'
import {
aggregateVoteGoals,
countHighPriorityEntries,
getVoteGoalsOrderViolation,
sumVoteGoals,
voteGoalProgressPercent,
} from '@/utilities/voteGoals'
describe('vote goals schema and aggregates', () => {
it('accepts vote goals and priority on the plaza strategy schema', () => {
const parsed = plazaStrategyUpdateSchema.parse({
plaza: 1,
voteGoals: { good: 1000, regular: 800, minimum: 500 },
priority: 'alta',
})
expect(parsed.voteGoals).toEqual({ good: 1000, regular: 800, minimum: 500 })
expect(parsed.priority).toBe('alta')
})
it('aggregates vote goals and counts high-priority plazas', () => {
const plazas = [
{
voteGoals: { good: 1000, regular: 800, minimum: 500 },
priority: 'alta' as const,
},
{
voteGoals: { good: 200, regular: 150, minimum: 100 },
priority: 'normal' as const,
},
]
expect(aggregateVoteGoals(plazas)).toEqual({
good: 1200,
regular: 950,
minimum: 600,
highPriorityCount: 1,
})
expect(sumVoteGoals(plazas)).toEqual({ good: 1200, regular: 950, minimum: 600 })
expect(countHighPriorityEntries(plazas)).toBe(1)
expect(voteGoalProgressPercent(400, 800)).toBe(50)
expect(voteGoalProgressPercent(null, 800)).toBeNull()
})
it('flags vote goal order violations on sparse inputs', () => {
expect(getVoteGoalsOrderViolation({ good: 100, regular: 200 })).toBe('regular')
expect(getVoteGoalsOrderViolation({ regular: 50, minimum: 100 })).toBe('minimum')
expect(getVoteGoalsOrderViolation({ good: 100, minimum: 200 })).toBe('minimum')
expect(getVoteGoalsOrderViolation({ good: 100, regular: 80 })).toBeNull()
})
})