mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-16 03:03:06 +00:00
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.
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
// @vitest-environment node
|
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const phoneMocks = vi.hoisted(() => ({
|
|
normalizeBrazilianPhone: vi.fn<(value: string) => string | null>(),
|
|
}))
|
|
|
|
vi.mock('@/utilities/phone', async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import('@/utilities/phone')>()
|
|
phoneMocks.normalizeBrazilianPhone.mockImplementation(actual.normalizeBrazilianPhone)
|
|
|
|
return {
|
|
...actual,
|
|
normalizeBrazilianPhone: phoneMocks.normalizeBrazilianPhone,
|
|
}
|
|
})
|
|
|
|
import { Contact } from '@/collections/Contact'
|
|
import { leadershipCreateSchema } from '@/lib/schemas/leadership'
|
|
|
|
const contactPhoneHook = Contact.hooks?.beforeValidate?.[0]
|
|
|
|
const runContactPhoneHook = async (phone: string) => {
|
|
if (typeof contactPhoneHook !== 'function') {
|
|
throw new Error('Expected Contact.beforeValidate phone hook.')
|
|
}
|
|
|
|
const data = { phone }
|
|
await contactPhoneHook({ data } as never)
|
|
return data.phone
|
|
}
|
|
|
|
describe('Contact phone normalization boundary', () => {
|
|
beforeEach(() => {
|
|
phoneMocks.normalizeBrazilianPhone.mockClear()
|
|
})
|
|
|
|
it('normalizes once before leadership dedupe and skips canonical Contact input', async () => {
|
|
const parsed = leadershipCreateSchema.parse({
|
|
municipalities: [1],
|
|
name: 'Liderança normalizada',
|
|
phone: '+55 (71) 99999-1234',
|
|
})
|
|
|
|
expect(parsed.phone).toBe('71999991234')
|
|
expect(await runContactPhoneHook(parsed.phone)).toBe('71999991234')
|
|
expect(phoneMocks.normalizeBrazilianPhone).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('normalizes a formatted phone sent directly to the Contact API boundary', async () => {
|
|
expect(await runContactPhoneHook('+55 (71) 99999-1234')).toBe('71999991234')
|
|
expect(phoneMocks.normalizeBrazilianPhone).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('rejects an invalid canonical-length direct API phone without re-normalizing it', async () => {
|
|
await expect(runContactPhoneHook('00000000000')).rejects.toThrow(
|
|
'Celular brasileiro inválido.',
|
|
)
|
|
expect(phoneMocks.normalizeBrazilianPhone).not.toHaveBeenCalled()
|
|
})
|
|
})
|