Skip to content

Commit

Permalink
test: Add repository and organization actions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nersoh committed Nov 7, 2019
1 parent fd71727 commit eb6fd77
Show file tree
Hide file tree
Showing 4 changed files with 485 additions and 0 deletions.
97 changes: 97 additions & 0 deletions __tests__/tests/actions/organization.action.js
@@ -0,0 +1,97 @@
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import {
GET_ORG_REPOS_LOADING,
GET_ORG_REPOS_ERROR,
GET_ORG_REPOS,
} from '../../../src/organization/organization.constants';
import { fetchOrganizationRepos } from '../../../src/organization/organization.action';
import { v3 } from '../../../src/api';

const store = configureStore([thunk])({ auth: { accessToken: 'ABCXYZ' } });

jest.mock('../../../src/api', () => ({
v3: {
getJson: jest.fn(),
},
}));

describe('fetchOrganizationRepos()', () => {
afterEach(() => {
store.clearActions();
});

it('should return a success response', async () => {
const expectedData = { name: 'organization' };

v3.getJson.mockResolvedValueOnce(expectedData);
await store.dispatch(fetchOrganizationRepos(''));

expect(store.getActions()).toEqual(
expect.arrayContaining([
{
type: GET_ORG_REPOS_LOADING,
payload: true,
},
{
type: GET_ORG_REPOS_ERROR,
payload: '',
},
{
type: GET_ORG_REPOS,
payload: expectedData,
},
])
);

expect(store.getActions()).not.toEqual(
expect.arrayContaining([
{
type: GET_ORG_REPOS_LOADING,
payload: false,
},
{
type: GET_ORG_REPOS_ERROR,
payload: expectedData,
},
])
);
});

it('should return an error response', async () => {
const expectedData = { error: 'no organization' };

v3.getJson.mockRejectedValueOnce(expectedData);
await store.dispatch(fetchOrganizationRepos(''));

expect(store.getActions()).toEqual(
expect.arrayContaining([
{
type: GET_ORG_REPOS_LOADING,
payload: true,
},
{
type: GET_ORG_REPOS_LOADING,
payload: false,
},
{
type: GET_ORG_REPOS_ERROR,
payload: '',
},
{
type: GET_ORG_REPOS_ERROR,
payload: expectedData,
},
])
);

expect(store.getActions()).not.toEqual(
expect.arrayContaining([
{
type: GET_ORG_REPOS,
payload: expectedData,
},
])
);
});
});

0 comments on commit eb6fd77

Please sign in to comment.