teqo/tests/unit/municipalityStaffVoteTotal.unit.spec.ts
Francisco Ignácio Fontoura Solla e2724c10da Remodel the campaign vertical from Praça to Município
Rename the operational unit "Praça"/"Núcleo" to "Município" (code identifier
`municipality`) and land the 2026-07-23 course changes:

- New `candidate` role with unrestricted visibility (`isCampaignStaff` now
  includes it) alongside coordinator/advisor; leader is locked down to the
  supporter contact tool only.
- Demandas become staff-only; dobradinhas modeled via a `stateDeputy` entity.
- Camaçari consolidated to a single município (ZE 170/171 aggregated);
  Salvador keeps its 19 zone municípios.
- Map moves to the staff dashboard; `/campanha/municipios` is list/overview.
- Vote pledges keep the declared vs estimated (scenario) asymmetry; leaders
  never see estimates.

Destructive migration for the campaign vertical (drops nucleus/plaza-era
tables, wipes campaign rows, seeds 435 municípios). Public-site data untouched.

Includes the post-delivery /simplify cleanups: shared reloadStaffActor /
reloadCoordinatorActor helpers, req.context cache for getFreshCampaignUser,
parallelized dashboard loads, candidate dashboard-copy fix, and dead
leader-dashboard / roleKind code removal.
2026-07-23 21:36:20 -03:00

63 lines
1.8 KiB
TypeScript

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