/* global describe: true, test:true, expect:true */ import { receivers as receiversReducer, initialState } from '~/reducers/receivers'; import { GET_RECEIVERS_TOKEN, GET_RECEIVERS_TOKEN_SUCCESS, GET_RECEIVERS_TOKEN_ERROR, } from '~/store/actionTypes'; describe('receivers reducer', () => { test('CASE 1: should return initial state', () => { expect(receiversReducer(undefined, { type: 'Default' })) .toEqual(initialState); }); test('CASE 2: should return state with meta set to loading when type is GET_RECEIVERS_TOKEN', () => { const receiversToken = { meta: { error: '', loading: true }, receiversToken: '' }; const expectedState = { ...initialState, meta: { ...initialState.meta, loading: true } }; const stateResult = receiversReducer(initialState, { type: GET_RECEIVERS_TOKEN, payload: receiversToken, }); expect(stateResult).toEqual(expectedState); }); test('CASE 3: should return state with meta set to loading when type is GET_RECEIVERS_TOKEN_SUCCESS', () => { const receiversToken = { meta: { error: '', loading: false }, receiversToken: { meta: { error: '', loading: false } } }; const expectedState = { ...initialState, receiversToken: { meta: { error: '', loading: false } } }; const stateResult = receiversReducer(initialState, { type: GET_RECEIVERS_TOKEN_SUCCESS, payload: receiversToken, }); expect(stateResult).toEqual(expectedState); }); test('CASE 4: should return state with error when type is GET_RECEIVERS_TOKEN_ERROR', () => { const error = { meta: { error: '', loading: false }, receiversToken: '' }; const expectedState = { ...initialState }; const stateResult = receiversReducer(initialState, { type: GET_RECEIVERS_TOKEN_ERROR, payload: error, }); expect(stateResult).toEqual(expectedState); }); });