Skip to content

Commit d729938

Browse files
committed
test: add resolveEventInOrg tests for events API coverage
Add 3 tests for resolveEventInOrg from src/lib/api/events.ts (lines 97-122): - returns resolved event (org, project) on successful 200 response - returns null for 404 (event not in this org — expected non-error case) - propagates other errors (500, etc.) as thrown exceptions
1 parent ce0b5c9 commit d729938

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

test/lib/api/events.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,55 @@ describe("listIssueEvents", () => {
141141
expect(capturedUrl).toContain("end=");
142142
});
143143
});
144+
145+
// ---------------------------------------------------------------------------
146+
// resolveEventInOrg
147+
// ---------------------------------------------------------------------------
148+
149+
import { resolveEventInOrg } from "../../../src/lib/api/events.js";
150+
151+
describe("resolveEventInOrg", () => {
152+
test("returns resolved event on success", async () => {
153+
globalThis.fetch = mockFetch(
154+
async () =>
155+
new Response(
156+
JSON.stringify({
157+
organizationSlug: "test-org",
158+
projectSlug: "test-project",
159+
event: { eventID: "abc123", title: "Error" },
160+
}),
161+
{ status: 200, headers: { "Content-Type": "application/json" } }
162+
)
163+
);
164+
165+
const result = await resolveEventInOrg("test-org", "abc123");
166+
expect(result).not.toBeNull();
167+
expect(result?.org).toBe("test-org");
168+
expect(result?.project).toBe("test-project");
169+
});
170+
171+
test("returns null on 404 (event not in this org)", async () => {
172+
globalThis.fetch = mockFetch(
173+
async () =>
174+
new Response(JSON.stringify({ detail: "Not found" }), {
175+
status: 404,
176+
headers: { "Content-Type": "application/json" },
177+
})
178+
);
179+
180+
const result = await resolveEventInOrg("test-org", "nonexistent");
181+
expect(result).toBeNull();
182+
});
183+
184+
test("propagates non-404 errors", async () => {
185+
globalThis.fetch = mockFetch(
186+
async () =>
187+
new Response(JSON.stringify({ detail: "Server error" }), {
188+
status: 500,
189+
headers: { "Content-Type": "application/json" },
190+
})
191+
);
192+
193+
await expect(resolveEventInOrg("test-org", "event-id")).rejects.toThrow();
194+
});
195+
});

0 commit comments

Comments
 (0)