From e090ac6998c84397c0f57209409e0e5ef4f7e525 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 15 Apr 2020 14:32:13 +0200 Subject: [PATCH] specs for searches by type --- backend/src/schema/resolvers/searches.spec.js | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/backend/src/schema/resolvers/searches.spec.js b/backend/src/schema/resolvers/searches.spec.js index 5c08497cc..8d0d3b4eb 100644 --- a/backend/src/schema/resolvers/searches.spec.js +++ b/backend/src/schema/resolvers/searches.spec.js @@ -47,6 +47,21 @@ const searchQuery = gql` } } ` + +const searchPostQuery = gql` + query($query: String!, $firstPosts: Int, $postsOffset: Int) { + searchPosts(query: $query, firstPosts: $firstPosts, postsOffset: $postsOffset) { + postCount + posts { + __typename + id + title + content + } + } + } +` + describe('resolvers/searches', () => { let variables @@ -416,6 +431,128 @@ und hinter tausend Stäben keine Welt.`, }) }) + describe('adding a user and a hashtag with a name that is content of a post', () => { + beforeAll(async () => { + await Promise.all([ + Factory.build('user', { + id: 'f-user', + name: 'Peter Panther', + slug: 'peter-panther', + }), + await Factory.build('tag', { id: 'Panther' }), + ]) + }) + + describe('query the word that contains the post, the hashtag and the name of the user', () => { + it('finds the user, the post and the hashtag', async () => { + variables = { query: 'panther' } + await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({ + data: { + searchResults: expect.arrayContaining([ + { + __typename: 'User', + id: 'f-user', + name: 'Peter Panther', + slug: 'peter-panther', + }, + { + __typename: 'Post', + id: 'd-post', + title: 'Der Panther', + content: `Sein Blick ist vom Vorübergehn der Stäbe
+so müd geworden, daß er nichts mehr hält.
+Ihm ist, als ob es tausend Stäbe gäbe
+und hinter tausend Stäben keine Welt.`, + }, + { + __typename: 'Tag', + id: 'Panther', + }, + ]), + }, + errors: undefined, + }) + }) + }) + + describe('@query the word that contains the post, the hashtag and the name of the user', () => { + it('only finds the user', async () => { + variables = { query: '@panther' } + await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({ + data: { + searchResults: expect.not.arrayContaining([ + { + __typename: 'Post', + id: 'd-post', + title: 'Der Panther', + content: `Sein Blick ist vom Vorübergehn der Stäbe
+so müd geworden, daß er nichts mehr hält.
+Ihm ist, als ob es tausend Stäbe gäbe
+und hinter tausend Stäben keine Welt.`, + }, + { + __typename: 'Tag', + id: 'Panther', + }, + ]), + }, + errors: undefined, + }) + }) + }) + + describe('!query the word that contains the post, the hashtag and the name of the user', () => { + it('only finds the post', async () => { + variables = { query: '!panther' } + await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({ + data: { + searchResults: expect.not.arrayContaining([ + { + __typename: 'User', + id: 'f-user', + name: 'Peter Panther', + slug: 'peter-panther', + }, + { + __typename: 'Tag', + id: 'Panther', + }, + ]), + }, + errors: undefined, + }) + }) + }) + + describe('#query the word that contains the post, the hashtag and the name of the user', () => { + it('only finds the hashtag', async () => { + variables = { query: '#panther' } + await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({ + data: { + searchResults: expect.not.arrayContaining([ + { + __typename: 'User', + id: 'f-user', + name: 'Peter Panther', + slug: 'peter-panther', + }, + { + __typename: 'Post', + id: 'd-post', + title: 'Der Panther', + content: `Sein Blick ist vom Vorübergehn der Stäbe
+so müd geworden, daß er nichts mehr hält.
+Ihm ist, als ob es tausend Stäbe gäbe
+und hinter tausend Stäben keine Welt.`, + }, + ]), + }, + errors: undefined, + }) + }) + }) + }) + describe('adding a post, written by a user who is muted by the authenticated user', () => { beforeAll(async () => { const mutedUser = await Factory.build('user', { @@ -477,6 +614,30 @@ und hinter tausend Stäben keine Welt.`, }) }) }) + + describe('searchPostQuery', () => { + describe('query with limit 1', () => { + it('has a count greater than 1', async () => { + variables = { query: 'beitrag', firstPosts: 1, postsOffset: 0 } + await expect(query({ query: searchPostQuery, variables })).resolves.toMatchObject({ + data: { + searchPosts: { + postCount: 2, + posts: [ + { + __typename: 'Post', + id: 'a-post', + title: 'Beitrag', + content: 'Ein erster Beitrag', + }, + ], + }, + }, + errors: undefined, + }) + }) + }) + }) }) }) })