mirror of
https://github.com/strapi/strapi.git
synced 2026-01-07 12:45:45 +00:00
Add tests
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
467d77cbaa
commit
2fd80d7de4
@ -0,0 +1,32 @@
|
||||
import init from '../init';
|
||||
|
||||
describe('UPLOAD | hooks | useUserPermissions | init', () => {
|
||||
it('should return the initialState and the allowedActions', () => {
|
||||
const initialState = {
|
||||
isLoading: true,
|
||||
};
|
||||
const expected = {
|
||||
isLoading: true,
|
||||
allowedActions: {},
|
||||
};
|
||||
|
||||
expect(init(initialState, [])).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should return an object with the allowedActions set properly', () => {
|
||||
const initialState = {
|
||||
isLoading: true,
|
||||
};
|
||||
const expected = {
|
||||
isLoading: true,
|
||||
allowedActions: {
|
||||
canRead: false,
|
||||
canUpdate: false,
|
||||
},
|
||||
};
|
||||
|
||||
const data = ['read', 'update'];
|
||||
|
||||
expect(init(initialState, data)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,36 @@
|
||||
import reducer from '../reducer';
|
||||
|
||||
describe('UPLOAD | hooks | useUserPermissions | reducer', () => {
|
||||
describe('DEFAULT_ACTION', () => {
|
||||
it('should return the initialState', () => {
|
||||
const initialState = {
|
||||
ok: true,
|
||||
};
|
||||
|
||||
expect(reducer(initialState, { type: '' })).toEqual(initialState);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET_DATA_SUCCEEDED', () => {
|
||||
it('should set the data correctly', () => {
|
||||
const initialState = {
|
||||
isLoading: true,
|
||||
allowedActions: {},
|
||||
};
|
||||
const action = {
|
||||
type: 'GET_DATA_SUCCEEDED',
|
||||
data: {
|
||||
canRead: false,
|
||||
},
|
||||
};
|
||||
const expected = {
|
||||
allowedActions: {
|
||||
canRead: false,
|
||||
},
|
||||
isLoading: false,
|
||||
};
|
||||
|
||||
expect(reducer(initialState, action)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,10 @@
|
||||
import { upperFirst } from 'lodash';
|
||||
|
||||
const generateResultsObject = array =>
|
||||
array.reduce((acc, current) => {
|
||||
acc[`can${upperFirst(current.permissionName)}`] = current.hasPermission;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
export default generateResultsObject;
|
||||
@ -0,0 +1,16 @@
|
||||
import generateResultsObject from '../generateResultsObject';
|
||||
|
||||
describe('UPLOAD | hooks | useUserPermissions | | utils | generateResultsObject', () => {
|
||||
it('should return an object with { key: can<PermissionName>, value: bool }', () => {
|
||||
const data = [
|
||||
{ permissionName: 'read', hasPermission: true },
|
||||
{ permissionName: 'update', hasPermission: false },
|
||||
];
|
||||
const expected = {
|
||||
canRead: true,
|
||||
canUpdate: false,
|
||||
};
|
||||
|
||||
expect(generateResultsObject(data)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user