Blame · Line-by-line history
org-health-route.test.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 76ee7bc | 1 | /** |
| 2 | * Regression: /orgs/:slug/health must reach org-health, not be shadowed. | |
| 3 | * | |
| 4 | * org-health.tsx's `GET /orgs/:slug/health` was mounted AFTER | |
| 5 | * healthDashboardRoutes' generic `GET /:owner/:repo/health`, so Hono bound | |
| 6 | * `/orgs/acme/health` as owner="orgs", repo="acme" → repoExists("orgs","acme") | |
| 7 | * false → 404. The entire org-health feature was dead (unreachable), and its | |
| 8 | * own recompute POST redirected into that 404. Mount order now puts | |
| 9 | * orgHealthRoutes first. | |
| 10 | * | |
| 11 | * An UNKNOWN slug can't distinguish the two handlers (both 404), so this test | |
| 12 | * seeds a REAL org and asserts the org-health page renders (200 + its own | |
| 13 | * "Engineering Health" markup). Under the old shadowed mount this 404'd. | |
| 14 | * DB-gated: skips locally without DATABASE_URL, runs in CI/deploy. | |
| 15 | */ | |
| 16 | import { describe, it, expect } from "bun:test"; | |
| 17 | import app from "../app"; | |
| 18 | import { db } from "../db"; | |
| 19 | import { users, organizations } from "../db/schema"; | |
| 20 | import { eq } from "drizzle-orm"; | |
| 21 | ||
| 22 | const HAS_DB = Boolean(process.env.DATABASE_URL); | |
| 23 | ||
| 24 | describe("org-health route is not shadowed by the repo health page", () => { | |
| 25 | it.skipIf(!HAS_DB)( | |
| 26 | "/orgs/:slug/health renders the org-health page (not a repo 404)", | |
| 27 | async () => { | |
| 28 | // Deterministic slug so a re-run can clean up first (no Math.random()). | |
| 29 | const slug = "orghealth-route-test-org"; | |
| 30 | const uname = "orghealth-route-test-user"; | |
| 31 | // Clean any leftovers from a prior run. | |
| 32 | await db.delete(organizations).where(eq(organizations.slug, slug)); | |
| 33 | await db.delete(users).where(eq(users.username, uname)); | |
| 34 | ||
| 35 | const [u] = await db | |
| 36 | .insert(users) | |
| 37 | .values({ | |
| 38 | username: uname, | |
| 39 | email: `${uname}@example.test`, | |
| 40 | passwordHash: "x", | |
| 41 | }) | |
| 42 | .returning({ id: users.id }); | |
| 43 | await db.insert(organizations).values({ | |
| 44 | slug, | |
| 45 | name: "Org Health Route Test", | |
| 46 | createdById: u.id, | |
| 47 | }); | |
| 48 | ||
| 49 | try { | |
| 50 | const res = await app.request(`/orgs/${slug}/health`); | |
| 51 | expect(res.status).toBe(200); | |
| 52 | const body = await res.text(); | |
| 53 | expect(body).toContain("Engineering Health"); | |
| 54 | } finally { | |
| 55 | await db.delete(organizations).where(eq(organizations.slug, slug)); | |
| 56 | await db.delete(users).where(eq(users.username, uname)); | |
| 57 | } | |
| 58 | } | |
| 59 | ); | |
| 60 | ||
| 61 | it("a genuine unknown repo health page still 404s through the repo handler", async () => { | |
| 62 | // Proves orgHealthRoutes' literal /orgs prefix didn't swallow generic | |
| 63 | // repo paths (this runs without a DB — it's a pure not-found path). | |
| 64 | const res = await app.request("/nobody-xyz/nothing-xyz/health"); | |
| 65 | expect(res.status).toBe(404); | |
| 66 | }); | |
| 67 | }); |