#23 - wip
This commit is contained in:
@@ -6,7 +6,6 @@ namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\FeatureTestCase;
|
||||
use Toby\Enums\EmploymentForm;
|
||||
@@ -16,13 +15,6 @@ class UserTest extends FeatureTestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Storage::fake();
|
||||
}
|
||||
|
||||
public function testAdminCanSeeUsersList(): void
|
||||
{
|
||||
User::factory()->count(10)->create();
|
||||
|
83
tests/Feature/VacationLimitTest.php
Normal file
83
tests/Feature/VacationLimitTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\FeatureTestCase;
|
||||
use Toby\Models\User;
|
||||
use Toby\Models\VacationLimit;
|
||||
|
||||
class VacationLimitTest extends FeatureTestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function testAdminCanSeeVacationLimits(): void
|
||||
{
|
||||
$admin = User::factory()->createQuietly();
|
||||
|
||||
User::factory(10)->create();
|
||||
|
||||
$this->actingAs($admin)
|
||||
->get("/vacation-limits")
|
||||
->assertOk()
|
||||
->assertInertia(
|
||||
fn(Assert $page) => $page
|
||||
->component("VacationLimits")
|
||||
->has("limits.data", 10)
|
||||
);
|
||||
}
|
||||
|
||||
public function testAdminCanUpdateVacationLimits(): void
|
||||
{
|
||||
$admin = User::factory()->createQuietly();
|
||||
|
||||
User::factory(3)->create();
|
||||
|
||||
[$limit1, $limit2, $limit3] = VacationLimit::all();
|
||||
|
||||
$data = [
|
||||
[
|
||||
"id" => $limit1->id,
|
||||
"hasVacation" => true,
|
||||
"days" => 25,
|
||||
],
|
||||
[
|
||||
"id" => $limit2->id,
|
||||
"hasVacation" => false,
|
||||
"days" => null,
|
||||
],
|
||||
[
|
||||
"id" => $limit3->id,
|
||||
"hasVacation" => true,
|
||||
"days" => 20,
|
||||
],
|
||||
];
|
||||
|
||||
$this->actingAs($admin)
|
||||
->put("/vacation-limits", [
|
||||
"items" => $data
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas("vacation_limits", [
|
||||
"id" => $limit1->id,
|
||||
"has_vacation" => true,
|
||||
"days" => 25,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas("vacation_limits", [
|
||||
"id" => $limit2->id,
|
||||
"has_vacation" => false,
|
||||
"days" => null,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas("vacation_limits", [
|
||||
"id" => $limit3->id,
|
||||
"has_vacation" => true,
|
||||
"days" => 20,
|
||||
]);
|
||||
}
|
||||
}
|
@@ -7,16 +7,19 @@ namespace Tests\Unit;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\InteractsWithYearPeriods;
|
||||
use Toby\Models\User;
|
||||
|
||||
class AvatarTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
use InteractsWithYearPeriods;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->createCurrentYearPeriod();
|
||||
Storage::fake();
|
||||
}
|
||||
|
||||
|
50
tests/Unit/VacationLimitTest.php
Normal file
50
tests/Unit/VacationLimitTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\InteractsWithYearPeriods;
|
||||
use Toby\Models\User;
|
||||
use Toby\Models\YearPeriod;
|
||||
|
||||
class VacationLimitTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
use InteractsWithYearPeriods;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->createCurrentYearPeriod();
|
||||
}
|
||||
|
||||
public function testWhenUserIsCreatedThenVacationLimitIsCreatedForCurrentYearPeriod(): void
|
||||
{
|
||||
$this->assertDatabaseCount("vacation_limits", 0);
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->assertDatabaseCount("vacation_limits", 1);
|
||||
|
||||
$this->assertDatabaseHas("vacation_limits", [
|
||||
"user_id" => $user->id,
|
||||
"year_period_id" => $currentYearPeriod->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testWhenYearPeriodIsCreatedThenVacationLimitsForThisYearPeriodAreCreated(): void
|
||||
{
|
||||
$this->assertDatabaseCount("vacation_limits", 0);
|
||||
|
||||
User::factory(10)->createQuietly();
|
||||
|
||||
YearPeriod::factory()->create();
|
||||
|
||||
$this->assertDatabaseCount("vacation_limits", 10);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user