62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
groupCookiesByCategory,
|
|
isValidCookieEntry,
|
|
normalizeCookieEntries,
|
|
} from "./cookie-schema.js";
|
|
|
|
describe("cookie-schema", () => {
|
|
it("validates cookie entries", () => {
|
|
expect(
|
|
isValidCookieEntry({
|
|
category: "analytics",
|
|
name: "_ga",
|
|
purpose: "Analytics",
|
|
duration: "2 years",
|
|
provider: "Google",
|
|
}),
|
|
).toBe(true);
|
|
|
|
expect(isValidCookieEntry({ category: "unknown", name: "_ga" })).toBe(false);
|
|
});
|
|
|
|
it("normalizes invalid entries out of the list", () => {
|
|
const cookies = normalizeCookieEntries([
|
|
{
|
|
category: "marketing",
|
|
name: "_fbp",
|
|
purpose: "Ads",
|
|
duration: "3 months",
|
|
provider: "Meta",
|
|
},
|
|
{ category: "invalid", name: "bad" },
|
|
]);
|
|
|
|
expect(cookies).toHaveLength(1);
|
|
expect(cookies[0].name).toBe("_fbp");
|
|
});
|
|
|
|
it("groups cookies by category", () => {
|
|
const grouped = groupCookiesByCategory([
|
|
{
|
|
category: "analytics",
|
|
name: "_ga",
|
|
purpose: "Analytics",
|
|
duration: "2 years",
|
|
provider: "Google",
|
|
},
|
|
{
|
|
category: "necessary",
|
|
name: "ccm_consent",
|
|
purpose: "Preferences",
|
|
duration: "1 year",
|
|
provider: "Site",
|
|
},
|
|
]);
|
|
|
|
expect(grouped.analytics).toHaveLength(1);
|
|
expect(grouped.necessary).toHaveLength(1);
|
|
expect(grouped.marketing).toHaveLength(0);
|
|
});
|
|
});
|