From 0d4cd74aa10006912a7bdf82900586c0fae9d5e7 Mon Sep 17 00:00:00 2001 From: Valentin Sickert <17144397+Lapotor@users.noreply.github.com> Date: Sat, 10 Feb 2024 02:00:53 +0100 Subject: [PATCH] Refactor show sorting and filtering in ShowControllerTest.php Signed-off-by: Valentin Sickert <17144397+Lapotor@users.noreply.github.com> --- .../Http/Controllers/ShowControllerTest.php | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/Feature/Http/Controllers/ShowControllerTest.php b/tests/Feature/Http/Controllers/ShowControllerTest.php index 6d18238e..25f6a535 100644 --- a/tests/Feature/Http/Controllers/ShowControllerTest.php +++ b/tests/Feature/Http/Controllers/ShowControllerTest.php @@ -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, ]); } }