Skip to content

Commit

Permalink
Use tries on all API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Hadka committed May 10, 2020
1 parent a8b6132 commit c8d75a8
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 132 deletions.
30 changes: 20 additions & 10 deletions __tests__/cacheHttpsClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,17 @@ function handleResponse(

async function testRetryExpectingResult(
responses: Array<TestResponse>,
expectedResult: string
expectedResult: string | null
): Promise<void> {
responses = responses.reverse(); // Reverse responses since we pop from end

const actualResult = await retry(
"test",
() => handleResponse(responses.pop()),
(response: TestResponse) => response.statusCode,
(response: TestResponse) => response.result,
(statusCode: number) => statusCode === 200,
(statusCode: number) => statusCode === 503
(response: TestResponse) => response.statusCode
);

expect(actualResult).toEqual(expectedResult);
expect(actualResult.result).toEqual(expectedResult);
}

async function testRetryExpectingError(
Expand All @@ -84,10 +81,7 @@ async function testRetryExpectingError(
retry(
"test",
() => handleResponse(responses.pop()),
(response: TestResponse) => response.statusCode,
(response: TestResponse) => response.result,
(statusCode: number) => statusCode === 200,
(statusCode: number) => statusCode === 503
(response: TestResponse) => response.statusCode
)
).rejects.toBeInstanceOf(Error);
}
Expand Down Expand Up @@ -165,3 +159,19 @@ test("retry works after error", async () => {
"Ok"
);
});

test("retry returns after client error", async () => {
await testRetryExpectingResult(
[
{
statusCode: 400,
result: null
},
{
statusCode: 200,
result: "Ok"
}
],
null
);
});
Loading

0 comments on commit c8d75a8

Please sign in to comment.