From 85d32dafc4291ee864f8ff278af458be684243eb Mon Sep 17 00:00:00 2001 From: Kamil Date: Thu, 4 Apr 2024 14:32:37 +0200 Subject: [PATCH] #421 - fixed birthday bug --- app/Domain/DailySummaryRetriever.php | 2 +- app/Domain/EmployeesMilestonesRetriever.php | 2 +- tests/Feature/EmployeesMilestonesTest.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Domain/DailySummaryRetriever.php b/app/Domain/DailySummaryRetriever.php index 53bf1ffb..11037d4c 100644 --- a/app/Domain/DailySummaryRetriever.php +++ b/app/Domain/DailySummaryRetriever.php @@ -97,7 +97,7 @@ public function getUpcomingBirthdays(?int $limit = null): Collection $users = User::query() ->whereRelation("profile", fn(Builder $query): Builder => $query->whereNotNull("birthday")) ->get() - ->sortBy(fn(User $user): int => (int)$user->upcomingBirthday()->diffInDays(Carbon::today())); + ->sortBy(fn(User $user): int => (int)$user->upcomingBirthday()->diffInDays(Carbon::today()), descending: true); if ($limit) { return $users->take($limit); diff --git a/app/Domain/EmployeesMilestonesRetriever.php b/app/Domain/EmployeesMilestonesRetriever.php index 9f3952db..c8a1e3cf 100644 --- a/app/Domain/EmployeesMilestonesRetriever.php +++ b/app/Domain/EmployeesMilestonesRetriever.php @@ -35,7 +35,7 @@ public function getUpcomingBirthdays(?string $searchText, string $direction = "a ->search($searchText) ->get(); - return $users->sortBy(fn(User $user): int => (int)$user->upcomingBirthday()->diffInDays(Carbon::today()), descending: $direction !== "asc"); + return $users->sortBy(fn(User $user): int => (int)$user->upcomingBirthday()->diffInDays(Carbon::today()), descending: $direction !== "desc"); } public function getSeniority(?string $searchText, string $direction = "asc"): Collection diff --git a/tests/Feature/EmployeesMilestonesTest.php b/tests/Feature/EmployeesMilestonesTest.php index a5edfb0c..90eb7873 100644 --- a/tests/Feature/EmployeesMilestonesTest.php +++ b/tests/Feature/EmployeesMilestonesTest.php @@ -59,15 +59,15 @@ public function testSortingByBirthdays(): void $sortedUsersByUpcomingBirthday = $this->employeesMilestonesRetriever->getResults(null, "birthday-asc")->values(); - $this->assertEquals($user2->id, $sortedUsersByUpcomingBirthday[0]->id); + $this->assertEquals($user1->id, $sortedUsersByUpcomingBirthday[0]->id); $this->assertEquals($user3->id, $sortedUsersByUpcomingBirthday[1]->id); - $this->assertEquals($user1->id, $sortedUsersByUpcomingBirthday[2]->id); + $this->assertEquals($user2->id, $sortedUsersByUpcomingBirthday[2]->id); $sortedUsersByFurthestBirthday = $this->employeesMilestonesRetriever->getResults(null, "birthday-desc")->values(); - $this->assertEquals($user1->id, $sortedUsersByFurthestBirthday[0]->id); + $this->assertEquals($user2->id, $sortedUsersByFurthestBirthday[0]->id); $this->assertEquals($user3->id, $sortedUsersByFurthestBirthday[1]->id); - $this->assertEquals($user2->id, $sortedUsersByFurthestBirthday[2]->id); + $this->assertEquals($user1->id, $sortedUsersByFurthestBirthday[2]->id); } public function testSortingBySeniority(): void