diff --git a/resources/js/Composables/statusInfo.js b/resources/js/Composables/statusInfo.js index a56ed1e..1d73c5a 100644 --- a/resources/js/Composables/statusInfo.js +++ b/resources/js/Composables/statusInfo.js @@ -125,4 +125,4 @@ const statuses = [ export function useStatusInfo(status) { return statuses.find(statusInfo => statusInfo.value === status) -} \ No newline at end of file +} diff --git a/tests/Feature/VacationRequestTest.php b/tests/Feature/VacationRequestTest.php index 94416da..4cc7f86 100644 --- a/tests/Feature/VacationRequestTest.php +++ b/tests/Feature/VacationRequestTest.php @@ -12,6 +12,7 @@ use Toby\Domain\Enums\VacationRequestState; use Toby\Domain\Enums\VacationType; use Toby\Domain\PolishHolidaysRetriever; use Toby\Eloquent\Models\User; +use Toby\Eloquent\Models\VacationLimit; use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\YearPeriod; @@ -55,6 +56,14 @@ class VacationRequestTest extends FeatureTestCase $currentYearPeriod = YearPeriod::current(); + VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + $this->actingAs($user) ->post("/vacation-requests", [ "type" => VacationType::VACATION->value, @@ -128,6 +137,13 @@ class VacationRequestTest extends FeatureTestCase $technicalApprover = User::factory()->createQuietly(); $currentYearPeriod = YearPeriod::current(); + $vacationLimit = VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + $vacationRequest = VacationRequest::factory([ "state" => VacationRequestState::WAITING_FOR_TECHNICAL, "type" => VacationType::VACATION, @@ -145,11 +161,43 @@ class VacationRequestTest extends FeatureTestCase ]); } + public function testUserCannotCreateVacationRequestIfHeExceedsHisVacationLimit(): void + { + $user = User::factory()->createQuietly(); + $currentYearPeriod = YearPeriod::current(); + + VacationLimit::factory([ + "days" => 3, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + $this->actingAs($user) + ->post("/vacation-requests", [ + "type" => VacationType::VACATION->value, + "from" => Carbon::create($currentYearPeriod->year, 2, 7)->toDateString(), + "to" => Carbon::create($currentYearPeriod->year, 2, 11)->toDateString(), + "comment" => "Comment for the vacation request.", + ]) + ->assertSessionHasErrors([ + "vacationRequest" => __("You have exceeded your vacation limit."), + ]); + } + + public function testUserCannotCreateVacationRequestAtWeekend(): void { $user = User::factory()->createQuietly(); $currentYearPeriod = YearPeriod::current(); + VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + $this->actingAs($user) ->post("/vacation-requests", [ "type" => VacationType::VACATION->value, @@ -158,7 +206,7 @@ class VacationRequestTest extends FeatureTestCase "comment" => "Vacation at weekend.", ]) ->assertSessionHasErrors([ - "vacationRequest" => trans("Vacation needs minimum one day."), + "vacationRequest" => __("Vacation needs minimum one day."), ]); } @@ -167,6 +215,13 @@ class VacationRequestTest extends FeatureTestCase $user = User::factory()->createQuietly(); $currentYearPeriod = YearPeriod::current(); + VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + foreach ($this->polishHolidaysRetriever->getForYearPeriod($currentYearPeriod) as $holiday) { $currentYearPeriod->holidays()->create([ "name" => $holiday["name"], @@ -182,7 +237,7 @@ class VacationRequestTest extends FeatureTestCase "comment" => "Vacation at holiday.", ]) ->assertSessionHasErrors([ - "vacationRequest" => trans("Vacation needs minimum one day."), + "vacationRequest" => __("Vacation needs minimum one day."), ]); } @@ -191,6 +246,13 @@ class VacationRequestTest extends FeatureTestCase $user = User::factory()->createQuietly(); $currentYearPeriod = YearPeriod::current(); + VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + VacationRequest::factory([ "type" => VacationType::VACATION->value, "state" => VacationRequestState::WAITING_FOR_TECHNICAL, @@ -210,8 +272,9 @@ class VacationRequestTest extends FeatureTestCase "comment" => "Another comment for the another vacation request.", ]) ->assertSessionHasErrors([ - "vacationRequest" => trans("You have pending vacation request in this range."), - ]); + "vacationRequest" => __("You have pending vacation request in this range."), + ]) + ; } public function testUserCannotCreateVacationRequestIfHeHasApprovedVacationRequestInThisRange(): void @@ -219,6 +282,13 @@ class VacationRequestTest extends FeatureTestCase $user = User::factory()->createQuietly(); $currentYearPeriod = YearPeriod::current(); + $vacationLimit = VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + VacationRequest::factory([ "type" => VacationType::VACATION->value, "state" => VacationRequestState::APPROVED, @@ -238,7 +308,7 @@ class VacationRequestTest extends FeatureTestCase "comment" => "Another comment for the another vacation request.", ]) ->assertSessionHasErrors([ - "vacationRequest" => trans("You have approved vacation request in this range."), + "vacationRequest" => __("You have approved vacation request in this range."), ]); } @@ -254,7 +324,7 @@ class VacationRequestTest extends FeatureTestCase "comment" => "Comment for the vacation request.", ]) ->assertSessionHasErrors([ - "vacationRequest" => trans("Vacation needs minimum one day."), + "vacationRequest" => __("Vacation needs minimum one day."), ]); } @@ -271,7 +341,7 @@ class VacationRequestTest extends FeatureTestCase "comment" => "Comment for the vacation request.", ]) ->assertSessionHasErrors([ - "vacationRequest" => trans("The vacation request cannot be created at the turn of the year."), + "vacationRequest" => __("The vacation request cannot be created at the turn of the year."), ]); } }