Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/utils/__snapshots__/api-requests.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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",
}
`;
41 changes: 41 additions & 0 deletions src/utils/api-requests.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});