Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Add assertHttpRequest to test
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodepixi committed Feb 9, 2021
1 parent 245d208 commit db71552
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/clients/graphql/test/graphql_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ describe('GraphQL client', () => {
fetchMock.mockResponseOnce(JSON.stringify(expectedResponse));

await expect(client.query({data: queryWithVariables})).resolves.toEqual(buildExpectedResponse(expectedResponse));

assertHttpRequest(
'POST',
DOMAIN,
'/admin/api/unstable/graphql.json',
{'Content-Length': 219, 'Content-Type': 'application/json', 'X-Shopify-Access-Token': 'bork'},
JSON.stringify(queryWithVariables),
);
});
});

Expand Down
18 changes: 8 additions & 10 deletions src/clients/http_client/test/test_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ export function assertHttpRequest(
const maxCall = currentCall + tries;
for (let i = currentCall; i < maxCall; i++) {
currentCall++;
expect(fetchMock.mock.calls[i]).toEqual(
[
`https://${domain}${path}`,
expect.objectContaining({
method,
headers: expect.objectContaining(headers),
body: data,
}),
],
);
expect(fetchMock.mock.calls[i]).toEqual([
`https://${domain}${path}`,
expect.objectContaining({
method,
headers: expect.objectContaining(headers),
body: data,
}),
]);
}
}

0 comments on commit db71552

Please sign in to comment.