-
Notifications
You must be signed in to change notification settings - Fork 783
Test api calls #746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Test api calls #746
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
71f5d14
test(__tests__/tests/api/index.js): Set up api tests
etcetera8 c5260ce
test(__tests__/tests/api/index.js): Add expected response object test
jjlljj 9fd25f7
test(__tests_/tests/api/index.js): Add v3.parameters test
15006f7
test(__tests__/tests/api/index.js): Add v3 count tests
etcetera8 3237c19
test(__tests__/tests/api/index.js): Add v3 delete tests
7cce99b
test(__tests__/tests/api/index.js): Resolve merge conflicts
2b424cc
chore(none): Update contributors
jjlljj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,140 @@ | ||
import { v3 } from '../../../src/api'; | ||
import { open } from '../../data/api/pull-request'; | ||
import { notification } from '../../data/api/notification'; | ||
|
||
describe('API v3 test', () => { | ||
describe('v3 call', () => { | ||
beforeEach(() => { | ||
global.fetch = jest.fn().mockImplementation(() => | ||
Promise.resolve({ | ||
status: 200, | ||
json: () => Promise.resolve(open), | ||
}) | ||
); | ||
}); | ||
|
||
it('should call fetch with the expected params', () => { | ||
const expectedUrl = 'https://api.github.com'; | ||
const expectedParams = 'parameters'; | ||
expect(global.fetch).not.toHaveBeenCalled(); | ||
v3.call('https://api.github.com', 'parameters'); | ||
expect(global.fetch).toHaveBeenCalledWith(expectedUrl, expectedParams); | ||
}); | ||
|
||
it('should return the expected response object', async () => { | ||
const expected = open; | ||
|
||
expect( | ||
await v3.call('https://api.github.com', 'parameters') | ||
).resolves.toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('v3 parameters', () => { | ||
const accessToken = '12345abcdef98765432'; | ||
|
||
it('should return the expected default params object', () => { | ||
const expected = { | ||
headers: { | ||
Accept: 'application/vnd.github.v3+json', | ||
Authorization: 'token 12345abcdef98765432', | ||
'Cache-Control': 'no-cache', | ||
}, | ||
method: 'GET', | ||
}; | ||
|
||
expect(v3.parameters(accessToken)).toEqual(expected); | ||
}); | ||
|
||
it('should return the expected params object when called with args', () => { | ||
const mercyPreview = 'application/vnd.github.mercy-preview+json'; | ||
const body = { | ||
client_id: '1234', | ||
client_secret: 'abc1234', | ||
code: '001', | ||
state: 'state string', | ||
}; | ||
const expected = { | ||
headers: { | ||
Accept: 'application/vnd.github.mercy-preview+json', | ||
Authorization: 'token 12345abcdef98765432', | ||
'Cache-Control': 'no-cache', | ||
}, | ||
body: | ||
'{"client_id":"1234","client_secret":"abc1234","code":"001","state":"state string"}', | ||
method: 'POST', | ||
}; | ||
|
||
expect(v3.parameters(accessToken, 'POST', mercyPreview, body)).toEqual( | ||
expected | ||
); | ||
}); | ||
}); | ||
|
||
describe('v3 count', () => { | ||
const accessToken = '12345abcdef98765432'; | ||
|
||
beforeEach(() => { | ||
global.fetch = jest.fn().mockImplementation(() => | ||
Promise.resolve({ | ||
status: 200, | ||
json: () => Promise.resolve([notification]), | ||
headers: { | ||
get: jest.fn().mockImplementation(() => null), | ||
}, | ||
}) | ||
); | ||
}); | ||
|
||
it('should be called with expected url and accessToken params', () => { | ||
const expectedUrl = 'https://api.github.com?per_page=1'; | ||
const expectedBody = v3.parameters(accessToken); | ||
v3.count('https://api.github.com', accessToken); | ||
|
||
expect(global.fetch).toHaveBeenCalledWith(expectedUrl, expectedBody); | ||
}); | ||
|
||
it('should return number', async () => { | ||
expect(await v3.count('https://api.github.com', accessToken)).toEqual(1); | ||
}); | ||
}); | ||
|
||
describe('v3 delete', () => { | ||
const accessToken = '12345abcdef98765432'; | ||
|
||
beforeEach(() => { | ||
global.fetch = jest.fn().mockImplementation(() => | ||
Promise.resolve({ | ||
status: 200, | ||
json: () => Promise.resolve('successful response'), | ||
}) | ||
); | ||
}); | ||
|
||
it('should call fetch with the expected params', () => { | ||
const expectedUrl = 'https://api.github.com'; | ||
const expected = { | ||
headers: { | ||
Accept: 'application/vnd.github.v3+json', | ||
Authorization: 'token 12345abcdef98765432', | ||
'Cache-Control': 'no-cache', | ||
}, | ||
method: 'DELETE', | ||
}; | ||
|
||
expect(global.fetch).not.toHaveBeenCalled(); | ||
|
||
v3.delete('https://api.github.com', accessToken); | ||
|
||
expect(global.fetch).toHaveBeenCalledWith(expectedUrl, expected); | ||
}); | ||
|
||
it('should return expected response', () => { | ||
const expected = 'successful response'; | ||
|
||
expect(v3.delete('https://api.github.com', accessToken)).resolves.toEqual( | ||
expected | ||
); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to the family everyone 😊