mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
chore(quality): provider fixtures, formatter snapshots, platform contract tests, CI, CodeQL, dependabot
This commit is contained in:
parent
04fa52db52
commit
320e825bf8
15 changed files with 405 additions and 3 deletions
55
tests/provider-fixtures.test.ts
Normal file
55
tests/provider-fixtures.test.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { describe, test, expect } from "bun:test";
|
||||
import { formatEvent } from "../server/lib/formatters";
|
||||
import { detectProvider } from "../server/lib/providers";
|
||||
import type { Route, WebhookEvent } from "../server/lib/types";
|
||||
import { githubPush, githubPullRequest, githubIssues, giteaPush, customPayload } from "./fixtures";
|
||||
|
||||
const route: Route = {
|
||||
id: "test",
|
||||
name: "Test",
|
||||
enabled: true,
|
||||
filters: [],
|
||||
targets: [{ channelId: "111" }],
|
||||
};
|
||||
|
||||
function event(ev: string, payload: Record<string, unknown>): WebhookEvent {
|
||||
return { event: ev, payload };
|
||||
}
|
||||
|
||||
describe("provider fixtures", () => {
|
||||
const githubFixtures = [
|
||||
{ event: "push", payload: githubPush },
|
||||
{ event: "pull_request", payload: githubPullRequest },
|
||||
{ event: "issues", payload: githubIssues },
|
||||
];
|
||||
|
||||
for (const { event: ev, payload } of githubFixtures) {
|
||||
test(`formats github ${ev} with a title`, () => {
|
||||
const msg = formatEvent(route, event(ev, payload));
|
||||
expect(msg.title.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test(`github parse detects ${ev}`, () => {
|
||||
const headers = { "x-github-event": ev };
|
||||
const parsed = detectProvider(headers)?.parse(JSON.stringify(payload), headers);
|
||||
expect(parsed?.event).toBe(ev);
|
||||
});
|
||||
}
|
||||
|
||||
test("formats gitea push with a title", () => {
|
||||
const msg = formatEvent(route, event("push", giteaPush));
|
||||
expect(msg.title.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("gitea parse detects push", () => {
|
||||
const headers = { "x-gitea-event": "push" };
|
||||
const parsed = detectProvider(headers)?.parse(JSON.stringify(giteaPush), headers);
|
||||
expect(parsed?.event).toBe("push");
|
||||
});
|
||||
|
||||
test("custom parse detects custom event", () => {
|
||||
const headers = { "x-webhooker-signature": "sha256=abc" };
|
||||
const parsed = detectProvider(headers)?.parse(JSON.stringify(customPayload), headers);
|
||||
expect(parsed?.event).toBe("custom");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue