From 26c3bcdb74f78d6ad6b46f19ec410e0219059aee Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 7 Mar 2019 00:21:43 +0100 Subject: [PATCH] Add regression test for #1738 This should ensure we can always search for search terms that appear either only in the subject or only in the text of discussions. --- .../ListDiscussionsControllerTest.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/integration/api/Controller/ListDiscussionsControllerTest.php b/tests/integration/api/Controller/ListDiscussionsControllerTest.php index 24f476038..c9d791e74 100644 --- a/tests/integration/api/Controller/ListDiscussionsControllerTest.php +++ b/tests/integration/api/Controller/ListDiscussionsControllerTest.php @@ -72,4 +72,30 @@ class ListDiscussionsControllerTest extends ApiControllerTestCase $this->assertEquals(200, $response->getStatusCode()); } + + /** + * @test + */ + public function can_search_for_word_in_title_and_post() + { + $this->database()->table('posts')->insert([ + ['id' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '

not in text

'], + ['id' => 3, 'discussion_id' => 3, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '

lightsail in text

'], + ]); + + $this->database()->table('discussions')->insert([ + ['id' => 2, 'title' => 'lightsail in title', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 2, 'comment_count' => 1], + ['id' => 3, 'title' => 'not in title', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 3, 'comment_count' => 1], + ]); + + $response = $this->callWith([], [ + 'filter' => ['q' => 'lightsail'], + 'include' => 'mostRelevantPost' + ]); + $data = json_decode($response->getBody()->getContents(), true); + $ids = array_map(function ($row) { return $row['id']; }, $data['data']); + + // Order-independent comparison + $this->assertEquals(['2', '3'], $ids, 'IDs do not match', 0.0, 10, true); + } }