teqo/tests/unit/municipalityStaffVoteTotal.unit.spec.ts
Francisco Ignácio Fontoura Solla cf6ae6c47c Pass 2 W2: correcoes de fronteira lib/utilities e client boundary
- helpers puros movidos utilities->lib: slug, phone, wordStartFilter, voteEstimate (9 inversoes lib->utilities zeradas)
- chaves de consent em src/lib/campaignConsentKeys.ts (client-safe); campaignInvite/campaignConsent re-exportam; onda0ConsentTexts referencia as constantes
- 'server-only' em 21 loaders Payload/cache (CLI segue com --conditions=react-server)
- ciclo de tipos supporterListFilters <-> supporterUi quebrado (SupporterListFilterInput estrutural; sqlFilters idem)
- votePledgeData dividido: votePledgeViews (puro, client-safe) + votePledgeData (loaders, server-only) - padrao contract-module
- predicados de role client-safe em src/lib/campaignRoles.ts; access/shared deriva deles (fonte unica); nav.ts para de importar o barrel campaignAccess (casts 'as CampaignUser' eliminados)
2026-07-25 14:38:41 -03:00

59 lines
1.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { createEmptyMunicipalityPledgeAggregate, resolveMunicipalityStaffVoteTotal, rollupMunicipalityStaffVotes } from '@/utilities/votePledgeViews'
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,
})
})
})