From 5e60f58bb31417185f5774ae470652b056e6ca3b Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Wed, 16 Feb 2022 18:10:09 -0400 Subject: [PATCH] Chore: Migrate redux actions/enterpriseModules to TS (#3698) * migrate enterpriseModules to TS * update test file --- app/actions/enterpriseModules.js | 14 -------------- app/actions/enterpriseModules.ts | 23 +++++++++++++++++++++++ app/definitions/redux/index.ts | 7 +++++-- app/reducers/enterpriseModules.js | 14 -------------- app/reducers/enterpriseModules.test.ts | 23 +++++++++++++++++++++++ app/reducers/enterpriseModules.ts | 17 +++++++++++++++++ 6 files changed, 68 insertions(+), 30 deletions(-) delete mode 100644 app/actions/enterpriseModules.js create mode 100644 app/actions/enterpriseModules.ts delete mode 100644 app/reducers/enterpriseModules.js create mode 100644 app/reducers/enterpriseModules.test.ts create mode 100644 app/reducers/enterpriseModules.ts diff --git a/app/actions/enterpriseModules.js b/app/actions/enterpriseModules.js deleted file mode 100644 index 74b097873..000000000 --- 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 000000000..073aef49b --- /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 558882b46..dc5033771 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 2f1a7ac9a..000000000 --- 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 000000000..7daf14167 --- /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 000000000..78616e246 --- /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; + } +};