/* global describe: true, test:true, expect:true */ import { avatar as avatarReducer, initialState, } from '~/reducers/avatar'; import { GET_AVATAR_UPLOADPOLICY, GET_AVATAR_UPLOADPOLICY_SUCCESS, GET_AVATAR_UPLOADPOLICY_ERROR, GET_AVATAR, GET_AVATAR_SUCCESS, GET_AVATAR_ERROR, ACTIVATE_AVATAR, ACTIVATE_AVATAR_SUCCESS, ACTIVATE_AVATAR_ERROR, DELETE_AVATAR, DELETE_AVATAR_SUCCESS, DELETE_AVATAR_ERROR, } from '~/store/actionTypes'; describe('avatar reducer', () => { test('CASE 1: should return initial state', () => { expect(avatarReducer(undefined, { type: 'Default' })) .toEqual(initialState); }); test('CASE 2: should return state with meta set to loading when type is GET_AVATAR', () => { const expectedState = { ...initialState, meta: { ...initialState.meta, loading: true } }; const stateResult = avatarReducer(initialState, { type: GET_AVATAR, payload: {}, }); expect(stateResult).toEqual(expectedState); }); test('CASE 3: should return state with meta set to loading when type is ACTIVATE_AVATAR', () => { const expectedState = { ...initialState, meta: { ...initialState.meta, loading: true } }; const stateResult = avatarReducer(initialState, { type: ACTIVATE_AVATAR, payload: {}, }); expect(stateResult).toEqual(expectedState); }); test('CASE 4: should return state with meta set to loading when type is GET_AVATAR_UPLOADPOLICY', () => { const expectedState = { ...initialState, meta: { ...initialState.meta, loading: true } }; const stateResult = avatarReducer(initialState, { type: GET_AVATAR_UPLOADPOLICY, payload: {}, }); expect(stateResult).toEqual(expectedState); }); test('CASE 5: should return state with meta set to loading when type is DELETE_AVATAR', () => { const expectedState = { ...initialState, meta: { ...initialState.meta, loading: true } }; const stateResult = avatarReducer(initialState, { type: DELETE_AVATAR, payload: {}, }); expect(stateResult).toEqual(expectedState); }); test('CASE 6: should return state with error when type is GET_AVATAR_ERROR', () => { const error = new Error('getAvatarError'); const expectedState = { ...initialState, meta: { ...initialState.meta, error } }; const stateResult = avatarReducer(initialState, { type: GET_AVATAR_ERROR, payload: { error }, }); expect(stateResult).toEqual(expectedState); }); test('CASE 6: should return state with error when type is ACTIVATE_AVATAR_ERROR', () => { const error = new Error('activateAvatarError'); const expectedState = { ...initialState, meta: { ...initialState.meta, error } }; const stateResult = avatarReducer(initialState, { type: ACTIVATE_AVATAR_ERROR, payload: { error }, }); expect(stateResult).toEqual(expectedState); }); test('CASE 8: should return state with error when type is GET_AVATAR_UPLOADPOLICY_ERROR', () => { const error = new Error('getUploadPolicyAvatarError'); const expectedState = { ...initialState, meta: { ...initialState.meta, error } }; const stateResult = avatarReducer(initialState, { type: GET_AVATAR_UPLOADPOLICY_ERROR, payload: { error }, }); expect(stateResult).toEqual(expectedState); }); test('CASE 9: should return state with error when type is DELETE_AVATAR_ERROR', () => { const error = new Error('deleteAvatarError'); const expectedState = { ...initialState, meta: { ...initialState.meta, error } }; const stateResult = avatarReducer(initialState, { type: DELETE_AVATAR_ERROR, payload: { error }, }); expect(stateResult).toEqual(expectedState); }); test('CASE 10: should return state with meta set to loading when type is GET_AVATAR_SUCCESS', () => { const payload = { uri: undefined }; const meta = { loading: false, error: '' }; const stateResult = avatarReducer(initialState, { type: GET_AVATAR_SUCCESS, payload, }); expect(stateResult.source).toEqual(payload); expect(stateResult).toHaveProperty('meta', meta); }); test('CASE 11: should return state with meta set to loading when type is ACTIVATE_AVATAR_SUCCESS', () => { const payload = { uri: undefined }; const meta = { loading: false, error: '' }; const stateResult = avatarReducer(initialState, { type: ACTIVATE_AVATAR_SUCCESS, payload, }); expect(stateResult.source).toEqual(payload); expect(stateResult).toHaveProperty('meta', meta); }); test('CASE 12: should return state with meta set to loading when type is GET_AVATAR_UPLOADPOLICY_SUCCESS', () => { const payload = { }; const meta = { loading: false, error: '' }; const stateResult = avatarReducer(initialState, { type: GET_AVATAR_UPLOADPOLICY_SUCCESS, payload, }); expect(stateResult.uploadPolicy).toEqual(payload); expect(stateResult).toHaveProperty('meta', meta); }); test('CASE 13: should return state with meta set to loading when type is DELETE_AVATAR_SUCCESS', () => { const payload = { }; const meta = { loading: false, error: '' }; const stateResult = avatarReducer(initialState, { type: DELETE_AVATAR_SUCCESS, payload, }); expect(stateResult).toEqual(initialState); expect(stateResult).toHaveProperty('meta', meta); }); });