- small changes (#98)

* - added some test

* - cr fix

* wip

* wip

* Update resources/js/Shared/MainMenu.vue

Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>

* fix

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
Adrian Hopek 2022-03-30 10:33:18 +02:00 committed by GitHub
parent ab16af1ca9
commit 08421b8a69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 323 additions and 286 deletions

View File

@ -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);
}
}

View 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,
]);
}
}
}

View File

@ -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

View File

@ -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());

View File

@ -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(
[

View File

@ -88,7 +88,7 @@ class UserVacationStatsRetriever
$limit = $user->vacationLimits()
->where("year_period_id", $yearPeriod->id)
->first()
->days;
?->days;
return $limit ?? 0;
}

View File

@ -30,13 +30,15 @@ class YearPeriodRetriever
public function links(): array
{
$current = $this->selected();
$selected = $this->selected();
$current = $this->current();
$years = YearPeriod::query()->whereIn("year", $this->offset($current->year))->get();
$years = YearPeriod::query()->whereIn("year", $this->offset($selected->year))->get();
$navigation = $years->map(fn(YearPeriod $yearPeriod) => $this->toNavigation($yearPeriod));
return [
"current" => $current->year,
"current" => $this->toNavigation($current),
"selected" => $this->toNavigation($selected),
"navigation" => $navigation->toArray(),
];
}

View File

@ -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);

View File

@ -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()),
);
}
}

View File

@ -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,
]);
}
}
}

View File

@ -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)) {

View File

@ -36,6 +36,6 @@ class GoogleController extends Controller
$auth->guard()->login($user, true);
return redirect()->route("dashboard");
return redirect()->intended();
}
}

View File

@ -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")

View File

@ -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")

View File

@ -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();

View File

@ -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,
]);
}
}

View File

@ -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"),

View File

@ -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",

View File

@ -2,8 +2,8 @@ import { computed } from 'vue'
import { usePage } from '@inertiajs/inertia-vue3'
export default function useCurrentYearPeriodInfo() {
const minDate = computed(() => new Date(usePage().props.value.years.current, 0, 1))
const maxDate = computed(() => new Date(usePage().props.value.years.current, 11, 31))
const minDate = computed(() => new Date(usePage().props.value.years.selected.year, 0, 1))
const maxDate = computed(() => new Date(usePage().props.value.years.selected.year, 11, 31))
return {
minDate,

View File

@ -10,7 +10,7 @@
<InertiaLink
v-if="previousMonth"
as="button"
:href="`/vacation-calendar/${previousMonth.value}`"
:href="`/vacation/calendar/${previousMonth.value}`"
class="flex items-center justify-center rounded-l-md border border-r-0 border-gray-300 bg-white py-2 pl-3 pr-4 text-gray-400 hover:text-gray-500 focus:relative md:w-9 md:px-2 md:hover:bg-gray-50"
>
<ChevronLeftIcon class="h-5 w-5" />
@ -23,7 +23,7 @@
</span>
<InertiaLink
as="button"
:href="`/vacation-calendar/${currentMonth.value}`"
:href="`/vacation/calendar/${currentMonth.value}`"
class="hidden border-t border-b border-gray-300 bg-white px-3.5 text-sm font-medium flex items-center text-gray-700 hover:bg-gray-50 hover:text-gray-900 focus:relative md:block"
>
Dzisiaj
@ -31,7 +31,7 @@
<InertiaLink
v-if="nextMonth"
as="button"
:href="`/vacation-calendar/${nextMonth.value}`"
:href="`/vacation/calendar/${nextMonth.value}`"
class="flex items-center justify-center rounded-r-md border border-l-0 border-gray-300 bg-white py-2 pl-4 pr-3 text-gray-400 hover:text-gray-500 focus:relative md:w-9 md:px-2 md:hover:bg-gray-50"
>
<ChevronRightIcon class="h-5 w-5" />
@ -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
@ -59,13 +59,13 @@
<tr>
<th class="w-64 py-2 border text-lg font-semibold text-gray-800 border-gray-300">
<div class="flex justify-center items-center">
{{ selectedMonth.name }} {{ years.current }}
{{ selectedMonth.name }} {{ years.selected.year }}
</div>
</th>
<th
v-for="day in calendar"
:key="day.dayOfMonth"
class="border border-gray-300 text-lg font-semibold text-gray-900 py-4 px-2"
class="border border-gray-300 text-lg font-semibold text-gray-900 py-2 px-2"
style="min-width: 46px;"
:class="{ 'bg-red-100 text-red-800': day.isWeekend || day.isHoliday, 'text-blumilk-600 bg-blumilk-25': day.isToday }"
>
@ -83,16 +83,13 @@
v-for="user in users.data"
:key="user.id"
>
<th class="border border-gray-300 py-2 px-4">
<th class="border border-gray-300 py-2 px-2">
<div class="flex justify-start items-center">
<span class="inline-flex items-center justify-center h-10 w-10 rounded-full">
<img
class="h-10 w-10 rounded-full"
:src="user.avatar"
>
<span class="inline-flex items-center justify-center h-8 w-8 rounded-full">
<img :src="user.avatar">
</span>
<div class="ml-3">
<div class="text-sm font-medium text-gray-900 whitespace-nowrap">
<div class="text-sm font-medium text-gray-900 truncate">
{{ user.name }}
</div>
</div>

View File

@ -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>

View File

@ -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
@ -155,7 +155,7 @@ function submitVacationDays() {
days: item.hasVacation ? item.days : null,
})),
}))
.put('/vacation-limits', {
.put('/vacation/limits', {
preserveState: (page) => Object.keys(page.props.errors).length,
preserveScroll: true,
})

View File

@ -287,7 +287,7 @@
<div class="flex justify-end py-3">
<div class="space-x-3">
<InertiaLink
href="/vacation-requests"
href="/vacation/requests"
class="bg-white py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500"
>
Anuluj
@ -388,7 +388,7 @@ function createForm() {
type: data.type.value,
user: data.user.id,
}))
.post('/vacation-requests')
.post('/vacation/requests')
}
function onFromChange(selectedDates, dateStr) {
@ -418,14 +418,14 @@ function resetForm() {
async function refreshEstimatedDays(from, to) {
if (from && to) {
const res = await axios.post('/api/calculate-vacation-days', { from, to })
const res = await axios.post('/api/calculate-vacation/days', { from, to })
estimatedDays.value = res.data
}
}
async function refreshVacationStats(user) {
const res = await axios.post('/api/calculate-vacation-stats', { user: user.id })
const res = await axios.post('/api/calculate-vacation/stats', { user: user.id })
stats.value = res.data
}

View File

@ -9,7 +9,7 @@
</div>
<div>
<InertiaLink
href="/vacation-requests/create"
href="/vacation/requests/create"
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"
>
Dodaj wniosek
@ -84,7 +84,7 @@
>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
<InertiaLink
:href="`/vacation-requests/${request.id}`"
:href="`/vacation/requests/${request.id}`"
class="font-semibold text-blumilk-600 hover:text-blumilk-500 hover:underline"
>
{{ request.name }}
@ -107,13 +107,13 @@
</td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
<InertiaLink
:href="`/vacation-requests/${request.id}`"
:href="`/vacation/requests/${request.id}`"
class="flex justify-around"
>
<ChevronRightIcon class="block w-6 h-6 fill-blumilk-500" />
</InertiaLink>
<InertiaLink
:href="`/vacation-requests/${request.id}`"
:href="`/vacation/requests/${request.id}`"
class="absolute inset-0"
/>
</td>

View File

@ -9,7 +9,7 @@
</div>
<div>
<InertiaLink
href="/vacation-requests/create"
href="/vacation/requests/create"
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"
>
Dodaj wniosek
@ -224,7 +224,7 @@
>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
<InertiaLink
:href="`/vacation-requests/${request.id}`"
:href="`/vacation/requests/${request.id}`"
class="font-semibold text-blumilk-600 hover:text-blumilk-500 hover:underline"
>
{{ request.name }}
@ -263,13 +263,13 @@
</td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
<InertiaLink
:href="`/vacation-requests/${request.id}`"
:href="`/vacation/requests/${request.id}`"
class="flex justify-around"
>
<ChevronRightIcon class="block w-6 h-6 fill-blumilk-500" />
</InertiaLink>
<InertiaLink
:href="`/vacation-requests/${request.id}`"
:href="`/vacation/requests/${request.id}`"
class="absolute inset-0"
/>
</td>
@ -334,7 +334,7 @@ const form = reactive({
})
watch(form, debounce(() => {
Inertia.get('/vacation-requests', { user: form.user?.id, status: form.status.value }, {
Inertia.get('/vacation/requests', { user: form.user?.id, status: form.status.value }, {
preserveState: true,
replace: true,
})

View File

@ -60,13 +60,14 @@
Data
</dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
<span class="font-semibold">
<template v-if="request.days.length > 1">
{{ request.from }} - {{ request.to }} [Liczba dni: {{ request.days.length }}]
{{ request.from }} - {{ request.to }}
</template>
<template v-else>
{{ request.from }} [Liczba dni: {{ request.days.length }}]
{{ request.from }}
</template>
<span class="font-semibold">
[Liczba dni: {{ request.days.length }}]
</span>
</dd>
</div>
@ -100,7 +101,7 @@
</div>
<div class="ml-4 flex-shrink-0">
<a
:href="`/vacation-requests/${request.id}/download`"
:href="`/vacation/requests/${request.id}/download`"
target="_blank"
class="font-medium text-blumilk-600 hover:text-blumilk-500"
>
@ -130,7 +131,7 @@
</div>
<div class="mt-5">
<InertiaLink
:href="`/vacation-requests/${request.id}/accept-as-technical`"
:href="`/vacation/requests/${request.id}/accept-as-technical`"
method="post"
as="button"
preserve-scroll
@ -156,7 +157,7 @@
</div>
<div class="mt-5">
<InertiaLink
:href="`/vacation-requests/${request.id}/accept-as-administrative`"
:href="`/vacation/requests/${request.id}/accept-as-administrative`"
method="post"
as="button"
preserve-scroll
@ -182,7 +183,7 @@
</div>
<div class="mt-5">
<InertiaLink
:href="`/vacation-requests/${request.id}/reject`"
:href="`/vacation/requests/${request.id}/reject`"
method="post"
as="button"
preserve-scroll
@ -208,7 +209,7 @@
</div>
<div class="mt-5">
<InertiaLink
:href="`/vacation-requests/${request.id}/cancel`"
:href="`/vacation/requests/${request.id}/cancel`"
method="post"
as="button"
preserve-scroll

View File

@ -44,7 +44,6 @@
class="ml-1 flex items-center justify-center h-10 w-10 rounded-full focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white"
@click="sidebarOpen = false"
>
<span class="sr-only">Close sidebar</span>
<XIcon class="h-6 w-6 text-white" />
</button>
</div>
@ -102,8 +101,7 @@
>
</InertiaLink>
</div>
<nav class="mt-5 flex-1 flex flex-col divide-y divide-blumilk-800 overflow-y-auto">
<div class="px-2 space-y-1">
<nav class="mt-5 px-2 flex-1 flex flex-col divide-y divide-blumilk-800 overflow-y-auto">
<InertiaLink
href="/"
:class="[$page.component === 'Dashboard' ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-sm leading-6 font-medium rounded-md']"
@ -111,9 +109,7 @@
<HomeIcon class="mr-4 flex-shrink-0 h-6 w-6 text-blumilk-200" />
Strona główna
</InertiaLink>
</div>
<div class="mt-4 pt-4">
<div class="px-2 space-y-1">
<div class="mt-1 pt-1 space-y-1">
<InertiaLink
v-for="item in navigation"
:key="item.name"
@ -127,7 +123,6 @@
{{ item.name }}
</InertiaLink>
</div>
</div>
</nav>
</div>
</div>
@ -139,7 +134,6 @@
class="px-4 border-r border-gray-200 text-gray-400 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-blumilk-500 lg:hidden"
@click="sidebarOpen = true"
>
<span class="sr-only">Open sidebar</span>
<MenuAlt1Icon class="h-6 w-6" />
</button>
<div class="flex-1 px-4 flex justify-between sm:px-6 lg:px-8">
@ -150,14 +144,14 @@
class="relative inline-block text-left"
>
<div class="flex justify-center items-center">
<div class="mr-4">
<div class="mr-4 text-sm">
Wybrany rok:
</div>
<div>
<MenuButton
class="inline-flex justify-center w-full rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500"
>
{{ years.current }}
{{ years.selected.year }}
<ChevronDownIcon class="-mr-1 ml-2 h-5 w-5" />
</MenuButton>
</div>
@ -172,7 +166,7 @@
leave-to-class="transform opacity-0 scale-95"
>
<MenuItems
class="origin-top-right absolute right-0 mt-2 w-32 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none"
class="origin-top-right absolute right-0 mt-2 w-24 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none"
>
<div class="py-1">
<MenuItem
@ -189,7 +183,7 @@
>
{{ item.year }}
<CheckIcon
v-if="item.year === years.current"
v-if="item.year === years.selected.year"
class="h-5 w-5 text-blumilk-500 ml-2"
/>
</InertiaLink>
@ -199,6 +193,20 @@
</transition>
</Menu>
</div>
<div
v-if="years.current.year !== years.selected.year"
class="ml-3 text-sm hidden sm:block"
>
<InertiaLink
:href="years.current.link"
as="button"
method="post"
:preserve-state="false"
class="font-semibold text-blumilk-600 hover:text-blumilk-500"
>
Wróć do obecnego roku
</inertialink>
</div>
</div>
<div class="ml-4 flex items-center md:ml-6">
<Menu
@ -213,7 +221,6 @@
:src="auth.user.avatar"
>
<span class="hidden ml-3 text-gray-700 text-sm font-medium lg:block">
<span class="sr-only">Open user menu for </span>
{{ auth.user.name }}
</span>
<ChevronDownIcon class="hidden flex-shrink-0 ml-1 h-5 w-5 text-gray-400 lg:block" />
@ -285,28 +292,28 @@ const navigation = computed(() =>
[
{
name: 'Moje wnioski',
href: '/vacation-requests/me',
href: '/vacation/requests/me',
component: 'VacationRequest/Index',
icon: DocumentTextIcon,
can: true,
},
{
name: 'Wnioski urlopowe',
href: '/vacation-requests',
href: '/vacation/requests',
component: 'VacationRequest/IndexForApprovers',
icon: CollectionIcon,
can: props.auth.can.listAllVacationRequests,
},
{
name: 'Kalendarz urlopów',
href: '/vacation-calendar',
href: '/vacation/calendar',
component: 'Calendar',
icon: CalendarIcon,
can: true,
},
{
name: 'Wykorzystanie urlopu',
href: '/monthly-usage',
href: '/vacation/monthly-usage',
component: 'MonthlyUsage',
icon: AdjustmentsIcon,
can: props.auth.can.listMonthlyUsage,
@ -320,7 +327,7 @@ const navigation = computed(() =>
},
{
name: 'Limity urlopów',
href: '/vacation-limits',
href: '/vacation/limits',
component: 'VacationLimits',
icon: SunIcon,
can: props.auth.can.manageVacationLimits,

View File

@ -16,7 +16,7 @@
<div class="relative focus-within:ring-2 focus-within:ring-blumilk-500">
<h3 class="text-sm font-semibold text-blumilk-600 hover:text-blumilk-500">
<InertiaLink
:href="`/vacation-requests/${request.id}`"
:href="`/vacation/requests/${request.id}`"
class="hover:underline focus:outline-none"
>
<span class="absolute inset-0" />
@ -54,7 +54,7 @@
</div>
<div class="mt-6">
<InertiaLink
href="/vacation-requests"
href="/vacation/requests"
:data="{status: 'waiting_for_action'}"
class="w-full flex justify-center items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blumilk-500"
>

View File

@ -16,7 +16,7 @@
<div class="relative focus-within:ring-2 focus-within:ring-blumilk-500">
<h3 class="text-sm font-semibold text-blumilk-600 hover:text-blumilk-500">
<InertiaLink
:href="`/vacation-requests/${request.id}`"
:href="`/vacation/requests/${request.id}`"
class="hover:underline focus:outline-none"
>
<span class="absolute inset-0" />
@ -41,7 +41,7 @@
</div>
<div class="mt-6">
<InertiaLink
href="/vacation-requests/me"
href="/vacation/requests/me"
class="w-full flex justify-center items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blumilk-500"
>
Zobacz wszystkie

View File

@ -32,7 +32,7 @@ createInertiaApp({
InertiaProgress.init({
delay: 0,
color: 'red',
color: '#527ABA',
})
Flatpickr.localize(Polish)

View File

@ -21,51 +21,49 @@ Route::middleware("auth")->group(function (): void {
Route::post("/logout", LogoutController::class);
Route::resource("users", UserController::class);
Route::post("/users/{user}/restore", [UserController::class, "restore"])->withTrashed();
Route::post("/users/{user}/restore", [UserController::class, "restore"])
->withTrashed();
Route::resource("holidays", HolidayController::class);
Route::post("year-periods/{yearPeriod}/select", SelectYearPeriodController::class)
->name("year-periods.select");
Route::get("/vacation-limits", [VacationLimitController::class, "edit"])
Route::prefix("/vacation")->group(function (): void {
Route::get("/limits", [VacationLimitController::class, "edit"])
->name("vacation.limits");
Route::get("/vacation-calendar/{month?}", [VacationCalendarController::class, "index"])
Route::get("/calendar/{month?}", [VacationCalendarController::class, "index"])
->name("vacation.calendar");
Route::get("/timesheet/{month}", TimesheetController::class)
->name("timesheet");
Route::get("/vacation-limits", [VacationLimitController::class, "edit"])->name("vacation.limits");
Route::put("/vacation-limits", [VacationLimitController::class, "update"]);
Route::get("/limits", [VacationLimitController::class, "edit"])
->name("vacation.limits");
Route::put("/limits", [VacationLimitController::class, "update"]);
Route::get("/vacation-requests/me", [VacationRequestController::class, "index"])
->name("vacation.requests.index");
Route::get("/vacation-requests", [VacationRequestController::class, "indexForApprovers"])
Route::get("/requests", [VacationRequestController::class, "indexForApprovers"])
->name("vacation.requests.indexForApprovers");
Route::get("/vacation-requests/create", [VacationRequestController::class, "create"])
Route::get("/requests/me", [VacationRequestController::class, "index"])
->name("vacation.requests.index");
Route::get("/requests/create", [VacationRequestController::class, "create"])
->name("vacation.requests.create");
Route::post("/vacation-requests", [VacationRequestController::class, "store"])
Route::post("/requests", [VacationRequestController::class, "store"])
->name("vacation.requests.store");
Route::get("/vacation-requests/{vacationRequest}", [VacationRequestController::class, "show"])
Route::get("/requests/{vacationRequest}", [VacationRequestController::class, "show"])
->name("vacation.requests.show");
Route::get("/vacation-requests/{vacationRequest}/download", [VacationRequestController::class, "download"])
Route::get("/requests/{vacationRequest}/download", [VacationRequestController::class, "download"])
->name("vacation.requests.download");
Route::post("/vacation-requests/{vacationRequest}/reject", [VacationRequestController::class, "reject"])
Route::post("/requests/{vacationRequest}/reject", [VacationRequestController::class, "reject"])
->name("vacation.requests.reject");
Route::post("/vacation-requests/{vacationRequest}/cancel", [VacationRequestController::class, "cancel"])
Route::post("/requests/{vacationRequest}/cancel", [VacationRequestController::class, "cancel"])
->name("vacation.requests.cancel");
Route::post(
"/vacation-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(
"/vacation-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::post("year-periods/{yearPeriod}/select", SelectYearPeriodController::class)
->name("year-periods.select");
Route::get("/monthly-usage", MonthlyUsageController::class)->name("monthly-usage");
Route::get("/monthly-usage", MonthlyUsageController::class)
->name("vacation.monthly-usage");
});
});
Route::middleware("guest")->group(function (): void {

View File

@ -14,19 +14,19 @@ class MonthlyUsageTest extends FeatureTestCase
public function testAdministatorCanSeeVacationsMonthlyUsage(): void
{
$admin = User::factory()->admin()->createQuietly();
$admin = User::factory()->admin()->create();
$this->actingAs($admin)
->get("/monthly-usage")
->get("/vacation/monthly-usage")
->assertOk();
}
public function testEmployeeCannotSeeVacationsMonthlyUsage(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$this->actingAs($user)
->get("/monthly-usage")
->get("/vacation/monthly-usage")
->assertForbidden();
}
}

View File

@ -14,19 +14,19 @@ class VacationCalendarTest extends FeatureTestCase
public function testAdministrativeApproverCanDownloadTimesheet(): void
{
$administrativeApprover = User::factory()->administrativeApprover()->createQuietly();
$administrativeApprover = User::factory()->administrativeApprover()->create();
$this->actingAs($administrativeApprover)
->get("/timesheet/january")
->get("/vacation/timesheet/january")
->assertOk();
}
public function testEmployeeCannotDownloadTimesheet(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$this->actingAs($user)
->get("/timesheet/january")
->get("/vacation/timesheet/january")
->assertForbidden();
}
}

View File

@ -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();

View File

@ -40,7 +40,7 @@ class VacationRequestTest extends FeatureTestCase
public function testUserCanSeeVacationRequestsList(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
VacationRequest::factory()
@ -50,7 +50,7 @@ class VacationRequestTest extends FeatureTestCase
->create();
$this->actingAs($user)
->get("/vacation-requests/me")
->get("/vacation/requests/me")
->assertOk()
->assertInertia(
fn(Assert $page) => $page
@ -61,7 +61,7 @@ class VacationRequestTest extends FeatureTestCase
public function testUserCanCreateVacationRequest(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
@ -73,7 +73,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(),
@ -95,8 +95,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();
@ -108,7 +108,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(),
@ -131,8 +131,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();
@ -144,7 +144,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(),
@ -168,8 +168,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([
@ -181,7 +181,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")
->assertRedirect();
$vacationRequest->refresh();
@ -191,8 +191,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();
@ -204,7 +204,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")
->assertRedirect();
$vacationRequest->refresh();
@ -214,8 +214,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([
@ -235,7 +235,7 @@ class VacationRequestTest extends FeatureTestCase
->create();
$this->actingAs($technicalApprover)
->post("/vacation-requests/{$vacationRequest->id}/reject")
->post("/vacation/requests/{$vacationRequest->id}/reject")
->assertRedirect();
$vacationRequest->refresh();
@ -245,7 +245,7 @@ class VacationRequestTest extends FeatureTestCase
public function testUserCannotCreateVacationRequestIfHeExceedsHisVacationLimit(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
VacationLimit::factory([
@ -256,7 +256,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(),
@ -270,7 +270,7 @@ class VacationRequestTest extends FeatureTestCase
public function testUserCannotCreateVacationRequestAtWeekend(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
VacationLimit::factory([
@ -281,7 +281,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(),
@ -295,7 +295,7 @@ class VacationRequestTest extends FeatureTestCase
public function testUserCannotCreateVacationRequestAtHoliday(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
VacationLimit::factory([
@ -313,7 +313,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(),
@ -327,7 +327,7 @@ class VacationRequestTest extends FeatureTestCase
public function testUserCannotCreateVacationRequestIfHeHasPendingVacationRequestInThisRange(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
VacationLimit::factory([
@ -349,7 +349,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(),
@ -363,7 +363,7 @@ class VacationRequestTest extends FeatureTestCase
public function testUserCannotCreateVacationRequestIfHeHasApprovedVacationRequestInThisRange(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
VacationLimit::factory([
@ -385,7 +385,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(),
@ -399,10 +399,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(),
@ -416,11 +416,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(),
@ -434,22 +434,22 @@ class VacationRequestTest extends FeatureTestCase
public function testEmployeeCanSeeOnlyHisVacationRequests(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$this->actingAs($user)
->get("/vacation-requests")
->assertRedirect("/vacation-requests/me");
->get("/vacation/requests")
->assertRedirect("/vacation/requests/me");
}
public function testEmployeeCannotCreateVacationRequestForAnotherEmployee(): void
{
$user = User::factory()->createQuietly();
$anotherUser = User::factory()->createQuietly();
$user = User::factory()->create();
$anotherUser = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
$this->actingAs($user)
->post("/vacation-requests", [
->post("/vacation/requests", [
"user" => $anotherUser->id,
"type" => VacationType::Vacation->value,
"from" => Carbon::create($currentYearPeriod->year, 2, 7)->toDateString(),
@ -461,7 +461,7 @@ class VacationRequestTest extends FeatureTestCase
public function testEmployeeCanCancelVacationRequestWithWaitingForAdministrativeStatus(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
VacationLimit::factory([
@ -481,7 +481,7 @@ class VacationRequestTest extends FeatureTestCase
->create();
$this->actingAs($user)
->post("/vacation-requests/{$vacationRequest->id}/cancel")
->post("/vacation/requests/{$vacationRequest->id}/cancel")
->assertRedirect();
$vacationRequest->refresh();
@ -491,7 +491,7 @@ class VacationRequestTest extends FeatureTestCase
public function testEmployeeCannotCancelVacationRequestWithApprovedStatus(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
VacationLimit::factory([
@ -511,14 +511,14 @@ class VacationRequestTest extends FeatureTestCase
->create();
$this->actingAs($user)
->post("/vacation-requests/{$vacationRequest->id}/cancel")
->post("/vacation/requests/{$vacationRequest->id}/cancel")
->assertForbidden();
}
public function testAdministrativeApproverCanCancelVacationRequestWithApprovedStatus(): void
{
$user = User::factory()->createQuietly();
$administrativeApprover = User::factory()->administrativeApprover()->createQuietly();
$user = User::factory()->create();
$administrativeApprover = User::factory()->administrativeApprover()->create();
$currentYearPeriod = YearPeriod::current();
VacationLimit::factory([
@ -538,7 +538,7 @@ class VacationRequestTest extends FeatureTestCase
->create();
$this->actingAs($administrativeApprover)
->post("/vacation-requests/{$vacationRequest->id}/cancel")
->post("/vacation/requests/{$vacationRequest->id}/cancel")
->assertRedirect();
$vacationRequest->refresh();
@ -548,7 +548,7 @@ class VacationRequestTest extends FeatureTestCase
public function testEmployeeCanDownloadHisVacationRequestAsPdf(): void
{
$user = User::factory()->createQuietly();
$user = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
VacationLimit::factory([
@ -568,14 +568,14 @@ class VacationRequestTest extends FeatureTestCase
->create();
$this->actingAs($user)
->get("/vacation-requests/{$vacationRequest->id}/download")
->get("/vacation/requests/{$vacationRequest->id}/download")
->assertSuccessful();
}
public function testEmployeeCannotDownloadAnotherEmployeesVacationRequestAsPdf(): void
{
$user = User::factory()->createQuietly();
$anotherUser = User::factory()->createQuietly();
$user = User::factory()->create();
$anotherUser = User::factory()->create();
$currentYearPeriod = YearPeriod::current();
VacationLimit::factory([
@ -595,7 +595,7 @@ class VacationRequestTest extends FeatureTestCase
->create();
$this->actingAs($user)
->get("/vacation-requests/{$vacationRequest->id}/download")
->get("/vacation/requests/{$vacationRequest->id}/download")
->assertForbidden();
}
}

View File

@ -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,
]);

View File

@ -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);
}

View File

@ -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();

View File

@ -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();

View File

@ -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,