| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { asksFirst, choice, consentRequired } from "./analytics-consent.ts"; |
| 5 | |
| 6 | test("visitors from the EU, EEA, UK and Switzerland are asked first", () => { |
| 7 | for (const country of ["DE", "fr", "IE", "NO", "IS", "GB", "CH"]) assert.equal(asksFirst(country), true, country); |
| 8 | }); |
| 9 | |
| 10 | test("others are not, nor is a visitor whose country is unknown", () => { |
| 11 | for (const country of ["US", "CA", "AU", "JP", "BR"]) assert.equal(asksFirst(country), false, country); |
| 12 | assert.equal(asksFirst(null), false); |
| 13 | assert.equal(asksFirst(""), false); |
| 14 | }); |
| 15 | |
| 16 | test("on the server nothing is chosen or required", () => { |
| 17 | assert.equal(choice(), null); |
| 18 | assert.equal(consentRequired(), false); |
| 19 | }); |