| 1 | import type { DiffineryEvent } from "@diffinery/shared"; |
| 2 | import { describe, expect, it } from "vitest"; |
| 3 | import type { Repo } from "../../src/lib/directory.js"; |
| 4 | import { webhookPayload } from "../../src/lib/webhook-payload.js"; |
| 5 | |
| 6 | const BASE = "https://diffinery.example"; |
| 7 | const row = (visibility: Repo["visibility"]): Repo => ({ |
| 8 | id: "r1", |
| 9 | owner_id: "u1", |
| 10 | owner_login: "octo", |
| 11 | owner_kind: "user", |
| 12 | name: "app", |
| 13 | description: "", |
| 14 | visibility, |
| 15 | default_branch: "main", |
| 16 | archived: 0, |
| 17 | created_at: "2026-01-01T00:00:00.000Z", |
| 18 | updated_at: "2026-01-01T00:00:00.000Z", |
| 19 | pushed_at: null, |
| 20 | }); |
| 21 | const push: Extract<DiffineryEvent, { type: "push" }> = { type: "push", repoId: "r1", owner: "octo", repo: "app", ref: "refs/heads/main", before: "0".repeat(40), after: "a".repeat(40), forced: false, created: false, deleted: false, actor: { id: "u1", login: "octo", kind: "user" }, at: "2026-01-01T00:00:00.000Z" }; |
| 22 | |
| 23 | describe("webhookPayload", () => { |
| 24 | it("reports a public repository as public, like GitHub", () => { |
| 25 | const body = webhookPayload(BASE, push, row("public")); |
| 26 | expect(body.repository).toMatchObject({ full_name: "octo/app", private: false, visibility: "public", default_branch: "main", owner: { login: "octo" } }); |
| 27 | }); |
| 28 | |
| 29 | it("reports a private repository as private", () => { |
| 30 | expect(webhookPayload(BASE, push, row("private")).repository).toMatchObject({ private: true, visibility: "private" }); |
| 31 | }); |
| 32 | |
| 33 | it("falls back to a minimal private repository when the directory row is gone", () => { |
| 34 | expect(webhookPayload(BASE, push, null).repository).toMatchObject({ full_name: "octo/app", private: true, visibility: "private" }); |
| 35 | }); |
| 36 | }); |