import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
const legalDocuments = [
{
path: "../public/privacy-policy.html",
title: "Privacy Policy - CozSweet",
marker: "PRIVACY POLICY",
},
{
path: "../public/data-deletion.html",
title: "Data Deletion – CozSweet",
marker: "HOW CAN YOU REVIEW, UPDATE, OR DELETE THE DATA WE COLLECT FROM YOU?",
},
{
path: "../public/membership-agreement.html",
title: "Membership Service Agreement - CozSweet",
marker: "MEMBERSHIP SERVICE AGREEMENT",
},
{
path: "../public/auto-renewal-agreement.html",
title: "Auto-Renewal Service Agreement - CozSweet",
marker: "AUTO-RENEWAL SERVICE AGREEMENT",
},
{
path: "../public/cozsweet/privacy-policy.html",
title: "Privacy Policy - CozSweet",
marker: "BUYER PROTECTION POLICY",
},
{
path: "../public/cozsweet/data-deletion.html",
title: "Data Deletion – CozSweet",
marker: "HOW CAN YOU REVIEW, UPDATE, OR DELETE THE DATA WE COLLECT FROM YOU?",
},
{
path: "../public/cozsweet/membership-agreement.html",
title: "Membership Service Agreement - CozSweet",
marker: "MEMBERSHIP SERVICE AGREEMENT",
},
{
path: "../public/cozsweet/auto-renewal-agreement.html",
title: "Auto-Renewal Service Agreement - CozSweet",
marker: "AUTO-RENEWAL SERVICE AGREEMENT",
},
];
for (const document of legalDocuments) {
test(`includes ${document.title}`, async () => {
const html = await readFile(new URL(document.path, import.meta.url), "utf8");
assert.match(html, new RegExp(`
${document.title}`));
assert.ok(html.includes(document.marker));
assert.ok(html.length > 1_000);
});
}
test("keeps both privacy policy URLs byte-identical", async () => {
const rootPolicy = await readFile(
new URL("../public/privacy-policy.html", import.meta.url),
);
const cozsweetPolicy = await readFile(
new URL("../public/cozsweet/privacy-policy.html", import.meta.url),
);
assert.deepEqual(cozsweetPolicy, rootPolicy);
});
for (const documentName of [
"data-deletion",
"membership-agreement",
"auto-renewal-agreement",
]) {
test(`keeps both ${documentName} URLs byte-identical`, async () => {
const rootDocument = await readFile(
new URL(`../public/${documentName}.html`, import.meta.url),
);
const cozsweetDocument = await readFile(
new URL(`../public/cozsweet/${documentName}.html`, import.meta.url),
);
assert.deepEqual(cozsweetDocument, rootDocument);
});
}
test("exposes all legal documents from the site footer", async () => {
const source = await readFile(
new URL("../components/SiteShell.tsx", import.meta.url),
"utf8",
);
for (const href of [
"/cozsweet/privacy-policy.html",
"/cozsweet/data-deletion.html",
"/cozsweet/membership-agreement.html",
"/cozsweet/auto-renewal-agreement.html",
]) {
assert.ok(source.includes(`href="${href}"`), `Missing footer link: ${href}`);
}
});
test("redirects the legacy .html URLs through the worker", async () => {
const source = await readFile(
new URL("../worker/index.ts", import.meta.url),
"utf8",
);
for (const documentName of [
"privacy-policy",
"data-deletion",
"membership-agreement",
"auto-renewal-agreement",
]) {
assert.ok(
source.includes(
`"/cozsweet/${documentName}.html": "/${documentName}.html"`,
),
`Missing legacy redirect: ${documentName}`,
);
}
});