From 00248cbc7438f657bfaba88c680aab58f708eeba Mon Sep 17 00:00:00 2001 From: Thomas Farla Date: Fri, 12 Oct 2018 07:28:21 +0200 Subject: [PATCH] test: add tests for organization reducer (#518) --- .../tests/reducers/organization.reducer.js | 49 +++++++++++++++++++ src/organization/organization.reducer.js | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 __tests__/tests/reducers/organization.reducer.js diff --git a/__tests__/tests/reducers/organization.reducer.js b/__tests__/tests/reducers/organization.reducer.js new file mode 100644 index 000000000..50a1dc0e1 --- /dev/null +++ b/__tests__/tests/reducers/organization.reducer.js @@ -0,0 +1,49 @@ +import { + GET_ORG_REPOS, + GET_ORG_REPOS_LOADING, + GET_ORG_REPOS_ERROR, +} from 'organization/organization.constants'; +import { + initialState, + organizationReducer, +} from 'organization/organization.reducer'; + +describe('Organization Reducer', () => { + it('should set initial state', () => { + expect(organizationReducer(undefined, {})).toEqual(initialState); + }); + + [true, false].forEach(payload => { + it(`should set loading state to ${JSON.stringify( + payload + )} on action "GET_ORG_REPOS_LOADING"`, () => { + const action = { type: GET_ORG_REPOS_LOADING, payload }; + const expectedState = { ...initialState, isPendingRepos: action.payload }; + + expect(organizationReducer(initialState, action)).toEqual(expectedState); + }); + }); + + [{ id: 1 }, { id: 2 }].forEach(payload => { + it('should set repos on success on action "GET_ORG_REPOS"', () => { + const action = { type: GET_ORG_REPOS, payload }; + const expectedState = { + ...initialState, + isPendingRepos: false, + repositories: payload, + }; + + expect(organizationReducer(initialState, action)).toEqual(expectedState); + }); + }); + + it('should set error state on action "GET_ORG_REPOS_ERROR"', () => { + const action = { type: GET_ORG_REPOS_ERROR, payload: 'error' }; + const expectedState = { + ...initialState, + organizationRepositoriesError: action.payload, + }; + + expect(organizationReducer(initialState, action)).toEqual(expectedState); + }); +}); diff --git a/src/organization/organization.reducer.js b/src/organization/organization.reducer.js index 9cf9a7cb1..f8be03af5 100644 --- a/src/organization/organization.reducer.js +++ b/src/organization/organization.reducer.js @@ -6,7 +6,7 @@ import { GET_ORG_REPOS_ERROR, } from './organization.constants'; -const initialState = { +export const initialState = { organization: {}, repositories: [], members: [],