Skip to content

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 7 commits into from
Mar 22, 2018
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
30 changes: 30 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,36 @@
"code",
"design"
]
},
{
"login": "jjlljj",
"name": "James Logue",
"avatar_url": "https://avatars1.githubusercontent.com/u/16650066?v=4",
"profile": "https://github.com/jjlljj",
"contributions": [
"code",
"test"
]
},
{
"login": "etcetera8",
"name": "parker lindley",
"avatar_url": "https://avatars0.githubusercontent.com/u/22607072?v=4",
"profile": "https://github.com/etcetera8",
"contributions": [
"code",
"test"
]
},
{
"login": "soytjan",
"name": "Amanda Tjan",
"avatar_url": "https://avatars2.githubusercontent.com/u/22456673?v=4",
"profile": "https://github.com/soytjan",
"contributions": [
"code",
"test"
]
Copy link
Member

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 😊

}
]
}
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ Thank you to all the people who have already contributed to GitPoint!
| [<img src="https://avatars3.githubusercontent.com/u/5467717?v=4" width="100px;"/><br /><sub><b>Serhii Baraniuk</b></sub>](https://www.facebook.com/serhii.baraniuk)<br />[⚠️](https://github.com/gitpoint/git-point/commits?author=kenitive "Tests") | [<img src="https://avatars2.githubusercontent.com/u/57701?v=4" width="100px;"/><br /><sub><b>Ben Snider</b></sub>](http://www.bensnider.com/)<br />[⚠️](https://github.com/gitpoint/git-point/commits?author=stupergenius "Tests") | [<img src="https://avatars1.githubusercontent.com/u/23706543?v=4" width="100px;"/><br /><sub><b>Simon Hoyos</b></sub>](https://www.linkedin.com/in/simonhoyos/)<br />[💻](https://github.com/gitpoint/git-point/commits?author=shmesa22 "Code") [🎨](#design-shmesa22 "Design") | [<img src="https://avatars3.githubusercontent.com/u/10438692?v=4" width="100px;"/><br /><sub><b>Damien Leroy</b></sub>](https://github.com/ShiiFu)<br />[🌍](#translation-ShiiFu "Translation") | [<img src="https://avatars1.githubusercontent.com/u/686676?v=4" width="100px;"/><br /><sub><b>botbotbot</b></sub>](http://dev.im-bot.com)<br />[⚠️](https://github.com/gitpoint/git-point/commits?author=ibotdotout "Tests") | [<img src="https://avatars1.githubusercontent.com/u/8254906?v=4" width="100px;"/><br /><sub><b>Dmytro Kytsmen</b></sub>](https://github.com/Kietzmann)<br />[🌍](#translation-Kietzmann "Translation") |
| [<img src="https://avatars0.githubusercontent.com/u/3683673?v=4" width="100px;"/><br /><sub><b>TheCodeTalker</b></sub>](https://thecodetalker.github.io/)<br />[💻](https://github.com/gitpoint/git-point/commits?author=TheCodeTalker "Code") | [<img src="https://avatars0.githubusercontent.com/u/2670744?v=4" width="100px;"/><br /><sub><b>Leonardo</b></sub>](https://github.com/LeoCp)<br />[💻](https://github.com/gitpoint/git-point/commits?author=LeoCp "Code") | [<img src="https://avatars2.githubusercontent.com/u/13105865?v=4" width="100px;"/><br /><sub><b>Stephen</b></sub>](https://github.com/coderste)<br />[📖](https://github.com/gitpoint/git-point/commits?author=coderste "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/5565340?v=4" width="100px;"/><br /><sub><b>Zahra Traboulsi</b></sub>](http://www.zahra.tech)<br />[💻](https://github.com/gitpoint/git-point/commits?author=ZahraTee "Code") [⚠️](https://github.com/gitpoint/git-point/commits?author=ZahraTee "Tests") | [<img src="https://avatars3.githubusercontent.com/u/13391685?v=4" width="100px;"/><br /><sub><b>Joseba Carral</b></sub>](http://codevs.es)<br />[🌍](#translation-jcarral "Translation") | [<img src="https://avatars2.githubusercontent.com/u/5800039?v=4" width="100px;"/><br /><sub><b>CTownsdin</b></sub>](https://github.com/CTownsdin)<br />[💻](https://github.com/gitpoint/git-point/commits?author=CTownsdin "Code") |
| [<img src="https://avatars0.githubusercontent.com/u/7470681?v=4" width="100px;"/><br /><sub><b>Apostolis Economou</b></sub>](https://github.com/apoeco)<br />[💻](https://github.com/gitpoint/git-point/commits?author=apoeco "Code") | [<img src="https://avatars3.githubusercontent.com/u/9337254?v=4" width="100px;"/><br /><sub><b>Arjun</b></sub>](https://github.com/Arjun-sna)<br />[💻](https://github.com/gitpoint/git-point/commits?author=Arjun-sna "Code") | [<img src="https://avatars1.githubusercontent.com/u/5786033?v=4" width="100px;"/><br /><sub><b>Riccardo</b></sub>](http://rkpasia.github.io)<br />[💻](https://github.com/gitpoint/git-point/commits?author=rkpasia "Code") [🎨](#design-rkpasia "Design") | [<img src="https://avatars3.githubusercontent.com/u/21980965?v=4" width="100px;"/><br /><sub><b>Luong Dang Hai</b></sub>](https://luongdanghai.com/)<br />[💻](https://github.com/gitpoint/git-point/commits?author=jarvisluong "Code") | [<img src="https://avatars3.githubusercontent.com/u/1428396?v=4" width="100px;"/><br /><sub><b>Jens Strobel</b></sub>](https://github.com/jstrobel)<br />[🐛](https://github.com/gitpoint/git-point/issues?q=author%3Ajstrobel "Bug reports") [🌍](#translation-jstrobel "Translation") | [<img src="https://avatars3.githubusercontent.com/u/3621147?v=4" width="100px;"/><br /><sub><b>James Gosbell</b></sub>](https://github.com/jamesg1)<br />[💻](https://github.com/gitpoint/git-point/commits?author=jamesg1 "Code") |
| [<img src="https://avatars1.githubusercontent.com/u/11476348?v=4" width="100px;"/><br /><sub><b>Dhanial Rizky Wira Putra</b></sub>](https://github.com/dhamanutd)<br />[💻](https://github.com/gitpoint/git-point/commits?author=dhamanutd "Code") [🎨](#design-dhamanutd "Design") |
| [<img src="https://avatars1.githubusercontent.com/u/11476348?v=4" width="100px;"/><br /><sub><b>Dhanial Rizky Wira Putra</b></sub>](https://github.com/dhamanutd)<br />[💻](https://github.com/gitpoint/git-point/commits?author=dhamanutd "Code") [🎨](#design-dhamanutd "Design") | [<img src="https://avatars1.githubusercontent.com/u/16650066?v=4" width="100px;"/><br /><sub><b>James Logue</b></sub>](https://github.com/jjlljj)<br />[💻](https://github.com/gitpoint/git-point/commits?author=jjlljj "Code") [⚠️](https://github.com/gitpoint/git-point/commits?author=jjlljj "Tests") | [<img src="https://avatars0.githubusercontent.com/u/22607072?v=4" width="100px;"/><br /><sub><b>parker lindley</b></sub>](https://github.com/etcetera8)<br />[💻](https://github.com/gitpoint/git-point/commits?author=etcetera8 "Code") [⚠️](https://github.com/gitpoint/git-point/commits?author=etcetera8 "Tests") | [<img src="https://avatars2.githubusercontent.com/u/22456673?v=4" width="100px;"/><br /><sub><b>Amanda Tjan</b></sub>](https://github.com/soytjan)<br />[💻](https://github.com/gitpoint/git-point/commits?author=soytjan "Code") [⚠️](https://github.com/gitpoint/git-point/commits?author=soytjan "Tests") |
<!-- ALL-CONTRIBUTORS-LIST:END -->
140 changes: 140 additions & 0 deletions __tests__/tests/api/index.js
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
);
});
});
});