test(auth): add cookie schema test

cookie.ts was the only entity model in the feature packages without a
sibling test. Covers minimal/full attributes, invalid sameSite, and a
missing required field.
This commit is contained in:
2026-05-21 11:25:42 +02:00
parent 714209e63e
commit affcb28c24

View File

@@ -0,0 +1,47 @@
import { describe, expect, it } from "vitest";
import { cookieSchema } from "./cookie";
describe("cookieSchema", () => {
it("accepts a minimal cookie with empty attributes", () => {
const result = cookieSchema.parse({
name: "session",
value: "abc123",
attributes: {},
});
expect(result.name).toBe("session");
expect(result.value).toBe("abc123");
});
it("accepts a fully-populated cookie", () => {
const result = cookieSchema.parse({
name: "session",
value: "abc123",
attributes: {
secure: true,
path: "/",
domain: "example.com",
sameSite: "strict",
httpOnly: true,
maxAge: 3600,
expires: new Date(),
},
});
expect(result.attributes.sameSite).toBe("strict");
});
it("rejects an invalid sameSite value", () => {
expect(() =>
cookieSchema.parse({
name: "session",
value: "abc123",
attributes: { sameSite: "invalid" },
}),
).toThrow();
});
it("rejects a missing required field", () => {
expect(() =>
cookieSchema.parse({ name: "session", attributes: {} }),
).toThrow();
});
});