Skip to content
Merged
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
Loading