Skip to content

Commit

Permalink
#354 - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
EwelinaSkrzypacz committed Oct 11, 2023
1 parent 927589d commit 1748464
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Support\Collection;
use Toby\Eloquent\Models\User;

class EmployeesMilestoneRetriever
class EmployeesMilestonesRetriever
{
public function __construct(
protected VacationTypeConfigRetriever $configRetriever,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use Illuminate\Http\Request;
use Inertia\Response;
use Toby\Domain\EmployeesMilestoneRetriever;
use Toby\Domain\EmployeesMilestonesRetriever;
use Toby\Infrastructure\Http\Resources\EmployeeMilestoneResource;

class EmployeesMilestonesController extends Controller
{
public function index(Request $request, EmployeesMilestoneRetriever $employeesMilestoneRetriever): Response
public function index(Request $request, EmployeesMilestonesRetriever $employeesMilestoneRetriever): Response
{
$searchText = $request->query("search");
$sort = $request->query("sort");
Expand Down
2 changes: 1 addition & 1 deletion app/Infrastructure/Http/Requests/UserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function rules(): array
"position" => ["required"],
"employmentForm" => ["required", new Enum(EmploymentForm::class)],
"employmentDate" => ["required", "date_format:Y-m-d"],
"birthday" => ["nullable", "date_format:Y-m-d", "before:today"],
"birthday" => ["required", "nullable", "date_format:Y-m-d", "before:today"],
"slackId" => [],
"nextMedicalExamDate" => ["nullable", "after:lastMedicalExamDate"],
"nextOhsTrainingDate" => ["nullable", "after:lastOhsTrainingDate"],
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/EmployeesMilestonesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
use Illuminate\Support\Carbon;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\FeatureTestCase;
use Toby\Domain\EmployeesMilestoneRetriever;
use Toby\Domain\EmployeesMilestonesRetriever;
use Toby\Eloquent\Models\User;

class EmployeesMilestonesTest extends FeatureTestCase
{
use DatabaseMigrations;

protected EmployeesMilestoneRetriever $employeesMilestoneRetriever;
protected EmployeesMilestonesRetriever $employeesMilestonesRetriever;

protected function setUp(): void
{
parent::setUp();

$this->employeesMilestoneRetriever = $this->app->make(EmployeesMilestoneRetriever::class);
$this->employeesMilestonesRetriever = $this->app->make(EmployeesMilestonesRetriever::class);
}

public function testUserCanSeeEmployeesMilestonesList(): void
Expand Down Expand Up @@ -57,13 +57,13 @@ public function testSortingByBirthdays(): void
->employee()
->create();

$sortedUsersByUpcomingBirthday = $this->employeesMilestoneRetriever->getResults(null, "birthday-asc")->values();
$sortedUsersByUpcomingBirthday = $this->employeesMilestonesRetriever->getResults(null, "birthday-asc")->values();

$this->assertEquals($user1->id, $sortedUsersByUpcomingBirthday[0]->id);
$this->assertEquals($user3->id, $sortedUsersByUpcomingBirthday[1]->id);
$this->assertEquals($user2->id, $sortedUsersByUpcomingBirthday[2]->id);

$sortedUsersByFurthestBirthday = $this->employeesMilestoneRetriever->getResults(null, "birthday-desc")->values();
$sortedUsersByFurthestBirthday = $this->employeesMilestonesRetriever->getResults(null, "birthday-desc")->values();

$this->assertEquals($user2->id, $sortedUsersByFurthestBirthday[0]->id);
$this->assertEquals($user3->id, $sortedUsersByFurthestBirthday[1]->id);
Expand All @@ -87,13 +87,13 @@ public function testSortingBySeniority(): void
->employee()
->create();

$sortedUsersByLongestSeniority = $this->employeesMilestoneRetriever->getResults(null, "seniority-asc")->values();
$sortedUsersByLongestSeniority = $this->employeesMilestonesRetriever->getResults(null, "seniority-asc")->values();

$this->assertEquals($user3->id, $sortedUsersByLongestSeniority[0]->id);
$this->assertEquals($user2->id, $sortedUsersByLongestSeniority[1]->id);
$this->assertEquals($user1->id, $sortedUsersByLongestSeniority[2]->id);

$sortedUsersByShortestSeniority = $this->employeesMilestoneRetriever->getResults(null, "seniority-desc")->values();
$sortedUsersByShortestSeniority = $this->employeesMilestonesRetriever->getResults(null, "seniority-desc")->values();

$this->assertEquals($user1->id, $sortedUsersByShortestSeniority[0]->id);
$this->assertEquals($user2->id, $sortedUsersByShortestSeniority[1]->id);
Expand Down
7 changes: 7 additions & 0 deletions tests/Feature/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function testAdminCanCreateUser(): void
"email" => "[email protected]",
"employmentForm" => EmploymentForm::B2bContract->value,
"employmentDate" => Carbon::now()->toDateString(),
"birthday" => Carbon::create(1990, 5, 31)->toDateString(),
])
->assertSessionHasNoErrors();

Expand All @@ -121,6 +122,7 @@ public function testAdminCanCreateUser(): void
"position" => "Test position",
"employment_form" => EmploymentForm::B2bContract->value,
"employment_date" => Carbon::now()->toDateString(),
"birthday" => Carbon::create(1990, 5, 31)->toDateString(),
]);
}

Expand All @@ -137,6 +139,7 @@ public function testItCreatesProperPermissionsWhileCreatingUser(): void
"email" => "[email protected]",
"employmentForm" => EmploymentForm::B2bContract->value,
"employmentDate" => Carbon::now()->toDateString(),
"birthday" => Carbon::create(1990, 5, 31)->toDateString(),
])
->assertSessionHasNoErrors();

Expand Down Expand Up @@ -165,6 +168,7 @@ public function testAdminCanEditUser(): void
"last_name" => $user->profile->last_name,
"employment_form" => $user->profile->employment_form->value,
"employment_date" => $user->profile->employment_date->toDateString(),
"birthday" => $user->profile->birthday->toDateString(),
]);

$this->actingAs($admin)
Expand All @@ -176,6 +180,7 @@ public function testAdminCanEditUser(): void
"position" => "Test position",
"employmentForm" => EmploymentForm::B2bContract->value,
"employmentDate" => Carbon::now()->toDateString(),
"birthday" => Carbon::create(1990, 5, 31)->toDateString(),
])
->assertSessionHasNoErrors();

Expand All @@ -192,6 +197,7 @@ public function testAdminCanEditUser(): void
"position" => "Test position",
"employment_form" => EmploymentForm::B2bContract->value,
"employment_date" => Carbon::now()->toDateString(),
"birthday" => Carbon::create(1990, 5, 31)->toDateString(),
]);
}

Expand Down Expand Up @@ -239,6 +245,7 @@ public function testChangingUserRoleUpdatesPermissions(): void
"position" => "Test position",
"employmentForm" => EmploymentForm::B2bContract->value,
"employmentDate" => Carbon::now()->toDateString(),
"birthday" => Carbon::create(1990, 5, 31)->toDateString(),
])
->assertSessionHasNoErrors();

Expand Down

0 comments on commit 1748464

Please sign in to comment.