Merge remote-tracking branch 'origin/#22-vacation-calendar' into #22-vacation-calendar
This commit is contained in:
commit
09da5cacda
@ -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
|
||||
@ -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();
|
||||
}
|
||||
|
@ -125,4 +125,4 @@ const statuses = [
|
||||
|
||||
export function useStatusInfo(status) {
|
||||
return statuses.find(statusInfo => statusInfo.value === status)
|
||||
}
|
||||
}
|
||||
|
@ -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."
|
||||
}
|
||||
|
@ -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,13 @@ 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 +136,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 +160,42 @@ 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" => __("Vacation limit has been exceeded."),
|
||||
]);
|
||||
}
|
||||
|
||||
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 +204,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 +213,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 +235,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 +244,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 +270,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 +280,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 +306,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 +322,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 +339,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."),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user