* #28 - holidays management * #28 - fix * #28 - fix * #28 - fix * #28 - fix * #28 - fix * #28 - fix * #28 - cr fix
This commit is contained in:
127
tests/Feature/HolidayTest.php
Normal file
127
tests/Feature/HolidayTest.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\FeatureTestCase;
|
||||
use Toby\Models\Holiday;
|
||||
use Toby\Models\User;
|
||||
use Toby\Models\YearPeriod;
|
||||
|
||||
class HolidayTest extends FeatureTestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function testUserCanSeeHolidayList(): void
|
||||
{
|
||||
Holiday::factory()->count(10)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->assertDatabaseCount("holidays", 10);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get("/holidays")
|
||||
->assertInertia(
|
||||
fn(Assert $page) => $page
|
||||
->component("Holidays/Index")
|
||||
->has("holidays.data", 10),
|
||||
);
|
||||
}
|
||||
|
||||
public function testAdminCanCreateHoliday(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
$this->actingAs($admin)
|
||||
->post("/holidays", [
|
||||
"name" => "Holiday 1",
|
||||
"date" => Carbon::create($currentYearPeriod->year, 5, 20)->toDateString(),
|
||||
])
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$this->assertDatabaseHas("holidays", [
|
||||
"name" => "Holiday 1",
|
||||
"date" => Carbon::create($currentYearPeriod->year, 5, 20),
|
||||
"year_period_id" => YearPeriod::current()->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAdminCannotCreateHolidayForYearPeriodThatDoesntExist(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
$year = YearPeriod::query()->max("year") + 1;
|
||||
|
||||
$this->actingAs($admin)
|
||||
->post("/holidays", [
|
||||
"name" => "Holiday 1",
|
||||
"date" => Carbon::create($year, 5, 20)->toDateString(),
|
||||
])
|
||||
->assertSessionHasErrors(["date"]);
|
||||
}
|
||||
|
||||
public function testAdminCannotCreateHolidayIfGivenDataIsUsed(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
$sameDate = Carbon::create($currentYearPeriod->year, 5, 20)->toDateString();
|
||||
|
||||
Holiday::factory()->create([
|
||||
"name" => "Holiday",
|
||||
"date" => $sameDate,
|
||||
]);
|
||||
|
||||
$this->actingAs($admin)
|
||||
->post("/holidays", [
|
||||
"name" => "Holiday 1",
|
||||
"date" => $sameDate,
|
||||
])
|
||||
->assertSessionHasErrors(["date"]);
|
||||
}
|
||||
|
||||
public function testAdminCanEditHoliday(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
$holiday = Holiday::factory()->create([
|
||||
"name" => "Name to change",
|
||||
"date" => Carbon::create($currentYearPeriod->year, 5, 20),
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas("holidays", [
|
||||
"name" => $holiday->name,
|
||||
"date" => $holiday->date->toDateString(),
|
||||
"year_period_id" => $currentYearPeriod->id,
|
||||
]);
|
||||
|
||||
$this->actingAs($admin)
|
||||
->put("/holidays/{$holiday->id}", [
|
||||
"name" => "Holiday 1",
|
||||
"date" => Carbon::create($currentYearPeriod->year, 10, 25)->toDateString(),
|
||||
])
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$this->assertDatabaseHas("holidays", [
|
||||
"name" => "Holiday 1",
|
||||
"date" => Carbon::create($currentYearPeriod->year, 10, 25)->toDateString(),
|
||||
"year_period_id" => $currentYearPeriod->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAdminCanDeleteHoliday(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
$holiday = Holiday::factory()->create();
|
||||
|
||||
$this->actingAs($admin)
|
||||
->delete("/holidays/{$holiday->id}")
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$this->assertDeleted($holiday);
|
||||
}
|
||||
}
|
@@ -89,7 +89,7 @@ class UserTest extends FeatureTestCase
|
||||
"lastName" => "Doe",
|
||||
"email" => "john.doe@example.com",
|
||||
"employmentForm" => EmploymentForm::B2B_CONTRACT->value,
|
||||
"employmentDate" => Carbon::now()->toDateTimeString(),
|
||||
"employmentDate" => Carbon::now()->toDateString(),
|
||||
])
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
@@ -98,7 +98,7 @@ class UserTest extends FeatureTestCase
|
||||
"last_name" => "Doe",
|
||||
"email" => "john.doe@example.com",
|
||||
"employment_form" => EmploymentForm::B2B_CONTRACT->value,
|
||||
"employment_date" => Carbon::now()->toDateTimeString(),
|
||||
"employment_date" => Carbon::now()->toDateString(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class UserTest extends FeatureTestCase
|
||||
"last_name" => $user->last_name,
|
||||
"email" => $user->email,
|
||||
"employment_form" => $user->employment_form->value,
|
||||
"employment_date" => $user->employment_date->toDateTimeString(),
|
||||
"employment_date" => $user->employment_date->toDateString(),
|
||||
]);
|
||||
|
||||
$this->actingAs($admin)
|
||||
@@ -123,7 +123,7 @@ class UserTest extends FeatureTestCase
|
||||
"lastName" => "Doe",
|
||||
"email" => "john.doe@example.com",
|
||||
"employmentForm" => EmploymentForm::B2B_CONTRACT->value,
|
||||
"employmentDate" => Carbon::now()->toDateTimeString(),
|
||||
"employmentDate" => Carbon::now()->toDateString(),
|
||||
])
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
@@ -132,7 +132,7 @@ class UserTest extends FeatureTestCase
|
||||
"last_name" => "Doe",
|
||||
"email" => "john.doe@example.com",
|
||||
"employment_form" => EmploymentForm::B2B_CONTRACT->value,
|
||||
"employment_date" => Carbon::now()->toDateTimeString(),
|
||||
"employment_date" => Carbon::now()->toDateString(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,7 @@ trait InteractsWithYearPeriods
|
||||
public function createYearPeriod(int $year): YearPeriod
|
||||
{
|
||||
/** @var YearPeriod $yearPeriod */
|
||||
$yearPeriod = YearPeriod::factory()->create([
|
||||
$yearPeriod = YearPeriod::factory()->createQuietly([
|
||||
"year" => $year,
|
||||
]);
|
||||
|
||||
|
Reference in New Issue
Block a user