From 2bf2b99e28b6f1eaafa87f073b2125fd1d4fbd6f Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 14 Feb 2022 15:26:50 +0100 Subject: [PATCH 1/3] #22 - fix --- resources/js/Composables/statusInfo.js | 2 +- tests/Feature/VacationRequestTest.php | 84 +++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 8 deletions(-) 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."), ]); } } From 885dcdf9bb28e52ca678fd958c206c07929edec5 Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 14 Feb 2022 15:29:24 +0100 Subject: [PATCH 2/3] #22 - fix --- app/Domain/Validation/Rules/DoesNotExceedLimitRule.php | 2 +- resources/lang/pl.json | 2 +- tests/Feature/VacationRequestTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php index 0fb6d1d..26705a8 100644 --- a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php +++ b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php @@ -37,7 +37,7 @@ class DoesNotExceedLimitRule implements VacationRequestRule public function errorMessage(): string { - return __("You have exceeded your vacation limit."); + return __("Vacation limit has been exceeded."); } protected function getUserVacationLimit(User $user, YearPeriod $yearPeriod): int diff --git a/resources/lang/pl.json b/resources/lang/pl.json index 01cf187..7979b2a 100644 --- a/resources/lang/pl.json +++ b/resources/lang/pl.json @@ -28,7 +28,7 @@ "accepted_by_administrative": "Zaakceptowany przez administracyjnego", "You have pending vacation request in this range.": "Masz oczekujący wniosek urlopowy w tym zakresie dat.", "You have approved vacation request in this range.": "Masz zaakceptowany wniosek urlopowy w tym zakresie dat.", - "You have exceeded your vacation limit.": "Przekroczyłeś/aś limit urlopu.", + "Vacation limit has been exceeded.": "Limit urlopu został przekroczony.", "Vacation needs minimum one day.": "Urlop musi być co najmniej na jeden dzień.", "The vacation request cannot be created at the turn of the year.": "Wniosek urlopowy nie może zostać złożony na przełomie roku." } diff --git a/tests/Feature/VacationRequestTest.php b/tests/Feature/VacationRequestTest.php index 4cc7f86..2aab28e 100644 --- a/tests/Feature/VacationRequestTest.php +++ b/tests/Feature/VacationRequestTest.php @@ -181,7 +181,7 @@ class VacationRequestTest extends FeatureTestCase "comment" => "Comment for the vacation request.", ]) ->assertSessionHasErrors([ - "vacationRequest" => __("You have exceeded your vacation limit."), + "vacationRequest" => __("Vacation limit has been exceeded."), ]); } From 131924da766e4d4d4d5b8eb9dd75c5630b19ecbc Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 14 Feb 2022 15:30:09 +0100 Subject: [PATCH 3/3] #22 - fix --- app/Domain/Validation/Rules/DoesNotExceedLimitRule.php | 4 ++-- tests/Feature/VacationRequestTest.php | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php index 26705a8..c8c9ab5 100644 --- a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php +++ b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php @@ -52,8 +52,8 @@ class DoesNotExceedLimitRule implements VacationRequestRule ->whereRelation( "vacationRequest", fn(Builder $query) => $query - ->whereIn("type", $this->getLimitableVacationTypes()) - ->noStates(VacationRequestState::failedStates()), + ->whereIn("type", $this->getLimitableVacationTypes()) + ->noStates(VacationRequestState::failedStates()), ) ->count(); } diff --git a/tests/Feature/VacationRequestTest.php b/tests/Feature/VacationRequestTest.php index 2aab28e..5b40026 100644 --- a/tests/Feature/VacationRequestTest.php +++ b/tests/Feature/VacationRequestTest.php @@ -56,14 +56,13 @@ class VacationRequestTest extends FeatureTestCase $currentYearPeriod = YearPeriod::current(); - VacationLimit::factory([ + VacationLimit::factory([ "days" => 20, ]) ->for($user) ->for($currentYearPeriod) ->create(); - $this->actingAs($user) ->post("/vacation-requests", [ "type" => VacationType::VACATION->value, @@ -185,7 +184,6 @@ class VacationRequestTest extends FeatureTestCase ]); } - public function testUserCannotCreateVacationRequestAtWeekend(): void { $user = User::factory()->createQuietly();