mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 09:35:56 -05:00
Add tests for new studio permissions
This commit is contained in:
parent
29f6006b40
commit
0f8baaaa45
3 changed files with 121 additions and 5 deletions
|
@ -29,14 +29,15 @@ const selectCanFollowStudio = state => selectIsLoggedIn(state);
|
|||
const selectCanEditCommentsAllowed = state => selectIsAdmin(state) || isCreator(state);
|
||||
const selectCanEditOpenToAll = state => isManager(state);
|
||||
|
||||
const selectShowCuratorInvite = state => state.studio.invited;
|
||||
const selectShowCuratorInvite = state => !!state.studio.invited;
|
||||
const selectCanInviteCurators = state => isManager(state);
|
||||
const selectCanRemoveCurators = state => isManager(state);
|
||||
const selectCanRemoveManager = (state, managerId) => isManager(state) && managerId !== state.studio.owner;
|
||||
const selectCanRemoveCurators = state => isManager(state) || selectIsAdmin(state);
|
||||
const selectCanRemoveManager = (state, managerId) =>
|
||||
(selectIsAdmin(state) || isManager(state)) && managerId !== state.studio.owner;
|
||||
const selectCanPromoteCurators = state => isManager(state);
|
||||
|
||||
// TODO this permission needs to account for who added the project
|
||||
const selectCanRemoveProjects = state => isCurator(state) || isManager(state);
|
||||
const selectCanRemoveProjects = state => isCurator(state) || isManager(state) || selectIsAdmin(state);
|
||||
|
||||
export {
|
||||
selectCanEditInfo,
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
"isCurator": {
|
||||
"curator": true
|
||||
},
|
||||
"isInvited": {
|
||||
"invited": true
|
||||
},
|
||||
"creator1": {
|
||||
"owner": 1
|
||||
},
|
||||
|
|
|
@ -8,7 +8,13 @@ import {
|
|||
selectCanRestoreComment,
|
||||
selectCanFollowStudio,
|
||||
selectCanEditCommentsAllowed,
|
||||
selectCanEditOpenToAll
|
||||
selectCanEditOpenToAll,
|
||||
selectShowCuratorInvite,
|
||||
selectCanInviteCurators,
|
||||
selectCanRemoveCurators,
|
||||
selectCanRemoveManager,
|
||||
selectCanPromoteCurators,
|
||||
selectCanRemoveProjects
|
||||
} from '../../../src/redux/studio-permissions';
|
||||
|
||||
import {getInitialState as getInitialStudioState} from '../../../src/redux/studio';
|
||||
|
@ -42,6 +48,9 @@ const setStateByRole = (role) => {
|
|||
break;
|
||||
case 'logged out': // Default state set in beforeEach
|
||||
break;
|
||||
case 'invited':
|
||||
state.studio = studios.isInvited;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown user role in test: ' + role);
|
||||
}
|
||||
|
@ -98,6 +107,21 @@ describe('studio projects', () => {
|
|||
expect(selectCanAddProjects(state)).toBe(expected);
|
||||
});
|
||||
});
|
||||
describe('can remove projects', () => {
|
||||
test.each([
|
||||
['admin', true],
|
||||
['curator', true],
|
||||
['manager', true],
|
||||
['creator', true],
|
||||
['logged in', false],
|
||||
['unconfirmed', false],
|
||||
['logged out', false]
|
||||
])('%s: %s', (role, expected) => {
|
||||
setStateByRole(role);
|
||||
// TODO this permission is wrong, curators can only remove projects they added
|
||||
expect(selectCanRemoveProjects(state)).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('studio comments', () => {
|
||||
|
@ -208,4 +232,92 @@ describe('studio comments', () => {
|
|||
expect(selectCanEditOpenToAll(state)).toBe(expected);
|
||||
});
|
||||
});
|
||||
describe('studio members', () => {
|
||||
describe('can accept invitation', () => {
|
||||
test.each([
|
||||
['admin', false],
|
||||
['curator', false],
|
||||
['manager', false],
|
||||
['creator', false],
|
||||
['invited', true],
|
||||
['logged in', false],
|
||||
['unconfirmed', false],
|
||||
['logged out', false]
|
||||
])('%s: %s', (role, expected) => {
|
||||
setStateByRole(role);
|
||||
expect(selectShowCuratorInvite(state)).toBe(expected);
|
||||
});
|
||||
});
|
||||
describe('can promote curators', () => {
|
||||
test.each([
|
||||
['admin', false],
|
||||
['curator', false],
|
||||
['manager', true],
|
||||
['creator', true],
|
||||
['logged in', false],
|
||||
['unconfirmed', false],
|
||||
['logged out', false]
|
||||
])('%s: %s', (role, expected) => {
|
||||
setStateByRole(role);
|
||||
expect(selectCanPromoteCurators(state)).toBe(expected);
|
||||
});
|
||||
});
|
||||
describe('can remove curators', () => {
|
||||
test.each([
|
||||
['admin', true],
|
||||
['curator', false],
|
||||
['manager', true],
|
||||
['creator', true],
|
||||
['logged in', false],
|
||||
['unconfirmed', false],
|
||||
['logged out', false]
|
||||
])('%s: %s', (role, expected) => {
|
||||
setStateByRole(role);
|
||||
expect(selectCanRemoveCurators(state)).toBe(expected);
|
||||
});
|
||||
});
|
||||
describe('can remove managers', () => {
|
||||
test.each([
|
||||
['admin', true],
|
||||
['curator', false],
|
||||
['manager', true],
|
||||
['creator', true],
|
||||
['logged in', false],
|
||||
['unconfirmed', false],
|
||||
['logged out', false]
|
||||
])('%s: %s', (role, expected) => {
|
||||
setStateByRole(role);
|
||||
expect(selectCanRemoveManager(state, '123')).toBe(expected);
|
||||
});
|
||||
describe('nobody can remove the studio creator', () => {
|
||||
test.each([
|
||||
['admin', false],
|
||||
['curator', false],
|
||||
['manager', false],
|
||||
['creator', false],
|
||||
['logged in', false],
|
||||
['unconfirmed', false],
|
||||
['logged out', false]
|
||||
])('%s: %s', (role, expected) => {
|
||||
setStateByRole(role);
|
||||
state.studio.owner = 'the creator';
|
||||
expect(selectCanRemoveManager(state, 'the creator')).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('can invite curators', () => {
|
||||
test.each([
|
||||
['admin', false],
|
||||
['curator', false],
|
||||
['manager', true],
|
||||
['creator', false],
|
||||
['logged in', false],
|
||||
['unconfirmed', false],
|
||||
['logged out', false]
|
||||
])('%s: %s', (role, expected) => {
|
||||
setStateByRole(role);
|
||||
expect(selectCanInviteCurators(state)).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue