Skip to content

Commit 00248cb

Browse files
committed
test: add tests for organization reducer (#518)
1 parent ecdde67 commit 00248cb

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
GET_ORG_REPOS,
3+
GET_ORG_REPOS_LOADING,
4+
GET_ORG_REPOS_ERROR,
5+
} from 'organization/organization.constants';
6+
import {
7+
initialState,
8+
organizationReducer,
9+
} from 'organization/organization.reducer';
10+
11+
describe('Organization Reducer', () => {
12+
it('should set initial state', () => {
13+
expect(organizationReducer(undefined, {})).toEqual(initialState);
14+
});
15+
16+
[true, false].forEach(payload => {
17+
it(`should set loading state to ${JSON.stringify(
18+
payload
19+
)} on action "GET_ORG_REPOS_LOADING"`, () => {
20+
const action = { type: GET_ORG_REPOS_LOADING, payload };
21+
const expectedState = { ...initialState, isPendingRepos: action.payload };
22+
23+
expect(organizationReducer(initialState, action)).toEqual(expectedState);
24+
});
25+
});
26+
27+
[{ id: 1 }, { id: 2 }].forEach(payload => {
28+
it('should set repos on success on action "GET_ORG_REPOS"', () => {
29+
const action = { type: GET_ORG_REPOS, payload };
30+
const expectedState = {
31+
...initialState,
32+
isPendingRepos: false,
33+
repositories: payload,
34+
};
35+
36+
expect(organizationReducer(initialState, action)).toEqual(expectedState);
37+
});
38+
});
39+
40+
it('should set error state on action "GET_ORG_REPOS_ERROR"', () => {
41+
const action = { type: GET_ORG_REPOS_ERROR, payload: 'error' };
42+
const expectedState = {
43+
...initialState,
44+
organizationRepositoriesError: action.payload,
45+
};
46+
47+
expect(organizationReducer(initialState, action)).toEqual(expectedState);
48+
});
49+
});

src/organization/organization.reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
GET_ORG_REPOS_ERROR,
77
} from './organization.constants';
88

9-
const initialState = {
9+
export const initialState = {
1010
organization: {},
1111
repositories: [],
1212
members: [],

0 commit comments

Comments
 (0)