-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.test.ts
More file actions
82 lines (70 loc) · 2.6 KB
/
Copy pathgithub.test.ts
File metadata and controls
82 lines (70 loc) · 2.6 KB
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
import { describe, it, expect, vi, afterEach } from "vitest";
import { GitHubError, RateLimitError, NotFoundError } from "../errors.js";
// Validate error class hierarchy and messages
describe("GitHubError", () => {
it("stores statusCode and endpoint", () => {
const err = new GitHubError("bad request", 400, "/repos/foo");
expect(err.statusCode).toBe(400);
expect(err.endpoint).toBe("/repos/foo");
expect(err.name).toBe("GitHubError");
});
});
describe("NotFoundError", () => {
it("sets status 404 and includes resource in message", () => {
const err = new NotFoundError("TMHSDigital/steam-mcp");
expect(err.statusCode).toBe(404);
expect(err.message).toContain("TMHSDigital/steam-mcp");
expect(err instanceof GitHubError).toBe(true);
});
});
describe("RateLimitError", () => {
it("sets status 429 and mentions GH_TOKEN", () => {
const err = new RateLimitError();
expect(err.statusCode).toBe(429);
expect(err.message).toContain("GH_TOKEN");
expect(err instanceof GitHubError).toBe(true);
});
});
// Validate schema helpers
describe("extractStandardsVersion", () => {
it("extracts version from HTML comment", async () => {
const { extractStandardsVersion } = await import("../github.js");
expect(
extractStandardsVersion("<!-- standards-version: 1.10.0 -->\n# CLAUDE.md"),
).toBe("1.10.0");
});
it("returns null when marker is absent", async () => {
const { extractStandardsVersion } = await import("../github.js");
expect(extractStandardsVersion("# CLAUDE.md\nNo marker here.")).toBeNull();
});
it("tolerates extra whitespace in comment", async () => {
const { extractStandardsVersion } = await import("../github.js");
expect(
extractStandardsVersion("<!-- standards-version: 1.9.5 -->"),
).toBe("1.9.5");
});
});
// Validate fetch error mapping
describe("githubFetch error mapping", () => {
afterEach(() => {
vi.restoreAllMocks();
});
it("throws NotFoundError on 404", async () => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({ ok: false, status: 404, json: async () => ({}) }),
);
const { githubFetch } = await import("../github.js");
await expect(githubFetch("/repos/x/y")).rejects.toThrow(NotFoundError);
vi.unstubAllGlobals();
});
it("throws RateLimitError on 429", async () => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({ ok: false, status: 429, json: async () => ({}) }),
);
const { githubFetch } = await import("../github.js");
await expect(githubFetch("/repos/x/y")).rejects.toThrow(RateLimitError);
vi.unstubAllGlobals();
});
});