wip
This commit is contained in:
parent
93f0151b14
commit
3c43f6814d
@ -6,15 +6,12 @@ namespace Toby\Architecture\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
use Toby\Eloquent\Observers\UserObserver;
|
||||
use Toby\Eloquent\Observers\YearPeriodObserver;
|
||||
|
||||
class ObserverServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot(): void
|
||||
{
|
||||
User::observe(UserObserver::class);
|
||||
YearPeriod::observe(YearPeriodObserver::class);
|
||||
}
|
||||
}
|
||||
|
33
app/Domain/Actions/CreateUserAction.php
Normal file
33
app/Domain/Actions/CreateUserAction.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Actions;
|
||||
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class CreateUserAction
|
||||
{
|
||||
public function execute(array $data): User
|
||||
{
|
||||
$user = new User($data);
|
||||
|
||||
$user->save();
|
||||
|
||||
$this->createVacationLimitsFor($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function createVacationLimitsFor(User $user): void
|
||||
{
|
||||
$yearPeriods = YearPeriod::all();
|
||||
|
||||
foreach ($yearPeriods as $yearPeriod) {
|
||||
$user->vacationLimits()->create([
|
||||
"year_period_id" => $yearPeriod->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,22 +2,30 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Observers;
|
||||
namespace Toby\Domain\Actions;
|
||||
|
||||
use Toby\Domain\PolishHolidaysRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class YearPeriodObserver
|
||||
class CreateYearPeriodAction
|
||||
{
|
||||
public function __construct(
|
||||
protected PolishHolidaysRetriever $polishHolidaysRetriever,
|
||||
) {}
|
||||
|
||||
public function created(YearPeriod $yearPeriod): void
|
||||
public function execute(int $year): YearPeriod
|
||||
{
|
||||
$yearPeriod = new YearPeriod([
|
||||
"year" => $year,
|
||||
]);
|
||||
|
||||
$yearPeriod->save();
|
||||
|
||||
$this->createVacationLimitsFor($yearPeriod);
|
||||
$this->createHolidaysFor($yearPeriod);
|
||||
|
||||
return $yearPeriod;
|
||||
}
|
||||
|
||||
protected function createVacationLimitsFor(YearPeriod $yearPeriod): void
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Toby\Domain;
|
||||
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
@ -55,7 +54,7 @@ class CalendarGenerator
|
||||
{
|
||||
return Vacation::query()
|
||||
->whereBetween("date", [$period->start, $period->end])
|
||||
->whereRelation("vacationRequest", fn(Builder $query) => $query->states(VacationRequestStatesRetriever::successStates()))
|
||||
->approved()
|
||||
->with("vacationRequest")
|
||||
->get()
|
||||
->groupBy(fn(Vacation $vacation) => $vacation->date->toDateString());
|
||||
|
@ -25,7 +25,6 @@ use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\States\VacationRequest\Approved;
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\Vacation;
|
||||
@ -189,7 +188,7 @@ class TimesheetPerUserSheet implements WithTitle, WithHeadings, WithEvents, With
|
||||
return $user->vacations()
|
||||
->with("vacationRequest")
|
||||
->whereBetween("date", [$period->start, $period->end])
|
||||
->whereRelation("vacationRequest", "state", Approved::$name)
|
||||
->approved()
|
||||
->get()
|
||||
->groupBy(
|
||||
[
|
||||
|
@ -88,7 +88,7 @@ class UserVacationStatsRetriever
|
||||
$limit = $user->vacationLimits()
|
||||
->where("year_period_id", $yearPeriod->id)
|
||||
->first()
|
||||
->days;
|
||||
?->days;
|
||||
|
||||
return $limit ?? 0;
|
||||
}
|
||||
|
@ -71,18 +71,6 @@ class User extends Authenticatable
|
||||
return $this->hasMany(Vacation::class);
|
||||
}
|
||||
|
||||
public function scopeSearch(Builder $query, ?string $text): Builder
|
||||
{
|
||||
if ($text === null) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query
|
||||
->where("first_name", "ILIKE", $text)
|
||||
->orWhere("last_name", "ILIKE", $text)
|
||||
->orWhere("email", "ILIKE", $text);
|
||||
}
|
||||
|
||||
public function getAvatar(): string
|
||||
{
|
||||
return $this->getAvatarGenerator()
|
||||
@ -108,6 +96,28 @@ class User extends Authenticatable
|
||||
->exists();
|
||||
}
|
||||
|
||||
public function scopeSearch(Builder $query, ?string $text): Builder
|
||||
{
|
||||
if ($text === null) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query
|
||||
->where("first_name", "ILIKE", $text)
|
||||
->orWhere("last_name", "ILIKE", $text)
|
||||
->orWhere("email", "ILIKE", $text);
|
||||
}
|
||||
|
||||
public function scopeWithVacationLimitIn(Builder $query, YearPeriod $yearPeriod): Builder
|
||||
{
|
||||
return $query->whereRelation(
|
||||
"vacationlimits",
|
||||
fn(Builder $query) => $query
|
||||
->where("year_period_id", $yearPeriod->id)
|
||||
->whereNotNull("days"),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getAvatarName(): string
|
||||
{
|
||||
return mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);
|
||||
|
@ -4,10 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Toby\Domain\VacationRequestStatesRetriever;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@ -40,4 +42,12 @@ class Vacation extends Model
|
||||
{
|
||||
return $this->belongsTo(YearPeriod::class);
|
||||
}
|
||||
|
||||
public function scopeApproved(Builder $query): Builder
|
||||
{
|
||||
return $query->whereRelation(
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query->states(VacationRequestStatesRetriever::successStates()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ namespace Toby\Eloquent\Observers;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Illuminate\Support\Str;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class UserObserver
|
||||
{
|
||||
@ -23,15 +22,4 @@ class UserObserver
|
||||
*/
|
||||
$user->password = $this->hash->make(Str::random(40));
|
||||
}
|
||||
|
||||
public function created(User $user): void
|
||||
{
|
||||
$yearPeriods = YearPeriod::all();
|
||||
|
||||
foreach ($yearPeriods as $yearPeriod) {
|
||||
$user->vacationLimits()->create([
|
||||
"year_period_id" => $yearPeriod->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Inertia\Response;
|
||||
@ -29,10 +28,7 @@ class DashboardController extends Controller
|
||||
$absences = Vacation::query()
|
||||
->with(["user", "vacationRequest"])
|
||||
->whereDate("date", $now)
|
||||
->whereRelation(
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query->states(VacationRequestStatesRetriever::successStates()),
|
||||
)
|
||||
->approved()
|
||||
->get();
|
||||
|
||||
if ($user->can("listAll", VacationRequest::class)) {
|
||||
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\Enums\Month;
|
||||
@ -26,10 +25,7 @@ class MonthlyUsageController extends Controller
|
||||
$currentUser = $request->user();
|
||||
|
||||
$users = User::query()
|
||||
->whereRelation(
|
||||
"vacationlimits",
|
||||
fn(Builder $query) => $query->where("year_period_id", $currentYearPeriod->id)->whereNotNull("days"),
|
||||
)
|
||||
->withVacationLimitIn($currentYearPeriod)
|
||||
->where("id", "!=", $currentUser->id)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
|
@ -8,6 +8,7 @@ use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\Actions\CreateUserAction;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\Role;
|
||||
use Toby\Eloquent\Models\User;
|
||||
@ -54,11 +55,11 @@ class UserController extends Controller
|
||||
/**
|
||||
* @throws AuthorizationException
|
||||
*/
|
||||
public function store(UserRequest $request): RedirectResponse
|
||||
public function store(UserRequest $request, CreateUserAction $createUserAction): RedirectResponse
|
||||
{
|
||||
$this->authorize("manageUsers");
|
||||
|
||||
User::query()->create($request->data());
|
||||
$createUserAction->execute($request->data());
|
||||
|
||||
return redirect()
|
||||
->route("users.index")
|
||||
|
@ -103,10 +103,7 @@ class VacationRequestController extends Controller
|
||||
->paginate();
|
||||
|
||||
$users = User::query()
|
||||
->whereRelation(
|
||||
"vacationlimits",
|
||||
fn(Builder $query) => $query->where("year_period_id", $yearPeriod->id)->whereNotNull("days"),
|
||||
)
|
||||
->withVacationLimitIn($yearPeriod)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->get();
|
||||
@ -164,10 +161,7 @@ class VacationRequestController extends Controller
|
||||
$yearPeriod = $yearPeriodRetriever->selected();
|
||||
|
||||
$users = User::query()
|
||||
->whereRelation(
|
||||
"vacationlimits",
|
||||
fn(Builder $query) => $query->where("year_period_id", $yearPeriod->id)->whereNotNull("days"),
|
||||
)
|
||||
->withVacationLimitIn($yearPeriod)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->get();
|
||||
|
@ -8,6 +8,7 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Toby\Domain\Actions\CreateYearPeriodAction;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class CheckYearPeriod implements ShouldQueue
|
||||
@ -15,30 +16,17 @@ class CheckYearPeriod implements ShouldQueue
|
||||
use Dispatchable;
|
||||
use Queueable;
|
||||
|
||||
public function handle(): void
|
||||
public function handle(CreateYearPeriodAction $createYearPeriodAction): void
|
||||
{
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
$now = Carbon::now();
|
||||
|
||||
if ($currentYearPeriod === null) {
|
||||
$this->createCurrentYearPeriod();
|
||||
$createYearPeriodAction->execute($now->year);
|
||||
}
|
||||
|
||||
if (YearPeriod::query()->max("year") === Carbon::now()->year) {
|
||||
$this->createNextYearPeriod();
|
||||
if (YearPeriod::query()->max("year") === $now->year) {
|
||||
$createYearPeriodAction->execute($now->year + 1);
|
||||
}
|
||||
}
|
||||
|
||||
protected function createCurrentYearPeriod(): void
|
||||
{
|
||||
YearPeriod::query()->create([
|
||||
"year" => Carbon::now()->year,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function createNextYearPeriod(): void
|
||||
{
|
||||
YearPeriod::query()->create([
|
||||
"year" => Carbon::now()->year + 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,6 @@ class DatabaseSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
User::unsetEventDispatcher();
|
||||
YearPeriod::unsetEventDispatcher();
|
||||
VacationRequest::unsetEventDispatcher();
|
||||
|
||||
User::factory(9)->create();
|
||||
User::factory([
|
||||
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
|
||||
|
@ -29,10 +29,6 @@ class DemoSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
User::unsetEventDispatcher();
|
||||
YearPeriod::unsetEventDispatcher();
|
||||
VacationRequest::unsetEventDispatcher();
|
||||
|
||||
$user = User::factory([
|
||||
"first_name" => "Jan",
|
||||
"last_name" => "Kowalski",
|
||||
|
@ -46,7 +46,7 @@
|
||||
</div>
|
||||
<div v-if="can.generateTimesheet">
|
||||
<a
|
||||
:href="`/timesheet/${selectedMonth.value}`"
|
||||
:href="`/vacation/timesheet/${selectedMonth.value}`"
|
||||
class="inline-flex items-center px-4 py-3 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-blumilk-600 hover:bg-blumilk-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500"
|
||||
>
|
||||
Pobierz plik Excel
|
||||
|
@ -81,6 +81,7 @@ import { useMonthInfo } from '@/Composables/monthInfo'
|
||||
import VacationBar from '@/Shared/VacationBar'
|
||||
|
||||
const props = defineProps({
|
||||
years: Object,
|
||||
monthlyUsage: Object,
|
||||
currentMonth: String,
|
||||
})
|
||||
@ -89,6 +90,6 @@ const { getMonths } = useMonthInfo()
|
||||
const months = getMonths()
|
||||
|
||||
function isCurrentMonth(month) {
|
||||
return props.currentMonth === month.value
|
||||
return (props.years.selected.year === props.years.current.year && props.currentMonth === month.value)
|
||||
}
|
||||
</script>
|
||||
|
@ -14,7 +14,7 @@
|
||||
<div class="border-t border-gray-200">
|
||||
<div class="overflow-x-auto xl:overflow-x-visible overflow-y-auto xl:overflow-y-visible">
|
||||
<form @submit.prevent="submitVacationDays">
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<table class="min-w-full divide-y divide-gray-200 border-b">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th
|
||||
|
@ -109,7 +109,7 @@
|
||||
<HomeIcon class="mr-4 flex-shrink-0 h-6 w-6 text-blumilk-200" />
|
||||
Strona główna
|
||||
</InertiaLink>
|
||||
<div class="mt-1 pt-1">
|
||||
<div class="mt-1 pt-1 space-y-1">
|
||||
<InertiaLink
|
||||
v-for="item in navigation"
|
||||
:key="item.name"
|
||||
@ -202,9 +202,9 @@
|
||||
as="button"
|
||||
method="post"
|
||||
:preserve-state="false"
|
||||
class="font-medium text-blumilk-600 hover:text-blumilk-500"
|
||||
class="font-semibold text-blumilk-600 hover:text-blumilk-500"
|
||||
>
|
||||
Kliknij, aby wrócić do obecnego roku
|
||||
Wróc do obecnego roku
|
||||
</inertialink>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -28,7 +28,7 @@ Route::middleware("auth")->group(function (): void {
|
||||
Route::post("year-periods/{yearPeriod}/select", SelectYearPeriodController::class)
|
||||
->name("year-periods.select");
|
||||
|
||||
Route::prefix("/vacation")->group(function () {
|
||||
Route::prefix("/vacation")->group(function (): void {
|
||||
Route::get("/limits", [VacationLimitController::class, "edit"])
|
||||
->name("vacation.limits");
|
||||
Route::get("/calendar/{month?}", [VacationCalendarController::class, "index"])
|
||||
@ -56,9 +56,9 @@ Route::middleware("auth")->group(function (): void {
|
||||
->name("vacation.requests.reject");
|
||||
Route::post("/requests/{vacationRequest}/cancel", [VacationRequestController::class, "cancel"])
|
||||
->name("vacation.requests.cancel");
|
||||
Route::post("/requests/{vacationRequest}/accept-as-technical", [VacationRequestController::class, "acceptAsTechnical"],)
|
||||
Route::post("/requests/{vacationRequest}/accept-as-technical", [VacationRequestController::class, "acceptAsTechnical"], )
|
||||
->name("vacation.requests.accept-as-technical");
|
||||
Route::post("/requests/{vacationRequest}/accept-as-administrative", [VacationRequestController::class, "acceptAsAdministrative"],)
|
||||
Route::post("/requests/{vacationRequest}/accept-as-administrative", [VacationRequestController::class, "acceptAsAdministrative"], )
|
||||
->name("vacation.requests.accept-as-administrative");
|
||||
|
||||
Route::get("/monthly-usage", MonthlyUsageController::class)
|
||||
|
@ -9,6 +9,7 @@ use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\FeatureTestCase;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationLimit;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class VacationLimitTest extends FeatureTestCase
|
||||
{
|
||||
@ -16,12 +17,14 @@ class VacationLimitTest extends FeatureTestCase
|
||||
|
||||
public function testAdminCanSeeVacationLimits(): void
|
||||
{
|
||||
$admin = User::factory()->admin()->createQuietly();
|
||||
$admin = User::factory()->admin()->create();
|
||||
|
||||
User::factory(10)->create();
|
||||
VacationLimit::factory(10)
|
||||
->for(YearPeriod::current())
|
||||
->create();
|
||||
|
||||
$this->actingAs($admin)
|
||||
->get("/vacation-limits")
|
||||
->get("/vacation/limits")
|
||||
->assertOk()
|
||||
->assertInertia(
|
||||
fn(Assert $page) => $page
|
||||
@ -32,9 +35,11 @@ class VacationLimitTest extends FeatureTestCase
|
||||
|
||||
public function testAdminCanUpdateVacationLimits(): void
|
||||
{
|
||||
$admin = User::factory()->admin()->createQuietly();
|
||||
$admin = User::factory()->admin()->create();
|
||||
|
||||
User::factory(3)->create();
|
||||
VacationLimit::factory(3)
|
||||
->for(YearPeriod::current())
|
||||
->create();
|
||||
|
||||
[$limit1, $limit2, $limit3] = VacationLimit::all();
|
||||
|
||||
@ -54,7 +59,7 @@ class VacationLimitTest extends FeatureTestCase
|
||||
];
|
||||
|
||||
$this->actingAs($admin)
|
||||
->put("/vacation-limits", [
|
||||
->put("/vacation/limits", [
|
||||
"items" => $data,
|
||||
])
|
||||
->assertRedirect();
|
||||
|
@ -39,7 +39,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCanSeeVacationRequestsList(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationRequest::factory()
|
||||
@ -49,7 +49,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->get("/vacation-requests/me")
|
||||
->get("/vacation/requests/me")
|
||||
->assertOk()
|
||||
->assertInertia(
|
||||
fn(Assert $page) => $page
|
||||
@ -60,7 +60,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCanCreateVacationRequest(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
@ -72,7 +72,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
->post("/vacation/requests", [
|
||||
"user" => $user->id,
|
||||
"type" => VacationType::Vacation->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 2, 7)->toDateString(),
|
||||
@ -94,8 +94,8 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCanCreateVacationRequestOnEmployeeBehalf(): void
|
||||
{
|
||||
$creator = User::factory()->admin()->createQuietly();
|
||||
$user = User::factory()->createQuietly();
|
||||
$creator = User::factory()->admin()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
@ -107,7 +107,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($creator)
|
||||
->post("/vacation-requests", [
|
||||
->post("/vacation/requests", [
|
||||
"user" => $user->id,
|
||||
"type" => VacationType::Vacation->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 2, 7)->toDateString(),
|
||||
@ -130,8 +130,8 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCanCreateVacationRequestOnEmployeeBehalfAndSkipAcceptanceFlow(): void
|
||||
{
|
||||
$creator = User::factory()->admin()->createQuietly();
|
||||
$user = User::factory()->createQuietly();
|
||||
$creator = User::factory()->admin()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
@ -143,7 +143,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($creator)
|
||||
->post("/vacation-requests", [
|
||||
->post("/vacation/requests", [
|
||||
"user" => $user->id,
|
||||
"type" => VacationType::Vacation->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 2, 7)->toDateString(),
|
||||
@ -167,8 +167,8 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testTechnicalApproverCanApproveVacationRequest(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$technicalApprover = User::factory()->technicalApprover()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$technicalApprover = User::factory()->technicalApprover()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
$vacationRequest = VacationRequest::factory([
|
||||
@ -180,7 +180,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($technicalApprover)
|
||||
->post("/vacation-requests/{$vacationRequest->id}/accept-as-technical")
|
||||
->post("/vacation/requests/{$vacationRequest->id}/accept-as-technical")
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$vacationRequest->refresh();
|
||||
@ -190,8 +190,8 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testAdministrativeApproverCanApproveVacationRequest(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$administrativeApprover = User::factory()->administrativeApprover()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$administrativeApprover = User::factory()->administrativeApprover()->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
@ -203,7 +203,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($administrativeApprover)
|
||||
->post("/vacation-requests/{$vacationRequest->id}/accept-as-administrative")
|
||||
->post("/vacation/requests/{$vacationRequest->id}/accept-as-administrative")
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$vacationRequest->refresh();
|
||||
@ -213,8 +213,8 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testTechnicalApproverCanRejectVacationRequest(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$technicalApprover = User::factory()->technicalApprover()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$technicalApprover = User::factory()->technicalApprover()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
@ -234,7 +234,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($technicalApprover)
|
||||
->post("/vacation-requests/{$vacationRequest->id}/reject")
|
||||
->post("/vacation/requests/{$vacationRequest->id}/reject")
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$vacationRequest->refresh();
|
||||
@ -244,7 +244,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCannotCreateVacationRequestIfHeExceedsHisVacationLimit(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
@ -255,7 +255,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
->post("/vacation/requests", [
|
||||
"user" => $user->id,
|
||||
"type" => VacationType::Vacation->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 2, 7)->toDateString(),
|
||||
@ -269,7 +269,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCannotCreateVacationRequestAtWeekend(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
@ -280,7 +280,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
->post("/vacation/requests", [
|
||||
"user" => $user->id,
|
||||
"type" => VacationType::Vacation->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 2, 5)->toDateString(),
|
||||
@ -294,7 +294,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCannotCreateVacationRequestAtHoliday(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
@ -312,7 +312,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
}
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
->post("/vacation/requests", [
|
||||
"user" => $user->id,
|
||||
"type" => VacationType::Vacation->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 4, 18)->toDateString(),
|
||||
@ -326,7 +326,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCannotCreateVacationRequestIfHeHasPendingVacationRequestInThisRange(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
@ -348,7 +348,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
->post("/vacation/requests", [
|
||||
"user" => $user->id,
|
||||
"type" => VacationType::Vacation->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 2, 1)->toDateString(),
|
||||
@ -362,7 +362,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCannotCreateVacationRequestIfHeHasApprovedVacationRequestInThisRange(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
@ -384,7 +384,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
->post("/vacation/requests", [
|
||||
"user" => $user->id,
|
||||
"type" => VacationType::Vacation->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 2, 1)->toDateString(),
|
||||
@ -398,10 +398,10 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCannotCreateVacationRequestWithEndDatePriorToTheStartDate(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
->post("/vacation/requests", [
|
||||
"user" => $user->id,
|
||||
"type" => VacationType::Vacation->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 2, 7)->toDateString(),
|
||||
@ -415,11 +415,11 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCannotCreateVacationRequestAtTheTurnOfTheYear(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
$nextYearPeriod = $this->createYearPeriod(Carbon::now()->year + 1);
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
->post("/vacation/requests", [
|
||||
"user" => $user->id,
|
||||
"type" => VacationType::Vacation->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 12, 27)->toDateString(),
|
||||
|
@ -16,7 +16,7 @@ trait InteractsWithYearPeriods
|
||||
public function createYearPeriod(int $year): YearPeriod
|
||||
{
|
||||
/** @var YearPeriod $yearPeriod */
|
||||
$yearPeriod = YearPeriod::factory()->createQuietly([
|
||||
$yearPeriod = YearPeriod::factory()->create([
|
||||
"year" => $year,
|
||||
]);
|
||||
|
||||
|
@ -7,6 +7,8 @@ namespace Tests\Unit;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\InteractsWithYearPeriods;
|
||||
use Toby\Domain\Actions\CreateUserAction;
|
||||
use Toby\Domain\Actions\CreateYearPeriodAction;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
@ -27,7 +29,11 @@ class VacationLimitTest extends TestCase
|
||||
$this->assertDatabaseCount("vacation_limits", 0);
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
$user = User::factory()->create();
|
||||
$createUserAction = $this->app->make(CreateUserAction::class);
|
||||
|
||||
$dumpData = User::factory()->raw();
|
||||
|
||||
$user = $createUserAction->execute($dumpData);
|
||||
|
||||
$this->assertDatabaseCount("vacation_limits", 1);
|
||||
|
||||
@ -40,10 +46,12 @@ class VacationLimitTest extends TestCase
|
||||
public function testWhenYearPeriodIsCreatedThenVacationLimitsForThisYearPeriodAreCreated(): void
|
||||
{
|
||||
$this->assertDatabaseCount("vacation_limits", 0);
|
||||
$createYearPeriodAction = $this->app->make(CreateYearPeriodAction::class);
|
||||
$lastYear = YearPeriod::query()->max("year") + 1;
|
||||
|
||||
User::factory(10)->createQuietly();
|
||||
User::factory(10)->create();
|
||||
|
||||
YearPeriod::factory()->create();
|
||||
$createYearPeriodAction->execute($lastYear);
|
||||
|
||||
$this->assertDatabaseCount("vacation_limits", 10);
|
||||
}
|
||||
|
@ -39,16 +39,16 @@ class VacationRequestNotificationTest extends TestCase
|
||||
|
||||
$user = User::factory([
|
||||
"role" => Role::Employee,
|
||||
])->createQuietly();
|
||||
])->create();
|
||||
$technicalApprover = User::factory([
|
||||
"role" => Role::TechnicalApprover,
|
||||
])->createQuietly();
|
||||
])->create();
|
||||
$administrativeApprover = User::factory([
|
||||
"role" => Role::AdministrativeApprover,
|
||||
])->createQuietly();
|
||||
])->create();
|
||||
$admin = User::factory([
|
||||
"role" => Role::Administrator,
|
||||
])->createQuietly();
|
||||
])->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
@ -78,13 +78,13 @@ class VacationRequestNotificationTest extends TestCase
|
||||
|
||||
$technicalApprover = User::factory([
|
||||
"role" => Role::TechnicalApprover,
|
||||
])->createQuietly();
|
||||
])->create();
|
||||
$administrativeApprover = User::factory([
|
||||
"role" => Role::AdministrativeApprover,
|
||||
])->createQuietly();
|
||||
])->create();
|
||||
$admin = User::factory([
|
||||
"role" => Role::Administrator,
|
||||
])->createQuietly();
|
||||
])->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
|
@ -40,7 +40,7 @@ class VacationRequestStatesTest extends TestCase
|
||||
|
||||
public function testAfterCreatingVacationRequestOfTypeVacationItTransitsToProperState(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
@ -63,7 +63,7 @@ class VacationRequestStatesTest extends TestCase
|
||||
|
||||
public function testAfterCreatingVacationRequestOfTypeSickVacationItTransitsToProperState(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
@ -85,7 +85,7 @@ class VacationRequestStatesTest extends TestCase
|
||||
|
||||
public function testAfterCreatingVacationRequestOfTypeTimeInLieuItTransitsToProperState(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
|
@ -60,7 +60,14 @@ class YearPeriodRetrieverTest extends TestCase
|
||||
public function testLinks(): void
|
||||
{
|
||||
$expected = [
|
||||
"current" => $this->current->year,
|
||||
"current" => [
|
||||
"year" => $this->currentYearPeriod->year,
|
||||
"link" => route("year-periods.select", $this->currentYearPeriod),
|
||||
],
|
||||
"selected" => [
|
||||
"year" => $this->currentYearPeriod->year,
|
||||
"link" => route("year-periods.select", $this->currentYearPeriod),
|
||||
],
|
||||
"navigation" => [
|
||||
[
|
||||
"year" => $this->previousYearPeriod->year,
|
||||
|
Loading…
x
Reference in New Issue
Block a user