-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7789 from owncloud/space-role-tests
[tests-only] Add unit tests for project space role assignments
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
packages/web-client/tests/unit/helpers/space/functions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { buildSpace, ProjectSpaceResource } from '../../../../src/helpers/space' | ||
import { spaceRoleEditor, spaceRoleManager, spaceRoleViewer } from '../../../../src/helpers/share' | ||
|
||
describe('buildSpace', () => { | ||
const uuid = '1' | ||
|
||
describe('isViewer', () => { | ||
it.each([ | ||
{ role: spaceRoleViewer.name, expectedResult: true }, | ||
{ role: spaceRoleEditor.name, expectedResult: false }, | ||
{ role: spaceRoleManager.name, expectedResult: false } | ||
])('returns true for a viewer of the space', (data) => { | ||
const space = buildSpace({ | ||
root: { | ||
permissions: [{ roles: data.role, grantedTo: [{ user: { id: uuid } }] }] | ||
} | ||
}) as ProjectSpaceResource | ||
expect(space.isViewer(uuid)).toBe(data.expectedResult) | ||
}) | ||
}) | ||
|
||
describe('isEditor', () => { | ||
it.each([ | ||
{ role: spaceRoleViewer.name, expectedResult: false }, | ||
{ role: spaceRoleEditor.name, expectedResult: true }, | ||
{ role: spaceRoleManager.name, expectedResult: false } | ||
])('returns true for a editor of the space', (data) => { | ||
const space = buildSpace({ | ||
root: { | ||
permissions: [{ roles: data.role, grantedTo: [{ user: { id: uuid } }] }] | ||
} | ||
}) as ProjectSpaceResource | ||
expect(space.isEditor(uuid)).toBe(data.expectedResult) | ||
}) | ||
}) | ||
|
||
describe('isManager', () => { | ||
it.each([ | ||
{ role: spaceRoleViewer.name, expectedResult: false }, | ||
{ role: spaceRoleEditor.name, expectedResult: false }, | ||
{ role: spaceRoleManager.name, expectedResult: true } | ||
])('returns true for a manager of the space', (data) => { | ||
const space = buildSpace({ | ||
root: { | ||
permissions: [{ roles: data.role, grantedTo: [{ user: { id: uuid } }] }] | ||
} | ||
}) as ProjectSpaceResource | ||
expect(space.isManager(uuid)).toBe(data.expectedResult) | ||
}) | ||
}) | ||
}) |