Skip to content

Commit

Permalink
Add unit test for correct response object when status code is over 40…
Browse files Browse the repository at this point in the history
…0 with no error response
  • Loading branch information
Mouhajer-CO committed Jan 10, 2024
1 parent 4f0e127 commit 8f35486
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions test/mock/data.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,10 @@ export const MOCK_ERROR_RESPONSE = {
httpStatusCode: 500,
errors: [MOCK_ERROR]
};

export const MOCK_403_ERROR_MSG = { "message": "Must have admin rights to Repository." };

export const MOCK_403_ERROR_RESPONSE = {
httpStatusCode: 403,
errors: [MOCK_403_ERROR_MSG]
};
14 changes: 12 additions & 2 deletions test/unit/api-sdk/github/github.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
MOCK_MEMBERS_PER_TEAM,
MOCK_MEMBERS_PER_TEAM_RESPONSE,
MOCK_REPOS_PER_TEAM,
MOCK_REPOS_PER_TEAM_RESPONSE
MOCK_REPOS_PER_TEAM_RESPONSE,
MOCK_403_ERROR_MSG,
MOCK_403_ERROR_RESPONSE
} from '../../../mock/data.mock';
import { HttpResponse } from '../../../../src/http-request/type';

Expand Down Expand Up @@ -90,7 +92,7 @@ describe('Github sdk module test suites', () => {
test('Should return an object with an error property', async () => {
httpRequestMock.httpGet.mockResolvedValue(createMockHttpResponse(MOCK_TEAMS, 500, MOCK_ERROR));

const url = 'https://api.github.com/users/test/repos';
const url = 'https://api.github.com/users/test/teams';
const result = await github.getTeams(url);
expect(result).toEqual(MOCK_ERROR_RESPONSE);
});
Expand All @@ -103,4 +105,12 @@ describe('Github sdk module test suites', () => {

expect(result).toEqual(MOCK_REPO_FETCH_RESPONSE);
});

test('Should return an object with an error property when status code is 403 with no error response', async () => {
httpRequestMock.httpGet.mockResolvedValue(createMockHttpResponse(MOCK_403_ERROR_MSG, 403));

const url = 'https://api.github.com/users/test/repos';
const result = await github.getRepos(url);
expect(result).toEqual(MOCK_403_ERROR_RESPONSE);
});
});

0 comments on commit 8f35486

Please sign in to comment.