diff --git a/src/utils/__snapshots__/api-requests.test.ts.snap b/src/utils/__snapshots__/api-requests.test.ts.snap new file mode 100644 index 000000000..3283b8769 --- /dev/null +++ b/src/utils/__snapshots__/api-requests.test.ts.snap @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`apiRequest should make a request with the correct parameters 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", + "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 new file mode 100644 index 000000000..635588258 --- /dev/null +++ b/src/utils/api-requests.test.ts @@ -0,0 +1,41 @@ +import axios from 'axios'; +import { apiRequest, apiRequestAuth } from './api-requests'; + +jest.mock('axios'); + +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); + + expect(axios).toHaveBeenCalledWith({ + method, + url, + data, + }); + + expect(axios.defaults.headers.common).toMatchSnapshot(); + }); +}); + +describe('apiRequestAuth', () => { + 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); + + expect(axios).toHaveBeenCalledWith({ + method, + url, + data, + }); + + expect(axios.defaults.headers.common).toMatchSnapshot(); + }); +});