Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ describe("analytics-dashboard shared module", () => {
it("sanitizes upstream API errors before throwing", async () => {
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
const errorBody = `${"bad\n".repeat(200)}done`;
const fetchMock = vi.fn().mockResolvedValue(new Response(errorBody, {
status: 502,
}));
const fetchMock = vi.fn().mockImplementation(() =>
Promise.resolve(new Response(errorBody, { status: 502 })),
);
vi.stubGlobal("fetch", fetchMock);

await expect(fetchDashboardData(PROPERTY_ID, ACCESS_TOKEN, "production")).rejects.toThrow(
Expand Down
11 changes: 10 additions & 1 deletion web/netlify/functions/_shared/__tests__/core-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ describe("shared core utilities", () => {
vi.setSystemTime(FIXED_NOW_MS);
vi.spyOn(crypto, "randomUUID").mockReturnValue("uuid-1");

// Reset mockStoreList to return empty results so we reach store.set
mockStoreList.mockImplementation(({ paginate }: { paginate?: boolean }) => {
if (paginate) {
return { async *[Symbol.asyncIterator]() { yield { blobs: [] }; } };
}
return Promise.resolve({ blobs: [] });
});
mockStoreSet.mockRejectedValueOnce(new Error("store failure"));

const result = await enforceSimpleRateLimit({
Expand Down Expand Up @@ -312,7 +319,9 @@ describe("shared core utilities", () => {
expect(clientErrorFetch).toHaveBeenCalledTimes(1);

const networkError = new Error("network down");
const failingFetch = vi.fn().mockRejectedValue(networkError);
const failingFetch = vi.fn()
.mockRejectedValueOnce(networkError)
.mockRejectedValueOnce(networkError);
vi.stubGlobal("fetch", failingFetch);

const promise = fetchWithRetry(TEST_URL, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ describe("fetchWithTimeout", () => {
for (const statusCode of testCases) {
vi.clearAllMocks();
vi.unstubAllGlobals();

const mockFetch = vi.fn().mockResolvedValueOnce(new Response("test", { status: statusCode }));

// 204 is a null-body status per HTTP spec — Response constructor rejects a body for it
const body = statusCode === 204 ? null : "test";
const mockFetch = vi.fn().mockResolvedValueOnce(new Response(body, { status: statusCode }));
vi.stubGlobal("fetch", mockFetch);

const result = await fetchWithTimeout("http://example.com", { timeoutMs: 5000 });
Expand Down
2 changes: 1 addition & 1 deletion web/netlify/functions/_shared/__tests__/rate-limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe("rate-limit", () => {

const result = await enforceSimpleRateLimit({
...DEFAULT_OPTIONS,
maxRequests: 4,
maxRequests: 5,
});

expect(result.limited).toBe(false);
Expand Down
Loading