create videoConf reducer

This commit is contained in:
GleidsonDaniel 2023-03-08 14:36:49 -03:00
parent c6658d570b
commit 76c41474a6
3 changed files with 84 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import enterpriseModules from './enterpriseModules';
import encryption from './encryption'; import encryption from './encryption';
import permissions from './permissions'; import permissions from './permissions';
import roles from './roles'; import roles from './roles';
import videoConf from './videoConf';
export default combineReducers({ export default combineReducers({
settings, settings,
@ -43,5 +44,6 @@ export default combineReducers({
enterpriseModules, enterpriseModules,
encryption, encryption,
permissions, permissions,
roles roles,
videoConf
}); });

View File

@ -0,0 +1,48 @@
import { clearVideoConfCalls, removeVideoConfCall, setVideoConfCall } from '../actions/videoConf';
import { mockedStore } from './mockedStore';
import { initialState, ICallInfo } from './videoConf';
describe('test videoConf reducer', () => {
it('should return initial state', () => {
const state = mockedStore.getState().settings;
expect(state).toEqual(initialState);
});
const call1: ICallInfo = {
callId: '123',
rid: '123',
type: 'accepted',
uid: '123'
};
const call2: ICallInfo = {
callId: '321',
rid: '321',
type: 'accepted',
uid: '321'
};
it('should return call1 after call addSettings action with call1 as parameter', () => {
mockedStore.dispatch(setVideoConfCall(call1));
const state = mockedStore.getState().videoConf;
expect(state[call1.callId]).toEqual(call1);
});
it('should return call2 after call addSettings action with call2 as parameter', () => {
mockedStore.dispatch(setVideoConfCall(call2));
const state = mockedStore.getState().videoConf;
expect(state[call2.callId]).toEqual(call2);
});
it('should remove call1 after call removeVideoConfCall action with call1 as parameter', () => {
mockedStore.dispatch(removeVideoConfCall(call1));
const state = mockedStore.getState().videoConf;
expect(state[call1.callId]).toEqual(undefined);
});
it('should return initial state after clearSettings', () => {
mockedStore.dispatch(clearVideoConfCalls());
const state = mockedStore.getState().videoConf;
expect(state).toEqual({});
});
});

33
app/reducers/videoConf.ts Normal file
View File

@ -0,0 +1,33 @@
import { VIDEO_CONF } from '../actions/actionsTypes';
import { TActionVideoConf } from '../actions/videoConf';
export type TSupportedCallStatus = 'call' | 'canceled' | 'accepted' | 'rejected' | 'confirmed' | 'join' | 'end';
export interface ICallInfo {
callId: string;
rid: string;
uid: string;
type: TSupportedCallStatus;
}
interface ICallInfoRecord {
[key: string]: ICallInfo;
}
export const initialState: ICallInfoRecord = {};
export default (state = initialState, action: TActionVideoConf): ICallInfoRecord => {
switch (action.type) {
case VIDEO_CONF.SET:
return {
...state,
[action.payload.callId]: action.payload
};
case VIDEO_CONF.REMOVE:
return Object.fromEntries(Object.entries(state).filter(([key]) => key !== action.payload.callId));
case VIDEO_CONF.CLEAR:
return initialState;
default:
return state;
}
};