Skip to content

Commit

Permalink
Refactor show sorting and filtering in ShowControllerTest.php
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Sickert <[email protected]>
  • Loading branch information
Lapotor committed Feb 10, 2024
1 parent 20f00c2 commit 0d4cd74
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tests/Feature/Http/Controllers/ShowControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,24 @@ public function test_index(): void
],
]);

// Sort the shows by start date and take the first 5
$shows = $shows->sortBy('start_date')->values()->take($perPage);
$sortedShows = $shows->sortBy('start_date');

$sortedShows->values()->all();

// remove shows where the end or start date is not within the range
$sortedShows = $sortedShows->filter(function ($show) use ($today, $inAMonth) {
return $show->start_date->isBetween($today, $inAMonth) || $show->end_date->isBetween($today, $inAMonth);
});


// Assert that the response contains the correct show data
$response->assertJsonFragment([
'id' => $shows->first()->id,
'title' => $shows->first()->title,
'start_date' => $shows->first()->start_date,
'end_date' => $shows->first()->end_date,
'is_live' => $shows->first()->is_live,
'enabled' => $shows->first()->enabled,
'id' => $sortedShows->first()->id,
'title' => $sortedShows->first()->title,
'start_date' => $sortedShows->first()->start_date,
'end_date' => $sortedShows->first()->end_date,
'is_live' => $sortedShows->first()->is_live,
'enabled' => $sortedShows->first()->enabled,
]);
}
}

0 comments on commit 0d4cd74

Please sign in to comment.