Chore: Migrate redux module permissions to typescript (#3630)
This commit is contained in:
parent
9773fc1799
commit
03459147ed
|
@ -1,15 +0,0 @@
|
|||
import * as types from './actionsTypes';
|
||||
|
||||
export function setPermissions(permissions) {
|
||||
return {
|
||||
type: types.PERMISSIONS.SET,
|
||||
permissions
|
||||
};
|
||||
}
|
||||
|
||||
export function updatePermission(id, roles) {
|
||||
return {
|
||||
type: types.PERMISSIONS.UPDATE,
|
||||
payload: { id, roles }
|
||||
};
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
import { Action } from 'redux';
|
||||
|
||||
import { IPermissions } from '../reducers/permissions';
|
||||
import { PERMISSIONS } from './actionsTypes';
|
||||
|
||||
interface ISetPermissions extends Action {
|
||||
permissions: IPermissions;
|
||||
}
|
||||
|
||||
interface IUpdatePermissions extends Action {
|
||||
payload: { id: string; roles: string };
|
||||
}
|
||||
|
||||
export type TActionPermissions = ISetPermissions & IUpdatePermissions;
|
||||
|
||||
export function setPermissions(permissions: IPermissions): ISetPermissions {
|
||||
return {
|
||||
type: PERMISSIONS.SET,
|
||||
permissions
|
||||
};
|
||||
}
|
||||
|
||||
export function updatePermission(id: string, roles: string): IUpdatePermissions {
|
||||
return {
|
||||
type: PERMISSIONS.UPDATE,
|
||||
payload: { id, roles }
|
||||
};
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
import { setPermissions, updatePermission } from '../actions/permissions';
|
||||
import { mockedStore } from './mockedStore';
|
||||
import { initialState } from './permissions';
|
||||
|
||||
describe('test permissions reducer', () => {
|
||||
it('should return initial state', () => {
|
||||
const state = mockedStore.getState().permissions;
|
||||
expect(state).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('should return modified store after setPermissions', () => {
|
||||
const permissions = { hasEditPermission: 'enabled', hasForceDeletePermission: 'enabled' };
|
||||
mockedStore.dispatch(setPermissions(permissions));
|
||||
const state = mockedStore.getState().permissions;
|
||||
expect(state).toEqual(permissions);
|
||||
});
|
||||
|
||||
it('should return empty store after remove user', () => {
|
||||
mockedStore.dispatch(updatePermission('hasEditPermission', 'disabled'));
|
||||
const state = mockedStore.getState().permissions;
|
||||
expect(state.hasEditPermission).toEqual('disabled');
|
||||
});
|
||||
});
|
|
@ -1,8 +1,11 @@
|
|||
import { PERMISSIONS } from '../actions/actionsTypes';
|
||||
import { TActionPermissions } from '../actions/permissions';
|
||||
|
||||
const initialState = {};
|
||||
export type IPermissions = Record<string, string>;
|
||||
|
||||
export default function permissions(state = initialState, action) {
|
||||
export const initialState: IPermissions = {};
|
||||
|
||||
export default function permissions(state = initialState, action: TActionPermissions): IPermissions {
|
||||
switch (action.type) {
|
||||
case PERMISSIONS.SET:
|
||||
return action.permissions;
|
Loading…
Reference in New Issue