Skip to content

Commit

Permalink
#421 - birthday bug (#422)
Browse files Browse the repository at this point in the history
#421 - fixed birthday bug
  • Loading branch information
kamilpiech97 authored Apr 4, 2024
1 parent 75ecb04 commit 14c69e4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Domain/DailySummaryRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/Domain/EmployeesMilestonesRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/EmployeesMilestonesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 14c69e4

Please sign in to comment.