Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
novacuum committed Nov 21, 2024
1 parent 2a48906 commit 824a3f7
Showing 1 changed file with 48 additions and 14 deletions.
62 changes: 48 additions & 14 deletions tests/integration/search/BestAnswerFilterGambitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public function setUp(): void
],
'discussions' => [
['id' => 1, 'title' => __CLASS__, 'user_id' => 1, 'created_at' => Carbon::now(), 'comment_count' => 2, 'best_answer_post_id' => null],
['id' => 2, 'title' => __CLASS__, 'user_id' => 1, 'created_at' => Carbon::now(), 'comment_count' => 2, 'best_answer_post_id' => 4, 'best_answer_user_id' => 1, 'best_answer_set_at' => Carbon::now()],
['id' => 2, 'title' => __CLASS__, 'user_id' => 1, 'created_at' => Carbon::now(), 'comment_count' => 2, 'best_answer_post_id' => 4, 'best_answer_user_id' => 3, 'best_answer_set_at' => Carbon::now()],
],
'posts' => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => 'post 1', 'created_at' => Carbon::now()],
['id' => 2, 'discussion_id' => 1, 'user_id' => 2, 'type' => 'comment', 'content' => 'post 2', 'created_at' => Carbon::now()],
['id' => 3, 'discussion_id' => 2, 'user_id' => 2, 'type' => 'comment', 'content' => 'post 1', 'created_at' => Carbon::now()],
['id' => 4, 'discussion_id' => 2, 'user_id' => 1, 'type' => 'comment', 'content' => 'post 2', 'created_at' => Carbon::now()],
['id' => 4, 'discussion_id' => 2, 'user_id' => 3, 'type' => 'comment', 'content' => 'post 2', 'created_at' => Carbon::now()],
],
'tags' => [
['id' => 1, 'name' => 'Tag 1', 'slug' => 'tag-1', 'description' => 'Tag 1 description', 'color' => '#FF0000', 'position' => 0, 'parent_id' => null, 'is_restricted' => false, 'is_hidden' => false, 'is_qna' => true],
Expand All @@ -42,19 +42,16 @@ public function setUp(): void
]);
}

/**
* @test
*/
public function test_positive_filtering()
{
$response = $this->send(
$this->request(
'GET',
'/api/discussions?filter[solved-discussions]=1',
'/api/discussions',
[
'authenticatedAs' => 1,
'authenticatedAs' => 2,
]
)
)->withQueryParams(['filter' => ['solved-discussions' => 1]])
);

$this->assertEquals(200, $response->getStatusCode());
Expand All @@ -65,19 +62,56 @@ public function test_positive_filtering()
$this->assertEquals(2, $data['data'][0]['id']);
}

/**
* @test
*/
public function test_negative_filtering()
{
$response = $this->send(
$this->request(
'GET',
'/api/discussions?filter[!solved-discussions]=1',
'/api/discussions',
[
'authenticatedAs' => 1,
'authenticatedAs' => 2,
]
)
)->withQueryParams(['filter' => ['-solved-discussions' => 1]])
);

$this->assertEquals(200, $response->getStatusCode());

$data = json_decode($response->getBody()->getContents(), true);

$this->assertCount(1, $data['data']);
$this->assertEquals(1, $data['data'][0]['id']);
}

public function test_positive_search()
{
$response = $this->send(
$this->request(
'GET',
'/api/discussions',
[
'authenticatedAs' => 2,
]
)->withQueryParams(['filter' => ['q' => 'is:solved']])
);

$this->assertEquals(200, $response->getStatusCode());

$data = json_decode($response->getBody()->getContents(), true);

$this->assertCount(1, $data['data']);
$this->assertEquals(2, $data['data'][0]['id']);
}

public function test_negative_search()
{
$response = $this->send(
$this->request(
'GET',
'/api/discussions',
[
'authenticatedAs' => 2,
]
)->withQueryParams(['filter' => ['q' => '-is:solved']])
);

$this->assertEquals(200, $response->getStatusCode());
Expand Down

0 comments on commit 824a3f7

Please sign in to comment.