From 6079515f6cea5313ad4bfd94c00abccf23525bfe Mon Sep 17 00:00:00 2001 From: David McIntosh <804610+mctofu@users.noreply.github.com> Date: Tue, 31 Oct 2023 23:44:37 +0000 Subject: [PATCH] Add a unit test for retries --- __tests__/api_client.test.ts | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/__tests__/api_client.test.ts b/__tests__/api_client.test.ts index 0a0aa92..5d3d8f0 100644 --- a/__tests__/api_client.test.ts +++ b/__tests__/api_client.test.ts @@ -81,6 +81,49 @@ describe('ApiClient', () => { ) }) + test('job details retries on 500', async () => { + mockHttpClient.getJson.mockRejectedValueOnce( + new HttpClientError('retryable failure', 500) + ) + + const apiResponse = { + data: { + id: '1001', + type: 'update-jobs', + attributes: { + 'allowed-updates': [ + { + 'dependency-type': 'direct', + 'update-type': 'all' + } + ], + dependencies: null, + 'package-manager': 'npm_and_yarn' + } + } + } + mockHttpClient.getJson.mockResolvedValue({ + statusCode: 200, + result: apiResponse + }) + + const jobDetails = await api.getJobDetails() + expect(jobDetails['allowed-updates'].length).toBe(1) + expect(jobDetails['package-manager']).toBe('npm_and_yarn') + }) + + test('job details gives up on too many 500s', async () => { + mockHttpClient.getJson.mockRejectedValue( + new HttpClientError('retryable failure', 500) + ) + + await expect(api.getJobDetails()).rejects.toThrowError( + new JobDetailsFetchingError( + 'fetching job details: unexpected status code: 500: retryable failure' + ) + ) + }, 10000) + test('get job credentials', async () => { const apiResponse = { data: {