|
4 | 4 | import { createClient } from "../index" |
5 | 5 | import { OrgIdToOrgMemberInfo } from "../org" |
6 | 6 | import { ok, ResponseStatus, setupMockFetch, UnauthorizedResponse, UnknownErrorResponse } from "./mockfetch.test" |
| 7 | +import {DEFAULT_RETRIES} from "../fetch_retries"; |
7 | 8 |
|
8 | 9 | const INITIAL_TIME_MILLIS = 1619743452595 |
9 | 10 | const INITIAL_TIME_SECONDS = INITIAL_TIME_MILLIS / 1000 |
10 | 11 |
|
11 | 12 | beforeAll(() => { |
12 | 13 | jest.useFakeTimers("modern") |
| 14 | + // @ts-ignore |
| 15 | + global.setTimeout = jest.fn(cb => cb()); |
13 | 16 | }) |
14 | 17 |
|
15 | 18 | beforeEach(() => { |
@@ -276,8 +279,10 @@ test("client continues to use cached value if the API fails and the value hasn't |
276 | 279 | // The API will now fail, but that failure should be logged and not effect this method |
277 | 280 | const { mockFetch: errorMockFetch } = setupMockFetchThatReturnsUnknownError() |
278 | 281 | const newAuthenticationInfo = await client.getAuthenticationInfoOrNull() |
| 282 | + |
279 | 283 | expect(newAuthenticationInfo?.accessToken).toBe(expectedAccessToken) |
280 | | - expectCorrectEndpointWasHit(errorMockFetch, "https://www.example.com/api/v1/refresh_token") |
| 284 | + const numTimesCalled = 1 + DEFAULT_RETRIES |
| 285 | + expectCorrectEndpointWasHit(errorMockFetch, "https://www.example.com/api/v1/refresh_token", numTimesCalled) |
281 | 286 | }) |
282 | 287 |
|
283 | 288 | test("client cannot use cached value if the API fails and the value has expired", async () => { |
@@ -410,6 +415,7 @@ test("if a new client is created and cannot get an access token, it should trigg |
410 | 415 |
|
411 | 416 | const post401AuthenticationInfo1 = await client1.getAuthenticationInfoOrNull() |
412 | 417 | expect(post401AuthenticationInfo1).toBeNull() |
| 418 | + jest.useRealTimers() |
413 | 419 | const post401AuthenticationInfo0 = await client0.getAuthenticationInfoOrNull() |
414 | 420 | expect(post401AuthenticationInfo0).toBeNull() |
415 | 421 |
|
|
0 commit comments