-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |