diff --git a/.all-contributorsrc b/.all-contributorsrc index 0f3cec570..814164414 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -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" + ] } ] } diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 1b7398858..41e3f6965 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -18,5 +18,5 @@ Thank you to all the people who have already contributed to GitPoint! | [
Serhii Baraniuk](https://www.facebook.com/serhii.baraniuk)
[⚠️](https://github.com/gitpoint/git-point/commits?author=kenitive "Tests") | [
Ben Snider](http://www.bensnider.com/)
[⚠️](https://github.com/gitpoint/git-point/commits?author=stupergenius "Tests") | [
Simon Hoyos](https://www.linkedin.com/in/simonhoyos/)
[💻](https://github.com/gitpoint/git-point/commits?author=shmesa22 "Code") [🎨](#design-shmesa22 "Design") | [
Damien Leroy](https://github.com/ShiiFu)
[🌍](#translation-ShiiFu "Translation") | [
botbotbot](http://dev.im-bot.com)
[⚠️](https://github.com/gitpoint/git-point/commits?author=ibotdotout "Tests") | [
Dmytro Kytsmen](https://github.com/Kietzmann)
[🌍](#translation-Kietzmann "Translation") | | [
TheCodeTalker](https://thecodetalker.github.io/)
[💻](https://github.com/gitpoint/git-point/commits?author=TheCodeTalker "Code") | [
Leonardo](https://github.com/LeoCp)
[💻](https://github.com/gitpoint/git-point/commits?author=LeoCp "Code") | [
Stephen](https://github.com/coderste)
[📖](https://github.com/gitpoint/git-point/commits?author=coderste "Documentation") | [
Zahra Traboulsi](http://www.zahra.tech)
[💻](https://github.com/gitpoint/git-point/commits?author=ZahraTee "Code") [⚠️](https://github.com/gitpoint/git-point/commits?author=ZahraTee "Tests") | [
Joseba Carral](http://codevs.es)
[🌍](#translation-jcarral "Translation") | [
CTownsdin](https://github.com/CTownsdin)
[💻](https://github.com/gitpoint/git-point/commits?author=CTownsdin "Code") | | [
Apostolis Economou](https://github.com/apoeco)
[💻](https://github.com/gitpoint/git-point/commits?author=apoeco "Code") | [
Arjun](https://github.com/Arjun-sna)
[💻](https://github.com/gitpoint/git-point/commits?author=Arjun-sna "Code") | [
Riccardo](http://rkpasia.github.io)
[💻](https://github.com/gitpoint/git-point/commits?author=rkpasia "Code") [🎨](#design-rkpasia "Design") | [
Luong Dang Hai](https://luongdanghai.com/)
[💻](https://github.com/gitpoint/git-point/commits?author=jarvisluong "Code") | [
Jens Strobel](https://github.com/jstrobel)
[🐛](https://github.com/gitpoint/git-point/issues?q=author%3Ajstrobel "Bug reports") [🌍](#translation-jstrobel "Translation") | [
James Gosbell](https://github.com/jamesg1)
[💻](https://github.com/gitpoint/git-point/commits?author=jamesg1 "Code") | -| [
Dhanial Rizky Wira Putra](https://github.com/dhamanutd)
[💻](https://github.com/gitpoint/git-point/commits?author=dhamanutd "Code") [🎨](#design-dhamanutd "Design") | +| [
Dhanial Rizky Wira Putra](https://github.com/dhamanutd)
[💻](https://github.com/gitpoint/git-point/commits?author=dhamanutd "Code") [🎨](#design-dhamanutd "Design") | [
James Logue](https://github.com/jjlljj)
[💻](https://github.com/gitpoint/git-point/commits?author=jjlljj "Code") [⚠️](https://github.com/gitpoint/git-point/commits?author=jjlljj "Tests") | [
parker lindley](https://github.com/etcetera8)
[💻](https://github.com/gitpoint/git-point/commits?author=etcetera8 "Code") [⚠️](https://github.com/gitpoint/git-point/commits?author=etcetera8 "Tests") | [
Amanda Tjan](https://github.com/soytjan)
[💻](https://github.com/gitpoint/git-point/commits?author=soytjan "Code") [⚠️](https://github.com/gitpoint/git-point/commits?author=soytjan "Tests") | diff --git a/__tests__/tests/api/index.js b/__tests__/tests/api/index.js new file mode 100644 index 000000000..0706abbe4 --- /dev/null +++ b/__tests__/tests/api/index.js @@ -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 + ); + }); + }); +});