- 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
40 changed files with 323 additions and 286 deletions

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,