Files
GibSend/apps/web/src/server/utils/idempotency.unit.test.ts
T
KM Koushik 487902421b feat: add web testing foundation with infra-backed suites (#349)
* feat: add web test framework with infra-backed suites

* fix: honor DATABASE_URL env in integration prepare script

* fix: apply web test review feedback

* fix: streamline web test infra lifecycle and workflow scope
2026-02-16 09:13:29 +11:00

31 lines
914 B
TypeScript

import { describe, expect, it } from "vitest";
import { canonicalizePayload } from "~/server/utils/idempotency";
describe("canonicalizePayload", () => {
it("generates same hash for different key ordering", () => {
const payloadA = { b: 1, a: { y: 2, x: 1 } };
const payloadB = { a: { x: 1, y: 2 }, b: 1 };
const a = canonicalizePayload(payloadA);
const b = canonicalizePayload(payloadB);
expect(a.canonical).toBe(b.canonical);
expect(a.bodyHash).toBe(b.bodyHash);
});
it("normalizes dates and undefined values deterministically", () => {
const payload = {
createdAt: new Date("2025-01-01T00:00:00.000Z"),
name: "alpha",
skip: undefined,
};
const result = canonicalizePayload(payload);
expect(result.canonical).toBe(
'{"createdAt":"2025-01-01T00:00:00.000Z","name":"alpha"}',
);
expect(result.bodyHash).toHaveLength(64);
});
});