Skip to content

Commit

Permalink
Add test for doRequest new options
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannmoinet committed Feb 18, 2025
1 parent 80c1165 commit 0fc5b1e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/tests/src/unit/core/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ describe('Core Helpers', () => {
expect(scope.isDone()).toBe(true);
});

test('Should respect retry options.', async () => {
const { doRequest } = await import('@dd/core/helpers');
const onRetryMock = jest.fn();
const scope = nock(FAKE_URL)
.post(API_PATH)
.reply(500, 'Internal Server Error')
.post(API_PATH)
.reply(200, { data: 'ok' });

// TODO: Test maxTimeout and minTimeout
await doRequest({ ...requestOpts, retries: 2, onRetry: onRetryMock });

expect(onRetryMock).toHaveBeenCalledTimes(1);
expect(scope.isDone()).toBe(true);
});

test('Should bail on specific status', async () => {
const { doRequest } = await import('@dd/core/helpers');
const scope = nock(FAKE_URL).post(API_PATH).reply(400, 'Bad Request');
Expand Down

0 comments on commit 0fc5b1e

Please sign in to comment.