From dbf9b18d5b4c9fd1b78224e60521385d22f04136 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Thu, 19 Aug 2021 11:59:08 -0400 Subject: [PATCH] add unit test for permissions --- test/unit/redux/studio-permissions.test.js | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/unit/redux/studio-permissions.test.js b/test/unit/redux/studio-permissions.test.js index 2b409817c..994cdafb1 100644 --- a/test/unit/redux/studio-permissions.test.js +++ b/test/unit/redux/studio-permissions.test.js @@ -15,6 +15,7 @@ import { selectCanRemoveManager, selectCanPromoteCurators, selectCanRemoveProject, + selectCanTransfer, selectShowCommentsList, selectShowCommentsGloballyOffError, selectShowProjectMuteError, @@ -432,6 +433,30 @@ describe('studio members', () => { expect(selectCanInviteCurators(state)).toBe(expected); }); }); + + describe('can transfer host', () => { + test.each([ + ['admin', true], + ['curator', false], + ['manager', false], + ['creator', true], + ['logged in', false], + ['unconfirmed', false], + ['logged out', false], + ['muted creator', true], // Muted users do not see the transfer UI + ['muted logged in', false] + ])('%s: %s', (role, expected) => { + setStateByRole(role); + state.studio = {...state.studio, managers: 2, classroomId: null}; + // Only admin and host see the option to transfer the current host + expect(selectCanTransfer(state, state.studio.owner)).toBe(expected); + // Nobody sees the option to transfer a manager who is not the host + expect(selectCanTransfer(state, 123)).toBe(false); + // Nobody can transfer classroom studios + state.studio = {...state.studio, classroomId: 1}; + expect(selectCanTransfer(state, state.studio.owner)).toBe(false); + }); + }); }); describe('studio mute errors', () => {