| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { follows, happened } from "./happened.ts"; |
| 5 | |
| 6 | const ev = (type: string, data: Record<string, unknown>) => ({ type, repoId: null, data }) as never; |
| 7 | |
| 8 | test("events become the routine events they are, keyed so one thing runs once", () => { |
| 9 | assert.deepEqual(happened(ev("pull.ready", { repoId: "rep_1", number: 12 }))?.key, "pull_ready:rep_1:12"); |
| 10 | assert.equal(happened(ev("pull.opened", { repoId: "rep_1", number: 12 }))?.key, "pull_ready:rep_1:12", "opened and ready are the same thing"); |
| 11 | assert.equal(happened(ev("checks.completed", { repoId: "rep_1", number: 3, status: "passed", commit: "abc" })), null); |
| 12 | assert.equal(happened(ev("checks.completed", { repoId: "rep_1", number: 3, status: "failed", commit: "abc" }))?.key, "checks_failed:rep_1:3:abc"); |
| 13 | assert.notEqual( |
| 14 | happened(ev("checks.completed", { repoId: "rep_1", number: 3, status: "errored", commit: "def" }))?.key, |
| 15 | "checks_failed:rep_1:3:abc", |
| 16 | "a new commit failing is a new thing", |
| 17 | ); |
| 18 | assert.equal(happened(ev("issue.opened", { repoId: "rep_1", number: 9, title: "x" }))?.kind, "issue_opened"); |
| 19 | assert.equal(happened(ev("deployment.failed", { repoId: "rep_1", deploymentId: "dpl_1" }))?.key, "deploy_failed:dpl_1"); |
| 20 | assert.equal(happened(ev("pull.updated", { repoId: "rep_1", number: 1 })), null); |
| 21 | assert.equal(happened(ev("pull.ready", { number: 1 })), null, "no repository, nothing to check access on"); |
| 22 | }); |
| 23 | |
| 24 | test("a routine follows every repository, or only those it names", () => { |
| 25 | assert.equal(follows([], "acme/web"), true); |
| 26 | assert.equal(follows(["acme/web"], "Acme/Web"), true); |
| 27 | assert.equal(follows(["acme/api"], "acme/web"), false); |
| 28 | }); |