From ab5d308caaaf9a492d54a625c3051416740c9c97 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 5 Oct 2022 08:38:05 +0200 Subject: [PATCH] test profile page posts --- backend/src/db/graphql/posts.js | 17 +- .../schema/resolvers/postsInGroups.spec.js | 159 +++++++++++++++++- 2 files changed, 174 insertions(+), 2 deletions(-) diff --git a/backend/src/db/graphql/posts.js b/backend/src/db/graphql/posts.js index 571f853ce..e758c523e 100644 --- a/backend/src/db/graphql/posts.js +++ b/backend/src/db/graphql/posts.js @@ -55,4 +55,19 @@ export const filterPosts = () => { ` } -// fill queries in here +export const profilePagePosts = () => { + return gql` + query profilePagePosts( + $filter: _PostFilter + $first: Int + $offset: Int + $orderBy: [_PostOrdering] + ) { + profilePagePosts(filter: $filter, first: $first, offset: $offset, orderBy: $orderBy) { + id + title + content + } + } + ` +} diff --git a/backend/src/schema/resolvers/postsInGroups.spec.js b/backend/src/schema/resolvers/postsInGroups.spec.js index 530f2ca0f..5505feece 100644 --- a/backend/src/schema/resolvers/postsInGroups.spec.js +++ b/backend/src/schema/resolvers/postsInGroups.spec.js @@ -3,7 +3,12 @@ import Factory, { cleanDatabase } from '../../db/factories' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' import { createGroupMutation, changeGroupMemberRoleMutation } from '../../db/graphql/groups' -import { createPostMutation, postQuery, filterPosts } from '../../db/graphql/posts' +import { + createPostMutation, + postQuery, + filterPosts, + profilePagePosts, +} from '../../db/graphql/posts' // eslint-disable-next-line no-unused-vars import { DESCRIPTION_WITHOUT_HTML_LENGTH_MIN } from '../../constants/groups' import CONFIG from '../../config' @@ -783,5 +788,157 @@ describe('Posts in Groups', () => { }) }) }) + + describe('profile page posts', () => { + describe('without authentication', () => { + beforeEach(async () => { + authenticatedUser = null + }) + + it('shows a 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({ + data: { + profilePagePosts: 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: 'As a new user, I do not belong to a group yet.', + }, + ]), + }, + errors: undefined, + }) + }) + }) + + describe('as new user', () => { + beforeEach(async () => { + authenticatedUser = newUser + }) + + it('shows a 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({ + data: { + profilePagePosts: 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: 'As a new user, I do not belong to a group yet.', + }, + ]), + }, + errors: undefined, + }) + }) + }) + + describe('without membership of group', () => { + beforeEach(async () => { + authenticatedUser = await anyUser.toJson() + }) + + it('shows a 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({ + data: { + profilePagePosts: 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: 'As a new user, I do not belong to a group yet.', + }, + ]), + }, + errors: undefined, + }) + }) + }) + + describe('with pending membership of group', () => { + beforeEach(async () => { + authenticatedUser = await pendingUser.toJson() + }) + + it('shows a 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({ + data: { + profilePagePosts: 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: 'As a new user, I do not belong to a group yet.', + }, + ]), + }, + errors: undefined, + }) + }) + }) + + describe('as member of group', () => { + beforeEach(async () => { + authenticatedUser = await allGroupsUser.toJson() + }) + + it('shows all posts', async () => { + const result = await query({ query: profilePagePosts(), variables: {} }) + expect(result.data.profilePagePosts).toHaveLength(4) + expect(result).toMatchObject({ + data: { + profilePagePosts: 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: 'As a new user, I do 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, + }) + }) + }) + }) }) })