diff --git a/src/utils/__snapshots__/api-requests.test.ts.snap b/src/utils/__snapshots__/api-requests.test.ts.snap index 3283b8769..86a0ee8e5 100644 --- a/src/utils/__snapshots__/api-requests.test.ts.snap +++ b/src/utils/__snapshots__/api-requests.test.ts.snap @@ -8,6 +8,14 @@ exports[`apiRequest should make a request with the correct parameters 1`] = ` } `; +exports[`apiRequest should make a request with the correct parameters and default data 1`] = ` +{ + "Accept": "application/json", + "Cache-Control": "no-cache", + "Content-Type": "application/json", +} +`; + exports[`apiRequestAuth should make an authenticated request with the correct parameters 1`] = ` { "Accept": "application/json", @@ -16,3 +24,12 @@ exports[`apiRequestAuth should make an authenticated request with the correct pa "Content-Type": "application/json", } `; + +exports[`apiRequestAuth should make an authenticated request with the correct parameters and default data 1`] = ` +{ + "Accept": "application/json", + "Authorization": "token yourAuthToken", + "Cache-Control": "no-cache", + "Content-Type": "application/json", +} +`; diff --git a/src/utils/api-requests.test.ts b/src/utils/api-requests.test.ts index 635588258..9bb716488 100644 --- a/src/utils/api-requests.test.ts +++ b/src/utils/api-requests.test.ts @@ -3,10 +3,11 @@ import { apiRequest, apiRequestAuth } from './api-requests'; jest.mock('axios'); +const url = 'https://example.com'; +const method = 'get'; + describe('apiRequest', () => { it('should make a request with the correct parameters', async () => { - const url = 'https://example.com'; - const method = 'get'; const data = { key: 'value' }; await apiRequest(url, method, data); @@ -19,13 +20,25 @@ describe('apiRequest', () => { expect(axios.defaults.headers.common).toMatchSnapshot(); }); + + it('should make a request with the correct parameters and default data', async () => { + const data = {}; + await apiRequest(url, method); + + expect(axios).toHaveBeenCalledWith({ + method, + url, + data, + }); + + expect(axios.defaults.headers.common).toMatchSnapshot(); + }); }); describe('apiRequestAuth', () => { + const token = 'yourAuthToken'; + it('should make an authenticated request with the correct parameters', async () => { - const url = 'https://example.com'; - const method = 'get'; - const token = 'yourAuthToken'; const data = { key: 'value' }; await apiRequestAuth(url, method, token, data); @@ -38,4 +51,18 @@ describe('apiRequestAuth', () => { expect(axios.defaults.headers.common).toMatchSnapshot(); }); + + it('should make an authenticated request with the correct parameters and default data', async () => { + const data = {}; + + await apiRequestAuth(url, method, token); + + expect(axios).toHaveBeenCalledWith({ + method, + url, + data, + }); + + expect(axios.defaults.headers.common).toMatchSnapshot(); + }); });