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
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
api-v2.test.ts21.4 KB · 644 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
import { describe, it, expect, beforeAll, afterAll } from "bun:test";
import { join } from "path";
import { rm, mkdir } from "fs/promises";
import app from "../app";
import { clearRateLimitStore } from "../middleware/rate-limit";

const TEST_REPOS = join(import.meta.dir, "../../.test-repos-api-v2");

beforeAll(async () => {
  process.env.GIT_REPOS_PATH = TEST_REPOS;
  process.env.DATABASE_URL = process.env.DATABASE_URL || "";
  clearRateLimitStore();
  await mkdir(TEST_REPOS, { recursive: true });
});

afterAll(async () => {
  await rm(TEST_REPOS, { recursive: true, force: true });
});

// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------

function apiUrl(path: string): string {
  if (path === "/") return "/api/v2";
  return `/api/v2${path}`;
}

function jsonHeaders(extra: Record<string, string> = {}): Record<string, string> {
  return { "Content-Type": "application/json", ...extra };
}

function bearerHeader(token: string): Record<string, string> {
  return { Authorization: `Bearer ${token}` };
}

// ---------------------------------------------------------------------------
// 1. API Info endpoint
// ---------------------------------------------------------------------------

describe("API v2 - Info endpoint", () => {
  it("GET /api/v2/ returns 200 with JSON listing all endpoints", async () => {
    const res = await app.request(apiUrl("/"));
    expect(res.status).toBe(200);

    const body = await res.json();
    expect(body.name).toBe("gluecron API");
    expect(body.version).toBe("2.0");
    expect(body.endpoints).toBeDefined();
    expect(body.endpoints.users).toBeDefined();
    expect(body.endpoints.repositories).toBeDefined();
    expect(body.endpoints.branches).toBeDefined();
    expect(body.endpoints.commits).toBeDefined();
    expect(body.endpoints.files).toBeDefined();
    expect(body.endpoints.issues).toBeDefined();
    expect(body.endpoints.pullRequests).toBeDefined();
    expect(body.endpoints.stars).toBeDefined();
    expect(body.endpoints.labels).toBeDefined();
    expect(body.endpoints.search).toBeDefined();
    expect(body.endpoints.topics).toBeDefined();
    expect(body.endpoints.webhooks).toBeDefined();
    expect(body.endpoints.activity).toBeDefined();
    expect(body.authentication).toBeDefined();
    expect(body.rateLimit).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// 2. User endpoints
// ---------------------------------------------------------------------------

describe("API v2 - User endpoints", () => {
  it("GET /api/v2/user without auth returns 401", async () => {
    const res = await app.request(apiUrl("/user"));
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("GET /api/v2/users/nobody returns 404 or 500 (no DB)", async () => {
    const res = await app.request(apiUrl("/users/nobody"));
    expect([404, 500]).toContain(res.status);
  });
});

// ---------------------------------------------------------------------------
// 3. Repository endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Repository endpoints", () => {
  it("POST /api/v2/repos without auth returns 401", async () => {
    const res = await app.request(apiUrl("/repos"), {
      method: "POST",
      headers: jsonHeaders(),
      body: JSON.stringify({ name: "test-repo" }),
    });
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("GET /api/v2/repos/nobody/nothing returns 404 or 500 (no DB)", async () => {
    const res = await app.request(apiUrl("/repos/nobody/nothing"));
    expect([404, 500]).toContain(res.status);
  });

  it("PATCH /api/v2/repos/nobody/nothing without auth returns 401", async () => {
    const res = await app.request(apiUrl("/repos/nobody/nothing"), {
      method: "PATCH",
      headers: jsonHeaders(),
      body: JSON.stringify({ description: "updated" }),
    });
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("DELETE /api/v2/repos/nobody/nothing without auth returns 401", async () => {
    const res = await app.request(apiUrl("/repos/nobody/nothing"), {
      method: "DELETE",
    });
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// 4. Branch endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Branch endpoints", () => {
  it("GET /api/v2/repos/nobody/nothing/branches returns 404 or 500", async () => {
    const res = await app.request(apiUrl("/repos/nobody/nothing/branches"));
    expect([404, 500]).toContain(res.status);
  });
});

// ---------------------------------------------------------------------------
// 5. Commit endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Commit endpoints", () => {
  it("GET /api/v2/repos/nobody/nothing/commits returns 404 or 500", async () => {
    const res = await app.request(apiUrl("/repos/nobody/nothing/commits"));
    expect([404, 500]).toContain(res.status);
  });

  it("GET /api/v2/repos/nobody/nothing/commits/abc123 returns 404 or 500", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/commits/abc123")
    );
    expect([404, 500]).toContain(res.status);
  });
});

// ---------------------------------------------------------------------------
// 6. Tree / File endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Tree and File endpoints", () => {
  it("GET /api/v2/repos/nobody/nothing/tree/main returns 404 or 500", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/tree/main")
    );
    expect([404, 500]).toContain(res.status);
  });

  it("GET /api/v2/repos/nobody/nothing/contents/README.md returns 404 or 500", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/contents/README.md")
    );
    expect([404, 500]).toContain(res.status);
  });
});

// ---------------------------------------------------------------------------
// 7. Issue endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Issue endpoints", () => {
  it("GET /api/v2/repos/nobody/nothing/issues returns 404 or 500 (no DB)", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/issues")
    );
    expect([404, 500]).toContain(res.status);
  });

  it("POST /api/v2/repos/nobody/nothing/issues without auth returns 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/issues"),
      {
        method: "POST",
        headers: jsonHeaders(),
        body: JSON.stringify({ title: "Bug report" }),
      }
    );
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// 8. Pull Request endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Pull Request endpoints", () => {
  it("GET /api/v2/repos/nobody/nothing/pulls returns 404 or 500 (no DB)", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/pulls")
    );
    expect([404, 500]).toContain(res.status);
  });

  it("POST /api/v2/repos/nobody/nothing/pulls without auth returns 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/pulls"),
      {
        method: "POST",
        headers: jsonHeaders(),
        body: JSON.stringify({
          title: "Feature branch",
          baseBranch: "main",
          headBranch: "feature",
        }),
      }
    );
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// 9. Star endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Star endpoints", () => {
  it("PUT /api/v2/repos/nobody/nothing/star without auth returns 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/star"),
      { method: "PUT" }
    );
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("DELETE /api/v2/repos/nobody/nothing/star without auth returns 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/star"),
      { method: "DELETE" }
    );
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// 10. Label endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Label endpoints", () => {
  it("GET /api/v2/repos/nobody/nothing/labels returns 404 or 500 (no DB)", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/labels")
    );
    expect([404, 500]).toContain(res.status);
  });

  it("POST /api/v2/repos/nobody/nothing/labels without auth returns 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/labels"),
      {
        method: "POST",
        headers: jsonHeaders(),
        body: JSON.stringify({ name: "bug", color: "#ff0000" }),
      }
    );
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// 11. Search endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Search endpoints", () => {
  it("GET /api/v2/search/repos without query returns 400", async () => {
    const res = await app.request(apiUrl("/search/repos"));
    expect(res.status).toBe(400);

    const body = await res.json();
    expect(body.error).toContain("required");
  });

  it("GET /api/v2/search/repos?q=test returns 200 or 500 (no DB)", async () => {
    const res = await app.request(apiUrl("/search/repos?q=test"));
    expect([200, 500]).toContain(res.status);
  });

  it("GET /api/v2/repos/nobody/nothing/search/code?q=test returns 404 or 500", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/search/code?q=test")
    );
    expect([404, 500]).toContain(res.status);
  });

  it("GET /api/v2/search/repos with empty q returns 400", async () => {
    const res = await app.request(apiUrl("/search/repos?q="));
    expect(res.status).toBe(400);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("GET /api/v2/repos/nobody/nothing/search/code without q returns 400", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/search/code")
    );
    expect(res.status).toBe(400);

    const body = await res.json();
    expect(body.error).toContain("required");
  });
});

// ---------------------------------------------------------------------------
// 12. Topic endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Topic endpoints", () => {
  it("GET /api/v2/repos/nobody/nothing/topics returns 404 or 500 (no DB)", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/topics")
    );
    expect([404, 500]).toContain(res.status);
  });

  it("PUT /api/v2/repos/nobody/nothing/topics without auth returns 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/topics"),
      {
        method: "PUT",
        headers: jsonHeaders(),
        body: JSON.stringify({ topics: ["javascript", "web"] }),
      }
    );
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// 13. Webhook endpoints
// ---------------------------------------------------------------------------

describe("API v2 - Webhook endpoints", () => {
  it("GET /api/v2/repos/nobody/nothing/webhooks without auth returns 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/webhooks")
    );
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("POST /api/v2/repos/nobody/nothing/webhooks without auth returns 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/webhooks"),
      {
        method: "POST",
        headers: jsonHeaders(),
        body: JSON.stringify({ url: "https://example.com/hook" }),
      }
    );
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// 14. Activity endpoint
// ---------------------------------------------------------------------------

describe("API v2 - Activity endpoint", () => {
  it("GET /api/v2/repos/nobody/nothing/activity returns 404 or 500 (no DB)", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/activity")
    );
    expect([404, 500]).toContain(res.status);
  });
});

// ---------------------------------------------------------------------------
// 15. Rate limiting
// ---------------------------------------------------------------------------

describe("API v2 - Rate limiting", () => {
  it("responses include X-RateLimit-Limit header", async () => {
    const res = await app.request(apiUrl("/"));
    expect(res.status).toBe(200);

    const limitHeader = res.headers.get("X-RateLimit-Limit");
    expect(limitHeader).toBeDefined();
    expect(limitHeader).not.toBeNull();
    expect(parseInt(limitHeader!)).toBeGreaterThan(0);
  });

  it("responses include X-RateLimit-Remaining header", async () => {
    const res = await app.request(apiUrl("/"));
    expect(res.status).toBe(200);

    const remainingHeader = res.headers.get("X-RateLimit-Remaining");
    expect(remainingHeader).toBeDefined();
    expect(remainingHeader).not.toBeNull();
    expect(parseInt(remainingHeader!)).toBeGreaterThanOrEqual(0);
  });

  it("responses include X-RateLimit-Reset header", async () => {
    const res = await app.request(apiUrl("/"));
    expect(res.status).toBe(200);

    const resetHeader = res.headers.get("X-RateLimit-Reset");
    expect(resetHeader).toBeDefined();
    expect(resetHeader).not.toBeNull();
    expect(parseInt(resetHeader!)).toBeGreaterThan(0);
  });
});

// ---------------------------------------------------------------------------
// 16. Invalid Bearer token
// ---------------------------------------------------------------------------

describe("API v2 - Invalid Bearer token", () => {
  it("GET /api/v2/user with invalid Bearer token returns 401", async () => {
    const res = await app.request(apiUrl("/user"), {
      headers: bearerHeader("invalid-token-that-does-not-exist"),
    });
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("GET /api/v2/user with malformed Bearer header returns 401", async () => {
    const res = await app.request(apiUrl("/user"), {
      headers: bearerHeader(""),
    });
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// 17. JSON content type
// ---------------------------------------------------------------------------

describe("API v2 - JSON content type", () => {
  it("API info endpoint returns application/json", async () => {
    const res = await app.request(apiUrl("/"));
    expect(res.status).toBe(200);

    const contentType = res.headers.get("Content-Type");
    expect(contentType).toBeDefined();
    expect(contentType!).toContain("application/json");
  });

  it("401 responses return application/json", async () => {
    const res = await app.request(apiUrl("/user"));
    expect(res.status).toBe(401);

    const contentType = res.headers.get("Content-Type");
    expect(contentType).toBeDefined();
    expect(contentType!).toContain("application/json");
  });

  it("400 responses return application/json", async () => {
    const res = await app.request(apiUrl("/search/repos"));
    expect(res.status).toBe(400);

    const contentType = res.headers.get("Content-Type");
    expect(contentType).toBeDefined();
    expect(contentType!).toContain("application/json");
  });
});

// ---------------------------------------------------------------------------
// 18. Validation - POST /api/v2/repos with auth header but no body fields
// ---------------------------------------------------------------------------

describe("API v2 - Repo creation validation", () => {
  it("POST /api/v2/repos with auth header but no body returns 400 or 401", async () => {
    const res = await app.request(apiUrl("/repos"), {
      method: "POST",
      headers: jsonHeaders(bearerHeader("fake-token-for-validation-test")),
      body: JSON.stringify({}),
    });
    // Without a valid token the auth middleware rejects first (401),
    // but if auth somehow passes, missing name would be 400.
    expect([400, 401]).toContain(res.status);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("POST /api/v2/repos with invalid repo name format should return 400 or 401", async () => {
    const res = await app.request(apiUrl("/repos"), {
      method: "POST",
      headers: jsonHeaders(bearerHeader("fake-token")),
      body: JSON.stringify({ name: "invalid repo name with spaces!" }),
    });
    // Auth rejects first (401), but validates the pattern is checked
    expect([400, 401]).toContain(res.status);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// 19. Issue validation - POST issue without title
// ---------------------------------------------------------------------------

describe("API v2 - Issue creation validation", () => {
  it("POST issue without title returns 400 or 401 (auth blocks first without DB)", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/issues"),
      {
        method: "POST",
        headers: jsonHeaders(bearerHeader("fake-token")),
        body: JSON.stringify({ body: "Issue body without title" }),
      }
    );
    // Auth middleware rejects invalid tokens (401).
    // With valid auth, missing title would produce 400.
    expect([400, 401]).toContain(res.status);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("POST issue with empty title returns 400 or 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/issues"),
      {
        method: "POST",
        headers: jsonHeaders(bearerHeader("fake-token")),
        body: JSON.stringify({ title: "", body: "Some body" }),
      }
    );
    expect([400, 401]).toContain(res.status);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});

// ---------------------------------------------------------------------------
// Additional edge cases
// ---------------------------------------------------------------------------

describe("API v2 - Additional edge cases", () => {
  it("GET /api/v2/users/:username/repos returns 404 or 500 for nonexistent user", async () => {
    const res = await app.request(apiUrl("/users/nobody/repos"));
    expect([404, 500]).toContain(res.status);
  });

  it("PATCH /api/v2/user without auth returns 401", async () => {
    const res = await app.request(apiUrl("/user"), {
      method: "PATCH",
      headers: jsonHeaders(),
      body: JSON.stringify({ displayName: "New Name" }),
    });
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("GET /api/v2/repos/nobody/nothing/issues/1 returns 404 or 500 (no DB)", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/issues/1")
    );
    expect([404, 500]).toContain(res.status);
  });

  it("GET /api/v2/repos/nobody/nothing/pulls/1 returns 404 or 500 (no DB)", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/pulls/1")
    );
    expect([404, 500]).toContain(res.status);
  });

  it("PATCH /api/v2/repos/nobody/nothing/issues/1 without auth returns 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/issues/1"),
      {
        method: "PATCH",
        headers: jsonHeaders(),
        body: JSON.stringify({ state: "closed" }),
      }
    );
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });

  it("POST /api/v2/repos/nobody/nothing/issues/1/comments without auth returns 401", async () => {
    const res = await app.request(
      apiUrl("/repos/nobody/nothing/issues/1/comments"),
      {
        method: "POST",
        headers: jsonHeaders(),
        body: JSON.stringify({ body: "A comment" }),
      }
    );
    expect(res.status).toBe(401);

    const body = await res.json();
    expect(body.error).toBeDefined();
  });
});