teqo-backup/tests/unit/campaignConsent.unit.spec.ts
Francisco Ignácio Fontoura Solla bcac665cb5 Ship /campanha nuclei MVP with RBAC, invites, and vote estimates.
Adds electoral nuclei, leaderships, updates, and WhatsApp invite flows behind campaign auth, plus the consolidated schema migration that Vercel applies on deploy.
2026-07-18 15:01:56 -03:00

39 lines
1.3 KiB
TypeScript

// @vitest-environment node
import { describe, expect, it, vi } from 'vitest'
import type { Payload } from 'payload'
import {
getLeadershipConsent,
requireLeadershipConsent,
} from '@/utilities/campaignConsent'
describe('campaign consent descriptor', () => {
it('returns the stable descriptor and propagates the transaction request', async () => {
const req = { transactionID: 17 }
const find = vi.fn().mockResolvedValue({
docs: [{ id: 9, text: { root: { children: [] } } }],
})
const payload = { find } as unknown as Payload
const consent = await getLeadershipConsent(payload, req)
expect(consent).toEqual({
id: 9,
text: { root: { children: [] } },
contentHash: 'd800986181e1730e945e028853848395d8c34ccb95b54abbbaa50cb9539a845b',
})
expect(find).toHaveBeenCalledWith(expect.objectContaining({ req }))
})
it('keeps nullable and required missing-consent semantics distinct', async () => {
const payload = {
find: vi.fn().mockResolvedValue({ docs: [] }),
} as unknown as Payload
await expect(getLeadershipConsent(payload)).resolves.toBeNull()
await expect(requireLeadershipConsent(payload, undefined, 'Consentimento ausente.')).rejects.toThrow(
'Consentimento ausente.',
)
})
})