From 4fdaa0da4ed168d7322de066d3ca230d3382a3e3 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 6 Oct 2022 13:13:23 +0200 Subject: [PATCH 1/3] Update backend/src/schema/resolvers/helpers/filterInvisiblePosts.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Wolfgang Huß --- backend/src/schema/resolvers/helpers/filterInvisiblePosts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/schema/resolvers/helpers/filterInvisiblePosts.js b/backend/src/schema/resolvers/helpers/filterInvisiblePosts.js index 108f9c007..73dfaad91 100644 --- a/backend/src/schema/resolvers/helpers/filterInvisiblePosts.js +++ b/backend/src/schema/resolvers/helpers/filterInvisiblePosts.js @@ -13,7 +13,7 @@ const getInvisiblePosts = async (context) => { cypher = ` MATCH (post:Post)-[:IN]->(group:Group) WHERE NOT group.groupType = 'public' - RETURN collect(post.id) AS invisiblePostIds` + RETURN collect(post.id) AS invisiblePostIds` } const invisiblePostIdsResponse = await transaction.run(cypher, { userId: user ? user.id : null, From 45562763512d988ac85fe35a0e3a7da8bcc7b27d Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Oct 2022 20:57:42 +0200 Subject: [PATCH 2/3] fix: leaving public group keeps the posts in public group visible. Test leaving public group and visibility of posts in public group --- backend/src/schema/resolvers/groups.js | 5 +- .../schema/resolvers/postsInGroups.spec.js | 149 +++++++++++------- 2 files changed, 98 insertions(+), 56 deletions(-) diff --git a/backend/src/schema/resolvers/groups.js b/backend/src/schema/resolvers/groups.js index 259a7c818..55dd605ad 100644 --- a/backend/src/schema/resolvers/groups.js +++ b/backend/src/schema/resolvers/groups.js @@ -262,7 +262,10 @@ export default { MATCH (member:User {id: $userId})-[membership:MEMBER_OF]->(group:Group {id: $groupId}) DELETE membership WITH member, group - FOREACH (post IN [(p:Post)-[:IN]->(group) | p] | + OPTIONAL MATCH (p:Post)-[:IN]->(group) + WHERE NOT group.groupType = 'public' + WITH member, group, collect(p) AS posts + FOREACH (post IN posts | MERGE (member)-[:CANNOT_SEE]->(post)) RETURN member {.*, myRoleInGroup: NULL} ` diff --git a/backend/src/schema/resolvers/postsInGroups.spec.js b/backend/src/schema/resolvers/postsInGroups.spec.js index 48178ae93..55174c39d 100644 --- a/backend/src/schema/resolvers/postsInGroups.spec.js +++ b/backend/src/schema/resolvers/postsInGroups.spec.js @@ -182,6 +182,33 @@ describe('Posts in Groups', () => { roleInGroup: 'usual', }, }) + await Factory.build('emailAddress', { + email: 'new-user@example.org', + nonce: '12345', + verifiedAt: null, + }) + const result = await mutate({ + mutation: signupVerificationMutation, + variables: { + name: 'New User', + slug: 'new-user', + nonce: '12345', + password: '1234', + about: 'I am a new user!', + email: 'new-user@example.org', + termsAndConditionsAgreedVersion: '0.0.1', + }, + }) + newUser = result.data.SignupVerification + authenticatedUser = await anyUser.toJson() + await mutate({ + mutation: createPostMutation(), + variables: { + id: 'post-without-group', + title: 'A post without a group', + content: 'I am a user who does not belong to a group yet.', + }, + }) }) describe('creating posts in groups', () => { @@ -417,27 +444,6 @@ describe('Posts in Groups', () => { }) describe('as new user', () => { - beforeAll(async () => { - await Factory.build('emailAddress', { - email: 'new-user@example.org', - nonce: '12345', - verifiedAt: null, - }) - const result = await mutate({ - mutation: signupVerificationMutation, - variables: { - name: 'New User', - slug: 'new-user', - nonce: '12345', - password: '1234', - about: 'I am a new user!', - email: 'new-user@example.org', - termsAndConditionsAgreedVersion: '0.0.1', - }, - }) - newUser = result.data.SignupVerification - }) - beforeEach(async () => { authenticatedUser = newUser }) @@ -631,18 +637,6 @@ describe('Posts in Groups', () => { }) describe('filter posts', () => { - beforeAll(async () => { - authenticatedUser = newUser - await mutate({ - mutation: createPostMutation(), - variables: { - id: 'post-without-group', - title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', - }, - }) - }) - describe('without authentication', () => { beforeEach(async () => { authenticatedUser = null @@ -662,7 +656,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -690,7 +684,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -718,7 +712,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -746,7 +740,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -774,7 +768,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, { id: 'post-to-closed-group', @@ -814,7 +808,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -842,7 +836,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -870,7 +864,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -898,7 +892,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -926,7 +920,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, { id: 'post-to-closed-group', @@ -1000,7 +994,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -1037,7 +1031,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -1074,7 +1068,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -1111,7 +1105,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, { id: 'post-to-closed-group', @@ -1166,7 +1160,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, { id: 'post-to-closed-group', @@ -1211,7 +1205,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, { id: 'post-to-closed-group', @@ -1263,7 +1257,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, { id: 'post-to-hidden-group', @@ -1308,7 +1302,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -1319,6 +1313,51 @@ describe('Posts in Groups', () => { }) describe('usual member leaves', () => { + describe('public group', () => { + beforeAll(async () => { + authenticatedUser = await allGroupsUser.toJson() + await mutate({ + mutation: leaveGroupMutation(), + variables: { + groupId: 'public-group', + userId: 'all-groups-user', + }, + }) + }) + + it('still shows the posts of the public group', async () => { + const result = await query({ query: filterPosts(), variables: {} }) + expect(result.data.Post).toHaveLength(4) + expect(result).toMatchObject({ + data: { + Post: expect.arrayContaining([ + { + id: 'post-to-public-group', + title: 'A post to a public group', + content: 'I am posting into a public group as a member of the group', + }, + { + id: 'post-without-group', + title: 'A post without a group', + content: 'I am a user who does not belong to a group yet.', + }, + { + id: 'post-to-closed-group', + title: 'A post to a closed group', + content: 'I am posting into a closed group as a member of the group', + }, + { + id: 'post-to-hidden-group', + title: 'A post to a hidden group', + content: 'I am posting into a hidden group as a member of the group', + }, + ]), + }, + errors: undefined, + }) + }) + }) + describe('closed group', () => { beforeAll(async () => { authenticatedUser = await allGroupsUser.toJson() @@ -1345,7 +1384,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, { id: 'post-to-hidden-group', @@ -1385,7 +1424,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, ]), }, @@ -1427,7 +1466,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, { id: 'post-to-closed-group', @@ -1472,7 +1511,7 @@ describe('Posts in Groups', () => { { id: 'post-without-group', title: 'A post without a group', - content: 'As a new user, I do not belong to a group yet.', + content: 'I am a user who does not belong to a group yet.', }, { id: 'post-to-closed-group', From 631f34a2e5224d68279337a92e7535794b670d70 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Oct 2022 21:21:45 +0200 Subject: [PATCH 3/3] improved code and tests as suggested by @tirokk, thanks for the great review! --- backend/src/schema/resolvers/groups.js | 13 +- backend/src/schema/resolvers/posts.js | 4 +- .../schema/resolvers/postsInGroups.spec.js | 442 +++++++++--------- 3 files changed, 220 insertions(+), 239 deletions(-) diff --git a/backend/src/schema/resolvers/groups.js b/backend/src/schema/resolvers/groups.js index 55dd605ad..76564cdb3 100644 --- a/backend/src/schema/resolvers/groups.js +++ b/backend/src/schema/resolvers/groups.js @@ -287,17 +287,16 @@ export default { const session = context.driver.session() const writeTxResultPromise = session.writeTransaction(async (transaction) => { let postRestrictionCypher = '' - if (['owner', 'admin', 'usual'].includes(roleInGroup)) { - postRestrictionCypher = ` - WITH group, member, membership - FOREACH (restriction IN [(member)-[r:CANNOT_SEE]->(:Post)-[:IN]->(group) | r] | - DELETE restriction)` - } else { - // user becomes pending member + if (roleInGroup === 'pending') { postRestrictionCypher = ` WITH group, member, membership FOREACH (post IN [(p:Post)-[:IN]->(group) | p] | MERGE (member)-[:CANNOT_SEE]->(post))` + } else { + postRestrictionCypher = ` + WITH group, member, membership + FOREACH (restriction IN [(member)-[r:CANNOT_SEE]->(:Post)-[:IN]->(group) | r] | + DELETE restriction)` } const joinGroupCypher = ` diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index 86dc22f44..78515e641 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -102,7 +102,7 @@ export default { WHERE group.groupType IN ['closed', 'hidden'] AND membership.role IN ['usual', 'admin', 'owner'] WITH post, collect(user.id) AS userIds - OPTIONAL MATCH path =(blocked:User) WHERE NOT blocked.id IN userIds + OPTIONAL MATCH path =(restricted:User) WHERE NOT restricted.id IN userIds FOREACH (user IN nodes(path) | MERGE (user)-[:CANNOT_SEE]->(post) )` @@ -129,7 +129,7 @@ export default { ${groupCypher} RETURN post {.*} `, - { userId: context.user.id, params, categoryIds, groupId }, + { userId: context.user.id, categoryIds, groupId, params }, ) const [post] = createPostTransactionResponse.records.map((record) => record.get('post')) if (imageInput) { diff --git a/backend/src/schema/resolvers/postsInGroups.spec.js b/backend/src/schema/resolvers/postsInGroups.spec.js index 55174c39d..d17c928ec 100644 --- a/backend/src/schema/resolvers/postsInGroups.spec.js +++ b/backend/src/schema/resolvers/postsInGroups.spec.js @@ -59,7 +59,7 @@ beforeAll(async () => { }) afterAll(async () => { - // await cleanDatabase() + await cleanDatabase() }) describe('Posts in Groups', () => { @@ -182,24 +182,6 @@ describe('Posts in Groups', () => { roleInGroup: 'usual', }, }) - await Factory.build('emailAddress', { - email: 'new-user@example.org', - nonce: '12345', - verifiedAt: null, - }) - const result = await mutate({ - mutation: signupVerificationMutation, - variables: { - name: 'New User', - slug: 'new-user', - nonce: '12345', - password: '1234', - about: 'I am a new user!', - email: 'new-user@example.org', - termsAndConditionsAgreedVersion: '0.0.1', - }, - }) - newUser = result.data.SignupVerification authenticatedUser = await anyUser.toJson() await mutate({ mutation: createPostMutation(), @@ -213,7 +195,7 @@ describe('Posts in Groups', () => { describe('creating posts in groups', () => { describe('without membership of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await anyUser.toJson() }) @@ -267,7 +249,7 @@ describe('Posts in Groups', () => { }) describe('as a pending member of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await pendingUser.toJson() }) @@ -321,7 +303,7 @@ describe('Posts in Groups', () => { }) describe('as a member of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await allGroupsUser.toJson() }) @@ -399,7 +381,7 @@ describe('Posts in Groups', () => { describe('visibility of posts', () => { describe('query post by ID', () => { describe('without authentication', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = null }) @@ -444,7 +426,25 @@ describe('Posts in Groups', () => { }) describe('as new user', () => { - beforeEach(async () => { + beforeAll(async () => { + await Factory.build('emailAddress', { + email: 'new-user@example.org', + nonce: '12345', + verifiedAt: null, + }) + const result = await mutate({ + mutation: signupVerificationMutation, + variables: { + name: 'New User', + slug: 'new-user', + nonce: '12345', + password: '1234', + about: 'I am a new user!', + email: 'new-user@example.org', + termsAndConditionsAgreedVersion: '0.0.1', + }, + }) + newUser = result.data.SignupVerification authenticatedUser = newUser }) @@ -489,7 +489,7 @@ describe('Posts in Groups', () => { }) describe('without membership of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await anyUser.toJson() }) @@ -534,7 +534,7 @@ describe('Posts in Groups', () => { }) describe('with pending membership of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await pendingUser.toJson() }) @@ -579,7 +579,7 @@ describe('Posts in Groups', () => { }) describe('as member of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await allGroupsUser.toJson() }) @@ -638,11 +638,11 @@ describe('Posts in Groups', () => { describe('filter posts', () => { describe('without authentication', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = null }) - it('shows a the post of the public group and the post without group', async () => { + it('shows the post of the public group and the post without group', async () => { const result = await query({ query: filterPosts(), variables: {} }) expect(result.data.Post).toHaveLength(2) expect(result).toMatchObject({ @@ -666,11 +666,11 @@ describe('Posts in Groups', () => { }) describe('as new user', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = newUser }) - it('shows a the post of the public group and the post without group', async () => { + it('shows the post of the public group and the post without group', async () => { const result = await query({ query: filterPosts(), variables: {} }) expect(result.data.Post).toHaveLength(2) expect(result).toMatchObject({ @@ -694,11 +694,11 @@ describe('Posts in Groups', () => { }) describe('without membership of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await anyUser.toJson() }) - it('shows a the post of the public group and the post without group', async () => { + it('shows the post of the public group and the post without group', async () => { const result = await query({ query: filterPosts(), variables: {} }) expect(result.data.Post).toHaveLength(2) expect(result).toMatchObject({ @@ -722,11 +722,11 @@ describe('Posts in Groups', () => { }) describe('with pending membership of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await pendingUser.toJson() }) - it('shows a the post of the public group and the post without group', async () => { + it('shows the post of the public group and the post without group', async () => { const result = await query({ query: filterPosts(), variables: {} }) expect(result.data.Post).toHaveLength(2) expect(result).toMatchObject({ @@ -750,7 +750,7 @@ describe('Posts in Groups', () => { }) describe('as member of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await allGroupsUser.toJson() }) @@ -790,11 +790,11 @@ describe('Posts in Groups', () => { describe('profile page posts', () => { describe('without authentication', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = null }) - it('shows a the post of the public group and the post without group', async () => { + it('shows the post of the public group and the post without group', async () => { const result = await query({ query: profilePagePosts(), variables: {} }) expect(result.data.profilePagePosts).toHaveLength(2) expect(result).toMatchObject({ @@ -818,11 +818,11 @@ describe('Posts in Groups', () => { }) describe('as new user', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = newUser }) - it('shows a the post of the public group and the post without group', async () => { + it('shows the post of the public group and the post without group', async () => { const result = await query({ query: profilePagePosts(), variables: {} }) expect(result.data.profilePagePosts).toHaveLength(2) expect(result).toMatchObject({ @@ -846,11 +846,11 @@ describe('Posts in Groups', () => { }) describe('without membership of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await anyUser.toJson() }) - it('shows a the post of the public group and the post without group', async () => { + it('shows the post of the public group and the post without group', async () => { const result = await query({ query: profilePagePosts(), variables: {} }) expect(result.data.profilePagePosts).toHaveLength(2) expect(result).toMatchObject({ @@ -874,11 +874,11 @@ describe('Posts in Groups', () => { }) describe('with pending membership of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await pendingUser.toJson() }) - it('shows a the post of the public group and the post without group', async () => { + it('shows the post of the public group and the post without group', async () => { const result = await query({ query: profilePagePosts(), variables: {} }) expect(result.data.profilePagePosts).toHaveLength(2) expect(result).toMatchObject({ @@ -902,7 +902,7 @@ describe('Posts in Groups', () => { }) describe('as member of group', () => { - beforeEach(async () => { + beforeAll(async () => { authenticatedUser = await allGroupsUser.toJson() }) @@ -938,189 +938,189 @@ describe('Posts in Groups', () => { }) }) }) + }) - describe('searchPosts', () => { - describe('without authentication', () => { - beforeEach(async () => { - authenticatedUser = null - }) - - it('finds nothing', async () => { - const result = await query({ - query: searchPosts(), - variables: { - query: 'post', - postsOffset: 0, - firstPosts: 25, - }, - }) - expect(result.data.searchPosts.posts).toHaveLength(0) - expect(result).toMatchObject({ - data: { - searchPosts: { - postCount: 0, - posts: [], - }, - }, - }) - }) + describe('searchPosts', () => { + describe('without authentication', () => { + beforeAll(async () => { + authenticatedUser = null }) - describe('as new user', () => { - beforeEach(async () => { - authenticatedUser = newUser + it('finds nothing', async () => { + const result = await query({ + query: searchPosts(), + variables: { + query: 'post', + postsOffset: 0, + firstPosts: 25, + }, }) - - it('finds the post of the public group and the post without group', async () => { - const result = await query({ - query: searchPosts(), - variables: { - query: 'post', - postsOffset: 0, - firstPosts: 25, + expect(result.data.searchPosts.posts).toHaveLength(0) + expect(result).toMatchObject({ + data: { + searchPosts: { + postCount: 0, + posts: [], }, - }) - expect(result.data.searchPosts.posts).toHaveLength(2) - expect(result).toMatchObject({ - data: { - searchPosts: { - postCount: 2, - posts: expect.arrayContaining([ - { - id: 'post-to-public-group', - title: 'A post to a public group', - content: 'I am posting into a public group as a member of the group', - }, - { - id: 'post-without-group', - title: 'A post without a group', - content: 'I am a user who does not belong to a group yet.', - }, - ]), - }, - }, - }) + }, }) }) + }) - describe('without membership of group', () => { - beforeEach(async () => { - authenticatedUser = await anyUser.toJson() - }) - - it('finds the post of the public group and the post without group', async () => { - const result = await query({ - query: searchPosts(), - variables: { - query: 'post', - postsOffset: 0, - firstPosts: 25, - }, - }) - expect(result.data.searchPosts.posts).toHaveLength(2) - expect(result).toMatchObject({ - data: { - searchPosts: { - postCount: 2, - posts: expect.arrayContaining([ - { - id: 'post-to-public-group', - title: 'A post to a public group', - content: 'I am posting into a public group as a member of the group', - }, - { - id: 'post-without-group', - title: 'A post without a group', - content: 'I am a user who does not belong to a group yet.', - }, - ]), - }, - }, - }) - }) + describe('as new user', () => { + beforeAll(async () => { + authenticatedUser = newUser }) - describe('with pending membership of group', () => { - beforeEach(async () => { - authenticatedUser = await pendingUser.toJson() + it('finds the post of the public group and the post without group', async () => { + const result = await query({ + query: searchPosts(), + variables: { + query: 'post', + postsOffset: 0, + firstPosts: 25, + }, }) - - it('finds the post of the public group and the post without group', async () => { - const result = await query({ - query: searchPosts(), - variables: { - query: 'post', - postsOffset: 0, - firstPosts: 25, + expect(result.data.searchPosts.posts).toHaveLength(2) + expect(result).toMatchObject({ + data: { + searchPosts: { + postCount: 2, + posts: expect.arrayContaining([ + { + id: 'post-to-public-group', + title: 'A post to a public group', + content: 'I am posting into a public group as a member of the group', + }, + { + id: 'post-without-group', + title: 'A post without a group', + content: 'I am a user who does not belong to a group yet.', + }, + ]), }, - }) - expect(result.data.searchPosts.posts).toHaveLength(2) - expect(result).toMatchObject({ - data: { - searchPosts: { - postCount: 2, - posts: expect.arrayContaining([ - { - id: 'post-to-public-group', - title: 'A post to a public group', - content: 'I am posting into a public group as a member of the group', - }, - { - id: 'post-without-group', - title: 'A post without a group', - content: 'I am a user who does not belong to a group yet.', - }, - ]), - }, - }, - }) + }, }) }) + }) - describe('as member of group', () => { - beforeEach(async () => { - authenticatedUser = await allGroupsUser.toJson() + describe('without membership of group', () => { + beforeAll(async () => { + authenticatedUser = await anyUser.toJson() + }) + + it('finds the post of the public group and the post without group', async () => { + const result = await query({ + query: searchPosts(), + variables: { + query: 'post', + postsOffset: 0, + firstPosts: 25, + }, }) + expect(result.data.searchPosts.posts).toHaveLength(2) + expect(result).toMatchObject({ + data: { + searchPosts: { + postCount: 2, + posts: expect.arrayContaining([ + { + id: 'post-to-public-group', + title: 'A post to a public group', + content: 'I am posting into a public group as a member of the group', + }, + { + id: 'post-without-group', + title: 'A post without a group', + content: 'I am a user who does not belong to a group yet.', + }, + ]), + }, + }, + }) + }) + }) - it('finds all posts', async () => { - const result = await query({ - query: searchPosts(), - variables: { - query: 'post', - postsOffset: 0, - firstPosts: 25, + describe('with pending membership of group', () => { + beforeAll(async () => { + authenticatedUser = await pendingUser.toJson() + }) + + it('finds the post of the public group and the post without group', async () => { + const result = await query({ + query: searchPosts(), + variables: { + query: 'post', + postsOffset: 0, + firstPosts: 25, + }, + }) + expect(result.data.searchPosts.posts).toHaveLength(2) + expect(result).toMatchObject({ + data: { + searchPosts: { + postCount: 2, + posts: expect.arrayContaining([ + { + id: 'post-to-public-group', + title: 'A post to a public group', + content: 'I am posting into a public group as a member of the group', + }, + { + id: 'post-without-group', + title: 'A post without a group', + content: 'I am a user who does not belong to a group yet.', + }, + ]), }, - }) - expect(result.data.searchPosts.posts).toHaveLength(4) - expect(result).toMatchObject({ - data: { - searchPosts: { - postCount: 4, - posts: expect.arrayContaining([ - { - id: 'post-to-public-group', - title: 'A post to a public group', - content: 'I am posting into a public group as a member of the group', - }, - { - id: 'post-without-group', - title: 'A post without a group', - content: 'I am a user who does not belong to a group yet.', - }, - { - id: 'post-to-closed-group', - title: 'A post to a closed group', - content: 'I am posting into a closed group as a member of the group', - }, - { - id: 'post-to-hidden-group', - title: 'A post to a hidden group', - content: 'I am posting into a hidden group as a member of the group', - }, - ]), - }, + }, + }) + }) + }) + + describe('as member of group', () => { + beforeAll(async () => { + authenticatedUser = await allGroupsUser.toJson() + }) + + it('finds all posts', async () => { + const result = await query({ + query: searchPosts(), + variables: { + query: 'post', + postsOffset: 0, + firstPosts: 25, + }, + }) + expect(result.data.searchPosts.posts).toHaveLength(4) + expect(result).toMatchObject({ + data: { + searchPosts: { + postCount: 4, + posts: expect.arrayContaining([ + { + id: 'post-to-public-group', + title: 'A post to a public group', + content: 'I am posting into a public group as a member of the group', + }, + { + id: 'post-without-group', + title: 'A post without a group', + content: 'I am a user who does not belong to a group yet.', + }, + { + id: 'post-to-closed-group', + title: 'A post to a closed group', + content: 'I am posting into a closed group as a member of the group', + }, + { + id: 'post-to-hidden-group', + title: 'A post to a hidden group', + content: 'I am posting into a hidden group as a member of the group', + }, + ]), }, - }) + }, }) }) }) @@ -1140,9 +1140,6 @@ describe('Posts in Groups', () => { roleInGroup: 'usual', }, }) - }) - - beforeEach(async () => { authenticatedUser = await pendingUser.toJson() }) @@ -1185,9 +1182,6 @@ describe('Posts in Groups', () => { roleInGroup: 'usual', }, }) - }) - - beforeEach(async () => { authenticatedUser = await pendingUser.toJson() }) @@ -1237,13 +1231,10 @@ describe('Posts in Groups', () => { roleInGroup: 'pending', }, }) - }) - - beforeEach(async () => { authenticatedUser = await pendingUser.toJson() }) - it('does not shows the posts of the closed group anymore', async () => { + it('does not show the posts of the closed group anymore', async () => { const result = await query({ query: filterPosts(), variables: {} }) expect(result.data.Post).toHaveLength(3) expect(result).toMatchObject({ @@ -1282,9 +1273,6 @@ describe('Posts in Groups', () => { roleInGroup: 'pending', }, }) - }) - - beforeEach(async () => { authenticatedUser = await pendingUser.toJson() }) @@ -1370,7 +1358,7 @@ describe('Posts in Groups', () => { }) }) - it('does not shows the posts of the closed group anymore', async () => { + it('does not show the posts of the closed group anymore', async () => { const result = await query({ query: filterPosts(), variables: {} }) expect(result.data.Post).toHaveLength(3) expect(result).toMatchObject({ @@ -1446,13 +1434,10 @@ describe('Posts in Groups', () => { roleInGroup: 'usual', }, }) - }) - - beforeEach(async () => { authenticatedUser = await allGroupsUser.toJson() }) - it('does not shows the posts of the closed group', async () => { + it('does not show the posts of the closed group', async () => { const result = await query({ query: filterPosts(), variables: {} }) expect(result.data.Post).toHaveLength(3) expect(result).toMatchObject({ @@ -1491,9 +1476,6 @@ describe('Posts in Groups', () => { roleInGroup: 'usual', }, }) - }) - - beforeEach(async () => { authenticatedUser = await allGroupsUser.toJson() })