Skip to content

Commit

Permalink
fix: improve the fetch handling (and testing) of requests to the Clou…
Browse files Browse the repository at this point in the history
…dflare API
  • Loading branch information
petebacondarwin committed Jan 7, 2022
1 parent 6b4cb78 commit 2f7e1b2
Show file tree
Hide file tree
Showing 14 changed files with 696 additions and 226 deletions.
17 changes: 17 additions & 0 deletions .changeset/modern-books-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"wrangler": patch
---

Refactor raw value extraction from Cloudflare APIs

Most API responses are JSON of the form:

```
{ result, success, errors, messages, result_info }
```

where the `result` contains the actual response value.

But some API responses only contain the result value.

This change refactors the client-side fetch API to allow callers to specify what kind of response they expect.
9 changes: 9 additions & 0 deletions .changeset/thick-beans-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

Fix pagination handling of list requests to the Cloudflare API

When doing a list request to the API, the server may respond with only a single page of results.
In this case, it will also provide a `cursor` value in the `result_info` part of the response, which can be used to request the next page.
This change implements this on the client-side so that we get all the results by requesting further pages when there is a cursor.
6 changes: 5 additions & 1 deletion packages/wrangler/src/__tests__/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { mockFetchInternal } from "./mock-cfetch";
import { confirm, prompt } from "../dialogs";
import { fetchInternal } from "../cfetch/internal";

jest.mock("../cfetch/internal");
(fetchInternal as jest.Mock).mockImplementation(mockFetchInternal);

jest.mock("../cfetch", () => jest.requireActual("./mock-cfetch"));
jest.mock("../dialogs");

// By default (if not configured by mockConfirm()) calls to `confirm()` should throw.
Expand Down
Loading

0 comments on commit 2f7e1b2

Please sign in to comment.