Skip to content

Commit

Permalink
Merge pull request #7789 from owncloud/space-role-tests
Browse files Browse the repository at this point in the history
[tests-only] Add unit tests for project space role assignments
  • Loading branch information
JammingBen authored Oct 13, 2022
2 parents 6640e05 + 72bb448 commit 1b19669
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions packages/web-client/tests/unit/helpers/space/functions.spec.ts
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)
})
})
})

0 comments on commit 1b19669

Please sign in to comment.