Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history

api.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.

api.test.tsBlame61 lines · 1 contributor
fc1817aClaude1import { describe, it, expect, beforeAll, afterAll } from "bun:test";
2import { join } from "path";
3import { rm, mkdir } from "fs/promises";
4import app from "../app";
5
6const TEST_REPOS = join(import.meta.dir, "../../.test-repos-api");
7
8beforeAll(async () => {
9 process.env.GIT_REPOS_PATH = TEST_REPOS;
10 process.env.DATABASE_URL = process.env.DATABASE_URL || "";
11 await mkdir(TEST_REPOS, { recursive: true });
12});
13
14afterAll(async () => {
15 await rm(TEST_REPOS, { recursive: true, force: true });
16});
17
18describe("API routes", () => {
19 it("GET / returns home page", async () => {
20 const res = await app.request("/");
21 expect(res.status).toBe(200);
22 const text = await res.text();
23 expect(text).toContain("gluecron");
24 });
25
63807e5Claude26 it("GET /api/repos/:owner/:name returns 404 or 503, never 500", async () => {
fc1817aClaude27 const res = await app.request("/api/repos/nobody/nothing");
63807e5Claude28 // Without DB: 503 (db unreachable). With DB + missing repo: 404.
29 // API must degrade gracefully — 500 is NOT acceptable.
30 expect([404, 503]).toContain(res.status);
fc1817aClaude31 });
32
63807e5Claude33 it("POST /api/repos returns 400 without required fields, never 500", async () => {
fc1817aClaude34 const res = await app.request("/api/repos", {
35 method: "POST",
36 headers: { "Content-Type": "application/json" },
37 body: JSON.stringify({}),
38 });
63807e5Claude39 // Validation happens before DB access — always 400.
40 expect(res.status).toBe(400);
41 });
42
43 it("GET /api/users/:u/repos returns 404 or 503, never 500", async () => {
44 const res = await app.request("/api/users/nobody/repos");
45 expect([404, 503]).toContain(res.status);
fc1817aClaude46 });
47});
48
49describe("Git HTTP routes", () => {
50 it("returns 400 for invalid service", async () => {
51 const res = await app.request("/test/repo.git/info/refs?service=invalid");
52 expect(res.status).toBe(400);
53 });
54
55 it("returns 404 for non-existent repo", async () => {
56 const res = await app.request(
57 "/nobody/nothing.git/info/refs?service=git-upload-pack"
58 );
59 expect(res.status).toBe(404);
60 });
61});