29 lines
985 B
TypeScript
29 lines
985 B
TypeScript
import { readFile } from "node:fs/promises";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import type { GenerationJob } from "@/lib/types";
|
|
import { buildJobWebhookPayload, signWebhookBody } from "@/lib/server/webhook";
|
|
|
|
const fixtureUrl = new URL("../contracts/webhook/job-webhook-v1.json", import.meta.url);
|
|
|
|
describe("job webhook v1 cross-language contract", () => {
|
|
it("freezes exact body bytes and HMAC header", async () => {
|
|
const fixture = JSON.parse(await readFile(fixtureUrl, "utf8"));
|
|
const job = {
|
|
...fixture.job,
|
|
ownerId: "owner-1",
|
|
provider: "mock",
|
|
reqKey: "fixture",
|
|
inputAssetIds: [],
|
|
inputUrls: [],
|
|
requestPayload: {},
|
|
createdAt: fixture.job.updatedAt,
|
|
} as GenerationJob;
|
|
const body = JSON.stringify(buildJobWebhookPayload(job));
|
|
expect(body).toBe(fixture.body);
|
|
expect(signWebhookBody(body, fixture.secret)).toBe(fixture.signature);
|
|
expect(fixture.maximumAttempts).toBe(3);
|
|
});
|
|
});
|