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:
47
packages/auth/src/entities/models/cookie.test.ts
Normal file
47
packages/auth/src/entities/models/cookie.test.ts
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user