This commit is contained in:
parent
816881c2cc
commit
3379abf99b
9 changed files with 57 additions and 36 deletions
|
|
@ -23,15 +23,15 @@ async function signedRequest(path: string, provider: "github" | "jojo", secret:
|
|||
|
||||
describe("server", () => {
|
||||
test("healthz returns ok", async () => {
|
||||
const handler = createHandler({ githubSecret: "gh", jojoSecret: "jojo", dataDir: await mkdtemp(join(tmpdir(), "git-webhooks-")) });
|
||||
const handler = createHandler({ githubSecret: "gh", jojoSecret: "jojo", dataDir: await mkdtemp(join(tmpdir(), "patchbay-")) });
|
||||
const response = await handler(new Request("http://localhost/healthz"));
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.text()).toBe("ok\n");
|
||||
});
|
||||
|
||||
test("rejects invalid signatures", async () => {
|
||||
const handler = createHandler({ githubSecret: "gh", jojoSecret: "jojo", dataDir: await mkdtemp(join(tmpdir(), "git-webhooks-")) });
|
||||
const response = await handler(new Request("http://localhost/git-webhooks/github", {
|
||||
const handler = createHandler({ githubSecret: "gh", jojoSecret: "jojo", dataDir: await mkdtemp(join(tmpdir(), "patchbay-")) });
|
||||
const response = await handler(new Request("http://localhost/patchbay/github", {
|
||||
method: "POST",
|
||||
headers: { "x-hub-signature-256": "sha256=bad" },
|
||||
body: "{}",
|
||||
|
|
@ -40,14 +40,14 @@ describe("server", () => {
|
|||
});
|
||||
|
||||
test("accepts jojo main pushes and queues a job", async () => {
|
||||
const dataDir = await mkdtemp(join(tmpdir(), "git-webhooks-"));
|
||||
const dataDir = await mkdtemp(join(tmpdir(), "patchbay-"));
|
||||
const handler = createHandler({ githubSecret: "gh", jojoSecret: "jojo", dataDir });
|
||||
const request = await signedRequest("/git-webhooks/jojo", "jojo", "jojo", {
|
||||
const request = await signedRequest("/patchbay/jojo", "jojo", "jojo", {
|
||||
ref: "refs/heads/main",
|
||||
after: "abc123",
|
||||
repository: {
|
||||
name: "git-webhooks",
|
||||
full_name: "peezy-tech/git-webhooks",
|
||||
name: "patchbay",
|
||||
full_name: "peezy-tech/patchbay",
|
||||
owner: { username: "peezy-tech" },
|
||||
},
|
||||
});
|
||||
|
|
@ -58,12 +58,30 @@ describe("server", () => {
|
|||
expect(await readFile(join(dataDir, "jobs.jsonl"), "utf8")).toContain("\"kind\":\"main_push\"");
|
||||
});
|
||||
|
||||
test("keeps legacy git-webhooks routes as aliases", async () => {
|
||||
const dataDir = await mkdtemp(join(tmpdir(), "patchbay-"));
|
||||
const handler = createHandler({ githubSecret: "gh", jojoSecret: "jojo", dataDir });
|
||||
const request = await signedRequest("/git-webhooks/jojo", "jojo", "jojo", {
|
||||
ref: "refs/heads/main",
|
||||
after: "abc123",
|
||||
repository: {
|
||||
name: "patchbay",
|
||||
full_name: "peezy-tech/patchbay",
|
||||
owner: { username: "peezy-tech" },
|
||||
},
|
||||
});
|
||||
|
||||
const response = await handler(request);
|
||||
expect(response.status).toBe(202);
|
||||
expect(await readFile(join(dataDir, "events.jsonl"), "utf8")).toContain("\"provider\":\"jojo\"");
|
||||
});
|
||||
|
||||
test("continues accepting webhooks when Discord returns an error", async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = (async () => new Response("bad", { status: 500 })) as unknown as typeof fetch;
|
||||
|
||||
try {
|
||||
const dataDir = await mkdtemp(join(tmpdir(), "git-webhooks-"));
|
||||
const dataDir = await mkdtemp(join(tmpdir(), "patchbay-"));
|
||||
const handler = createHandler({
|
||||
githubSecret: "gh",
|
||||
jojoSecret: "jojo",
|
||||
|
|
@ -73,12 +91,12 @@ describe("server", () => {
|
|||
notifyEvents: new Set(["push"]),
|
||||
},
|
||||
});
|
||||
const request = await signedRequest("/git-webhooks/jojo", "jojo", "jojo", {
|
||||
const request = await signedRequest("/patchbay/jojo", "jojo", "jojo", {
|
||||
ref: "refs/heads/main",
|
||||
after: "abc123",
|
||||
repository: {
|
||||
name: "git-webhooks",
|
||||
full_name: "peezy-tech/git-webhooks",
|
||||
name: "patchbay",
|
||||
full_name: "peezy-tech/patchbay",
|
||||
owner: { username: "peezy-tech" },
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue