Add permissions selector and tests

This commit is contained in:
Paul Kaplan 2021-03-23 15:18:17 -04:00
parent c0d681aea1
commit 2265cd0d90
2 changed files with 35 additions and 0 deletions

View file

@ -54,3 +54,7 @@ module.exports.setPermissionsError = error => ({
type: Types.SET_PERMISSIONS_ERROR, type: Types.SET_PERMISSIONS_ERROR,
error: error error: error
}); });
// Selectors - Being extra cautious with stict truthiness
module.exports.selectIsAdmin = state => state.permissions.admin === true;
module.exports.selectIsSocial = state => state.permissions.social === true;

View file

@ -0,0 +1,31 @@
import {
selectIsAdmin, selectIsSocial, permissionsReducer, setPermissions
} from '../../../src/redux/permissions';
describe('permission selectors', () => {
test('all permissions are initially false', () => {
const state = {
permissions: {}
};
expect(selectIsAdmin(state)).toBe(false);
expect(selectIsSocial(state)).toBe(false);
});
test('selectIsAdmin', () => {
let state = {
permissions: {}
};
const newPermissions = {admin: true};
state.permissions = permissionsReducer(state.session, setPermissions(newPermissions));
expect(selectIsAdmin(state)).toBe(true);
});
test('isSocial', () => {
let state = {
permissions: {}
};
const newPermissions = {social: true};
state.permissions = permissionsReducer(state.session, setPermissions(newPermissions));
expect(selectIsSocial(state)).toBe(true);
});
});