Add test for find all member of closed and hidden groups if you are usual member

This commit is contained in:
Wolfgang Huß 2022-08-22 07:19:07 +02:00
parent 695a71bf25
commit 0fe609e294
2 changed files with 64 additions and 19 deletions

View File

@ -55,6 +55,7 @@ const isMySocialMedia = rule({
const isAllowedSeeingMembersOfGroup = rule({
cache: 'no_cache',
})(async (_parent, args, { user, driver }) => {
// Wolle: may have a look to 'isAuthenticated'
if (!user) return false
const { id: groupId } = args
// Wolle: console.log('groupId: ', groupId)
@ -96,6 +97,7 @@ const isAllowedSeeingMembersOfGroup = rule({
const isAllowedToSwitchGroupMemberRole = rule({
cache: 'no_cache',
})(async (_parent, args, { user, driver }) => {
// Wolle: may have a look to 'isAuthenticated'
if (!user) return false
const adminId = user.id
const { id: groupId, userId, roleInGroup } = args

View File

@ -940,6 +940,19 @@ describe('GroupMember', () => {
},
)
// create groups
authenticatedUser = await user.toJson()
await mutate({
mutation: createGroupMutation,
variables: {
id: 'public-group',
name: 'The Best Group',
about: 'We will change the world!',
description: 'Some description' + descriptionAdditional100,
groupType: 'public',
actionRadius: 'regional',
categoryIds,
},
})
authenticatedUser = await ownerOfClosedGroupUser.toJson()
await mutate({
mutation: createGroupMutation,
@ -966,20 +979,8 @@ describe('GroupMember', () => {
categoryIds,
},
})
authenticatedUser = await user.toJson()
await mutate({
mutation: createGroupMutation,
variables: {
id: 'public-group',
name: 'The Best Group',
about: 'We will change the world!',
description: 'Some description' + descriptionAdditional100,
groupType: 'public',
actionRadius: 'regional',
categoryIds,
},
})
// create additional memberships
// public-group
await mutate({
mutation: joinGroupMutation,
variables: {
@ -994,6 +995,7 @@ describe('GroupMember', () => {
userId: 'owner-of-hidden-group',
},
})
// closed-group
await mutate({
mutation: joinGroupMutation,
variables: {
@ -1001,6 +1003,21 @@ describe('GroupMember', () => {
userId: 'current-user',
},
})
await mutate({
mutation: joinGroupMutation,
variables: {
id: 'closed-group',
userId: 'owner-of-hidden-group',
},
})
// hidden-group
await mutate({
mutation: joinGroupMutation,
variables: {
id: 'hidden-group',
userId: 'current-user',
},
})
await mutate({
mutation: joinGroupMutation,
variables: {
@ -1008,6 +1025,8 @@ describe('GroupMember', () => {
userId: 'owner-of-closed-group',
},
})
authenticatedUser = await user.toJson()
})
describe('public group', () => {
@ -1147,6 +1166,10 @@ describe('GroupMember', () => {
id: 'owner-of-closed-group',
myRoleInGroup: 'owner',
}),
expect.objectContaining({
id: 'owner-of-hidden-group',
myRoleInGroup: 'pending',
}),
]),
},
errors: undefined,
@ -1156,13 +1179,21 @@ describe('GroupMember', () => {
variables,
})
expect(result).toMatchObject(expected)
expect(result.data.GroupMember.length).toBe(2)
expect(result.data.GroupMember.length).toBe(3)
})
})
// needs 'SwitchGroupMemberRole'
describe.skip('by usual member "owner-of-hidden-group"', () => {
describe('by usual member "owner-of-hidden-group"', () => {
beforeEach(async () => {
authenticatedUser = await ownerOfClosedGroupUser.toJson()
await mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'closed-group',
userId: 'owner-of-hidden-group',
roleInGroup: 'usual',
},
})
authenticatedUser = await ownerOfHiddenGroupUser.toJson()
})
@ -1236,6 +1267,10 @@ describe('GroupMember', () => {
const expected = {
data: {
GroupMember: expect.arrayContaining([
expect.objectContaining({
id: 'current-user',
myRoleInGroup: 'pending',
}),
expect.objectContaining({
id: 'owner-of-closed-group',
myRoleInGroup: 'pending',
@ -1253,13 +1288,21 @@ describe('GroupMember', () => {
variables,
})
expect(result).toMatchObject(expected)
expect(result.data.GroupMember.length).toBe(2)
expect(result.data.GroupMember.length).toBe(3)
})
})
// needs 'SwitchGroupMemberRole'
describe.skip('by usual member "owner-of-closed-group"', () => {
describe('by usual member "owner-of-closed-group"', () => {
beforeEach(async () => {
authenticatedUser = await ownerOfHiddenGroupUser.toJson()
await mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'hidden-group',
userId: 'owner-of-closed-group',
roleInGroup: 'usual',
},
})
authenticatedUser = await ownerOfClosedGroupUser.toJson()
})