|
1 | 1 | import { describe, test, expect } from "bun:test" |
2 | | -import { checkBodySize, MAX_WEBHOOK_BODY_BYTES, recordDelivery } from "./github-webhook-auth" |
| 2 | +import { |
| 3 | + checkBodySize, |
| 4 | + MAX_WEBHOOK_BODY_BYTES, |
| 5 | + recordDelivery, |
| 6 | + isKnownInstallation, |
| 7 | +} from "./github-webhook-auth" |
3 | 8 | import { db } from "../db" |
4 | 9 | import { githubWebhookDeliveries } from "../db/schema/github-webhook-deliveries" |
| 10 | +import { githubIntegrations } from "../db/schema/github-integrations" |
| 11 | +import { projects } from "../db/schema/projects" |
5 | 12 | import { eq } from "drizzle-orm" |
6 | 13 |
|
7 | 14 | describe("checkBodySize", () => { |
@@ -37,3 +44,27 @@ describe("recordDelivery", () => { |
37 | 44 | await db.delete(githubWebhookDeliveries).where(eq(githubWebhookDeliveries.deliveryId, id)) |
38 | 45 | }) |
39 | 46 | }) |
| 47 | + |
| 48 | +describe("isKnownInstallation", () => { |
| 49 | + test("returns false when no row matches", async () => { |
| 50 | + expect(await isKnownInstallation(999_999_999)).toBe(false) |
| 51 | + }) |
| 52 | + |
| 53 | + test("returns true when a github_integrations row has the installation id", async () => { |
| 54 | + const [project] = await db |
| 55 | + .insert(projects) |
| 56 | + .values({ name: "wh-auth-test", createdBy: "test-user" }) |
| 57 | + .returning() |
| 58 | + const installationId = 42_000_000 + Math.floor(Math.random() * 1_000_000) |
| 59 | + await db.insert(githubIntegrations).values({ |
| 60 | + projectId: project.id, |
| 61 | + installationId, |
| 62 | + repoOwner: "", |
| 63 | + repoName: "", |
| 64 | + status: "connected", |
| 65 | + }) |
| 66 | + expect(await isKnownInstallation(installationId)).toBe(true) |
| 67 | + await db.delete(githubIntegrations).where(eq(githubIntegrations.projectId, project.id)) |
| 68 | + await db.delete(projects).where(eq(projects.id, project.id)) |
| 69 | + }) |
| 70 | +}) |
0 commit comments