Commit 69e581bc authored by Giannis Kopanas's avatar Giannis Kopanas

fix tests for GET list collections

parent 722c0c06
......@@ -66,6 +66,7 @@ class XpubCollabraMode {
return membershipCondition(team)
}),
)
return memberships.includes(true)
}
......@@ -279,11 +280,10 @@ class XpubCollabraMode {
filter: async collections => {
const filteredCollections = await Promise.all(
collections.map(async collection => {
let condition = this.checkTeamMembers(
let condition = await this.checkTeamMembers(
['isAssignedSeniorEditor', 'isAssignedHandlingEditor'],
collection,
)
condition = condition
? true
: await this.canReadatLeastOneFragmentOfCollection(collection, [
......@@ -294,6 +294,7 @@ class XpubCollabraMode {
return condition ? collection : false
}),
)
return filteredCollections.filter(collection => collection)
},
}
......
......@@ -5,9 +5,11 @@ const authsomeConfig = require('config').get('authsome')
const collections = [
{
id: 'collection1',
fragments: ['fragment1'],
},
{
id: 'collection2',
fragments: [],
},
]
......@@ -33,6 +35,14 @@ const teams = [
teamType: 'managingEditor',
// No associated object means this is a global team
},
{
id: 'team4',
teamType: 'reviewer',
object: {
id: 'fragment1',
type: 'fragment',
},
},
]
const users = [
......@@ -51,6 +61,11 @@ const users = [
username: 'managingEditor1',
teams: ['team3'],
},
{
id: 'user4',
username: 'reviewerEditor1',
teams: ['team4'],
},
{
id: 'adminId',
username: 'admin',
......@@ -84,11 +99,25 @@ describe('Handling Editor', () => {
const permission = await authsome.can('user1', 'GET', {
path: '/collections',
})
const filteredCollections = await permission.filter(collections)
expect(filteredCollections).toEqual([collections[1]])
})
})
describe('Reviewer Editor', () => {
it('lists only collections where user is a member of the reviewer editors team', async () => {
const permission = await authsome.can('user4', 'GET', {
path: '/collections',
})
const filteredCollections = await permission.filter(collections)
expect(filteredCollections).toEqual([collections[0]])
})
})
describe('Senior Editor', () => {
it('lists only collections where user is a member of the senior editors team', async () => {
const permission = await authsome.can('user2', 'GET', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment