Skip to content

Commit 44aa817

Browse files
committed
Adding unit tests for github resource
1 parent 2f3764e commit 44aa817

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const Github = require('../github');
2+
3+
describe('Github Resource', () => {
4+
const fakeRequest = {
5+
get: jest.fn()
6+
};
7+
const githubResource = new Github(fakeRequest);
8+
afterEach(() => jest.clearAllMocks());
9+
10+
it('should return the followers count for a given github user', async() => {
11+
fakeRequest.get.mockResolvedValueOnce({data: {followers: 120}});
12+
13+
const response = await githubResource.getFollowerCount('waldemarnt');
14+
expect(response).toEqual({followers:120});
15+
});
16+
it('should return not found when the user doenst exist', async() => {
17+
fakeRequest.get.mockRejectedValueOnce({response: {data: 'Not Found', status: 404}});
18+
19+
const response = await githubResource.getFollowerCount('odkasodksaodk');
20+
expect(response).toEqual({error: 'Not Found'});
21+
});
22+
it('should return error when a general error happens', async() => {
23+
fakeRequest.get.mockRejectedValueOnce({response: {data: 'Error', status: 500}});
24+
25+
const response = await githubResource.getFollowerCount('waldemarnt');
26+
expect(response).toEqual({error: 'Error'});
27+
});
28+
});

0 commit comments

Comments
 (0)