import { analyticsConsent } from '../../src/routes/customers'; import { MARKETING_CONSENT_TEXT } from '../../src/utils'; /** * The rule this file exists for: agreeing to the *old* consent wording does not * authorise the Brevo tracker (#56). * * The sentence customers agree to was widened to mention analytics. Everyone * who consented before that agreed to a sentence about email and nothing else, * and `marketing_consent` alone cannot tell the two populations apart — which * is exactly why the wording is stored per customer. Getting this wrong would * silently track people who never agreed to it, and would do so invisibly, * because the flag they set really is `true`. */ describe('analyticsConsent', () => { const OLD_WORDING = 'I want to receive occasional emails about new one-of-a-kind items from Redefined Designs. I can unsubscribe at any time.'; it('is true for a customer who agreed to the current wording', () => { expect( analyticsConsent({ marketing_consent: true, marketing_consent_text: MARKETING_CONSENT_TEXT }) ).toBe(true); }); it('is false for a customer who agreed to the previous, email-only wording', () => { // The case the whole mechanism exists for. They consented, and their // consent does not cover this. expect( analyticsConsent({ marketing_consent: true, marketing_consent_text: OLD_WORDING }) ).toBe(false); }); it('is false when consent was never given, whatever text is stored', () => { expect( analyticsConsent({ marketing_consent: false, marketing_consent_text: MARKETING_CONSENT_TEXT }) ).toBe(false); }); it('is false when no wording was recorded at all', () => { // Withdrawal writes a sentinel rather than the consent text, and older rows // may predate the column being populated. Neither is agreement. expect( analyticsConsent({ marketing_consent: true, marketing_consent_text: null }) ).toBe(false); }); it('does not accept a near-miss, so a reworded sentence re-asks rather than assumes', () => { expect( analyticsConsent({ marketing_consent: true, marketing_consent_text: `${MARKETING_CONSENT_TEXT} ` }) ).toBe(false); }); it('guards the wording itself: the current text must mention what is shared', () => { // Not a tautology — it fails if someone narrows the sentence back to email // while leaving the tracker gated on it, which would put this project back // in the position #56 was filed to get it out of. expect(MARKETING_CONSENT_TEXT).toContain('browse'); expect(MARKETING_CONSENT_TEXT).not.toBe(OLD_WORDING); }); });