diff --git a/app/actions/enterpriseModules.js b/app/actions/enterpriseModules.js deleted file mode 100644 index 74b09787..00000000 --- a/app/actions/enterpriseModules.js +++ /dev/null @@ -1,14 +0,0 @@ -import { ENTERPRISE_MODULES } from './actionsTypes'; - -export function setEnterpriseModules(modules) { - return { - type: ENTERPRISE_MODULES.SET, - payload: modules - }; -} - -export function clearEnterpriseModules() { - return { - type: ENTERPRISE_MODULES.CLEAR - }; -} diff --git a/app/actions/enterpriseModules.ts b/app/actions/enterpriseModules.ts new file mode 100644 index 00000000..073aef49 --- /dev/null +++ b/app/actions/enterpriseModules.ts @@ -0,0 +1,23 @@ +import { Action } from 'redux'; + +import { IEnterpriseModules } from '../reducers/enterpriseModules'; +import { ENTERPRISE_MODULES } from './actionsTypes'; + +interface ISetEnterpriseModules extends Action { + payload: IEnterpriseModules[]; +} + +export type TActionEnterpriseModules = ISetEnterpriseModules & Action; + +export function setEnterpriseModules(modules: IEnterpriseModules[]): ISetEnterpriseModules { + return { + type: ENTERPRISE_MODULES.SET, + payload: modules + }; +} + +export function clearEnterpriseModules(): Action { + return { + type: ENTERPRISE_MODULES.CLEAR + }; +} diff --git a/app/definitions/redux/index.ts b/app/definitions/redux/index.ts index 558882b4..dc503377 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -26,6 +26,8 @@ import { ISelectedUsers } from '../../reducers/selectedUsers'; import { IServer } from '../../reducers/server'; import { ISettings } from '../../reducers/settings'; import { IShare } from '../../reducers/share'; +import { IEnterpriseModules } from '../../reducers/enterpriseModules'; +import { TActionEnterpriseModules } from '../../actions/enterpriseModules'; export interface IApplicationState { settings: ISettings; @@ -45,7 +47,7 @@ export interface IApplicationState { inviteLinks: IInviteLinks; createDiscussion: ICreateDiscussion; inquiry: any; - enterpriseModules: any; + enterpriseModules: IEnterpriseModules; encryption: IEncryption; permissions: any; roles: IRoles; @@ -64,4 +66,5 @@ export type TApplicationActions = TActionActiveUsers & TActionCreateChannel & TActionsShare & TActionServer & - TActionApp; + TActionApp & + TActionEnterpriseModules; diff --git a/app/reducers/enterpriseModules.js b/app/reducers/enterpriseModules.js deleted file mode 100644 index 2f1a7ac9..00000000 --- a/app/reducers/enterpriseModules.js +++ /dev/null @@ -1,14 +0,0 @@ -import { ENTERPRISE_MODULES } from '../actions/actionsTypes'; - -const initialState = []; - -export default (state = initialState, action) => { - switch (action.type) { - case ENTERPRISE_MODULES.SET: - return action.payload; - case ENTERPRISE_MODULES.CLEAR: - return initialState; - default: - return state; - } -}; diff --git a/app/reducers/enterpriseModules.test.ts b/app/reducers/enterpriseModules.test.ts new file mode 100644 index 00000000..7daf1416 --- /dev/null +++ b/app/reducers/enterpriseModules.test.ts @@ -0,0 +1,23 @@ +import { clearEnterpriseModules, setEnterpriseModules } from '../actions/enterpriseModules'; +import { mockedStore } from './mockedStore'; +import { IEnterpriseModules, initialState } from './enterpriseModules'; + +describe('test enterpriseModules reducer', () => { + it('should return initial state', () => { + const state = mockedStore.getState().enterpriseModules; + expect(state).toEqual(initialState); + }); + + it('should return modified store after setEnterpriseModules', () => { + const modules = ['omnichannel-mobile-enterprise', 'livechat-enterprise'] as IEnterpriseModules[]; + mockedStore.dispatch(setEnterpriseModules(modules)); + const state = mockedStore.getState().enterpriseModules; + expect(state).toEqual(modules); + }); + + it('should return empty store after clearEnterpriseModules', () => { + mockedStore.dispatch(clearEnterpriseModules()); + const state = mockedStore.getState().enterpriseModules; + expect(state).toEqual([]); + }); +}); diff --git a/app/reducers/enterpriseModules.ts b/app/reducers/enterpriseModules.ts new file mode 100644 index 00000000..78616e24 --- /dev/null +++ b/app/reducers/enterpriseModules.ts @@ -0,0 +1,17 @@ +import { TActionEnterpriseModules } from '../actions/enterpriseModules'; +import { ENTERPRISE_MODULES } from '../actions/actionsTypes'; + +export type IEnterpriseModules = 'omnichannel-mobile-enterprise' | 'livechat-enterprise'; + +export const initialState: IEnterpriseModules[] = []; + +export default (state = initialState, action: TActionEnterpriseModules): IEnterpriseModules[] => { + switch (action.type) { + case ENTERPRISE_MODULES.SET: + return action.payload; + case ENTERPRISE_MODULES.CLEAR: + return initialState; + default: + return state; + } +};