This commit is contained in:
Adrian Hopek
2022-03-29 15:13:10 +02:00
parent 93f0151b14
commit 3c43f6814d
28 changed files with 176 additions and 144 deletions

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

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

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,