mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 09:35:56 -05:00
Add permissions selector and tests
This commit is contained in:
parent
c0d681aea1
commit
2265cd0d90
2 changed files with 35 additions and 0 deletions
|
@ -54,3 +54,7 @@ module.exports.setPermissionsError = error => ({
|
|||
type: Types.SET_PERMISSIONS_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;
|
||||
|
|
31
test/unit/redux/permissions.test.js
Normal file
31
test/unit/redux/permissions.test.js
Normal 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);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue