Skip to content

Commit

Permalink
ordering by created_at (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: dawid.miklas <[email protected]>
  • Loading branch information
dicani0 and dawid.miklas authored May 24, 2023
1 parent 6225018 commit 16e6146
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Http/Requests/QuestionnaireListingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function rules(): array
{
return [
'title' => ['sometimes', 'string'],
'order_by' => ['sometimes', 'string', 'in:id,title'],
'order_by' => ['sometimes', 'string', 'in:id,title,created_at'],
'order' => ['sometimes', 'string', 'in:ASC,DESC'],
];
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Api/QuestionnaireListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ public function testAdminCanListQuestionnaireWithFiltersAndSorts(): void
$questionnaireOne = Questionnaire::factory()->create([
'title' => 'one',
'active' => true,
'created_at' => now()->subDays(1),
]);

$questionnaireTwo = Questionnaire::factory()->create([
'title' => 'two',
'active' => true,
'created_at' => now(),
]);

$this
Expand All @@ -105,6 +107,26 @@ public function testAdminCanListQuestionnaireWithFiltersAndSorts(): void
'id' => $questionnaireOne->id,
]);

$response = $this
->actingAs($this->user, 'api')
->json('GET', '/api/admin/questionnaire', [
'order_by' => 'created_at',
'order' => 'ASC',
]);

$this->assertTrue($response->json('data.0.id') === $questionnaireOne->getKey());
$this->assertTrue($response->json('data.1.id') === $questionnaireTwo->getKey());

$response = $this
->actingAs($this->user, 'api')
->json('GET', '/api/admin/questionnaire', [
'order_by' => 'created_at',
'order' => 'DESC',
]);

$this->assertTrue($response->json('data.0.id') === $questionnaireTwo->getKey());
$this->assertTrue($response->json('data.1.id') === $questionnaireOne->getKey());

$response = $this
->actingAs($this->user, 'api')
->json('GET', '/api/admin/questionnaire', [
Expand Down

0 comments on commit 16e6146

Please sign in to comment.