- knip (files/deps at error level; unused exports ledgered as warn) with config for Payload/Next entries; deleted the dead modules it confirmed: RecentlyVisited + UpcomingActionPlansCard + actionPlanUpcomingPreview, lazy-dialog helpers, tseZone, federalCandidateTotalsAggregate (test-only), unused ui kit files, one-shot rename script; pruned unused radix deps and typescript-eslint; added pg/@types/pg (pinned to drizzle's 8.10.2) - GitHub Actions CI on the mirror: lint, typecheck, knip, unit, migrate, int against a Postgres 17 service - eslint: unused-vars with ^_ ignore patterns (migrations args exempt), repo-wide ban on `as never` (no-restricted-syntax), lint gate at --max-warnings=0; fixed all 54 pre-existing warnings (dead imports, hooks deps, tracking-pixel img disable with impeccable config exception) - tsconfig: include consolidated from 219 lines to 5 (wildcard covers all .next dist variants), noUnusedLocals on - typed replacements for every as-never: hookFilledCreateData (actions create data completed by collection hooks), drizzle scopeColumn narrowing, tests' stub<T> helper (property-level checking kept, completeness waived) - test infra: leased-consent generalization used by onda0 spec (shared leases over the stable consent keys; window race ledgered), purge fix - docs: IMPROVE-CODE-QUALITY-PLAN.md tracker, TECH-DEBT.md ledger, TESTING.md safety-net map (package.json also gains the Phase 2 build:election-aggregates script entry; the script lands next commit)
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
// @vitest-environment node
|
|
|
|
import { getPayload, type Payload } from 'payload'
|
|
import { beforeAll, describe, expect, it } from 'vitest'
|
|
|
|
import { ONDA0_CONSENT_ENTRIES } from '@/lib/onda0ConsentTexts'
|
|
import config from '@/payload.config'
|
|
import { requireConsentByKey } from '@/utilities/campaignConsent'
|
|
import { provisionOnda0ConsentAndPrivacy } from '@/utilities/onda0Provision'
|
|
|
|
import { assertTestDatabase } from '../helpers/assertTestDatabase'
|
|
import { installCampaignFixtures } from '../helpers/campaignFixtures'
|
|
import {
|
|
CAMPAIGN_INVITE_CONSENT_LEASE_KEY,
|
|
SUPPORTER_REGISTRATION_CONSENT_LEASE_KEY,
|
|
SUPPORTER_VOTE_INTENTION_CONSENT_LEASE_KEY,
|
|
withSharedTestDatabaseLease,
|
|
} from '../helpers/testDatabaseLease'
|
|
|
|
let payload: Payload
|
|
|
|
installCampaignFixtures({
|
|
getPayload: () => payload,
|
|
setPayload: (nextPayload) => {
|
|
payload = nextPayload
|
|
},
|
|
})
|
|
|
|
describe('Onda 0 provision (integration)', () => {
|
|
beforeAll(async () => {
|
|
assertTestDatabase(process.env.DATABASE_URL)
|
|
payload = await getPayload({ config })
|
|
})
|
|
|
|
it('upserts consent keys and publishes privacy-policy idempotently', async () => {
|
|
// Shared leases on every stable consent key: parallel spec files exercise
|
|
// "consent missing" fail-closed paths by deleting these rows under an
|
|
// EXCLUSIVE lease — without the shared leases this test races that window.
|
|
await withSharedTestDatabaseLease(payload, CAMPAIGN_INVITE_CONSENT_LEASE_KEY, () =>
|
|
withSharedTestDatabaseLease(payload, SUPPORTER_REGISTRATION_CONSENT_LEASE_KEY, () =>
|
|
withSharedTestDatabaseLease(payload, SUPPORTER_VOTE_INTENTION_CONSENT_LEASE_KEY, async () => {
|
|
await provisionOnda0ConsentAndPrivacy(payload)
|
|
await provisionOnda0ConsentAndPrivacy(payload)
|
|
|
|
for (const { key } of ONDA0_CONSENT_ENTRIES) {
|
|
const descriptor = await requireConsentByKey(payload, key)
|
|
expect(descriptor.key).toBe(key)
|
|
expect(descriptor.contentHash).toMatch(/^[a-f0-9]{64}$/)
|
|
}
|
|
|
|
const privacy = await payload.findGlobal({
|
|
slug: 'privacy-policy',
|
|
overrideAccess: true,
|
|
})
|
|
expect(privacy.published).toBe(true)
|
|
expect(privacy.body).toBeTruthy()
|
|
}),
|
|
),
|
|
)
|
|
})
|
|
})
|