fix(test): S9+ — harness ciente do guard de Consent (CI do #771)

- campaignSupporter: destaca voteIntentionConsent dos supporters antes de
  purgar o consent canônico de intenção de voto — o seed mínimo cria vínculos
  vivos nessa chave, e o delete passou a depender do SET NULL silencioso que
  o guard agora bloqueia (falha determinística em DB fresca de CI).
- campaignInvite: purga da chave lideranca-autopreenchimento na janela
  mutável passa a raw SQL (precedente Onda0/lease) — lifecycle de harness
  nunca deve passar pelo caminho admin/beforeDelete.
This commit is contained in:
Francisco Solla 2026-08-24 23:57:52 -03:00
parent d396870d22
commit aff8c6cbf3
2 changed files with 17 additions and 4 deletions

View file

@ -611,10 +611,12 @@ describe('campaign invite domain', () => {
const actions = await import('@/app/(campaign)/campanha/actions/invite').catch(() => null)
expect(actions).not.toBeNull()
await payload.delete({
collection: 'consent',
where: { key: { equals: 'lideranca-autopreenchimento' } },
})
// Harness purge (Onda0-provision / lease precedent): raw SQL so the
// admin-path beforeDelete guard and access checks never apply to this
// lifecycle setup — the window lease already guarantees isolation.
await payload.db.drizzle.execute(
sql`DELETE FROM "consent" WHERE "key" = ${'lideranca-autopreenchimento'}`,
)
const coordinator = await campaignFixtures().createCampaignUser('coordinator')
const municipality = await campaignFixtures().getMunicipality()
const { leadership } = await createInviteLeadershipGraph(coordinator, municipality.id)

View file

@ -212,6 +212,17 @@ describe('campaign supporter domain', () => {
limit: 1,
})
if (existingVoteConsent.docs[0]) {
// S9+: Consent.beforeDelete refuses deleting an in-use legal text. The
// minimal seed links seeded supporters to this canonical consent, so
// detach the live voteIntentionConsent references FIRST — the explicit,
// ordered version of the FK `ON DELETE SET NULL` this purge relied on
// silently before the guard existed.
await payload.update({
collection: 'supporter',
where: { voteIntentionConsent: { equals: existingVoteConsent.docs[0].id } },
data: { voteIntentionConsent: null },
overrideAccess: true,
})
await payload.delete({
collection: 'consent',
id: existingVoteConsent.docs[0].id,