From c09a1e664a0f1aabc49b814797dd905ecfe0e59f Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Tue, 29 Mar 2022 10:40:51 +0200 Subject: [PATCH 1/5] - added some test --- .../Http/Controllers/GoogleController.php | 2 +- tests/Feature/MonthlyUsageTest.php | 32 ++++ tests/Feature/VacationCalendarTest.php | 33 ++++ tests/Feature/VacationRequestTest.php | 176 ++++++++++++++++++ 4 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/MonthlyUsageTest.php create mode 100644 tests/Feature/VacationCalendarTest.php diff --git a/app/Infrastructure/Http/Controllers/GoogleController.php b/app/Infrastructure/Http/Controllers/GoogleController.php index 6f15e8d..7733e7c 100644 --- a/app/Infrastructure/Http/Controllers/GoogleController.php +++ b/app/Infrastructure/Http/Controllers/GoogleController.php @@ -36,6 +36,6 @@ class GoogleController extends Controller $auth->guard()->login($user, true); - return redirect()->route("dashboard"); + return redirect()->intended(); } } diff --git a/tests/Feature/MonthlyUsageTest.php b/tests/Feature/MonthlyUsageTest.php new file mode 100644 index 0000000..cface61 --- /dev/null +++ b/tests/Feature/MonthlyUsageTest.php @@ -0,0 +1,32 @@ +admin()->createQuietly(); + + $this->actingAs($admin) + ->get("/monthly-usage") + ->assertOk(); + } + + public function testEmployeeCannotSeeVacationsMonthlyUsage(): void + { + $user = User::factory()->createQuietly(); + + $this->actingAs($user) + ->get("/monthly-usage") + ->assertForbidden(); + } +} diff --git a/tests/Feature/VacationCalendarTest.php b/tests/Feature/VacationCalendarTest.php new file mode 100644 index 0000000..e2e6f39 --- /dev/null +++ b/tests/Feature/VacationCalendarTest.php @@ -0,0 +1,33 @@ +createQuietly(); + $administrativeApprover = User::factory()->administrativeApprover()->createQuietly(); + + $this->actingAs($administrativeApprover) + ->get("/timesheet/january") + ->assertOk(); + } + + public function testEmployeeCannotDownloadTimesheet(): void + { + $user = User::factory()->createQuietly(); + + $this->actingAs($user) + ->get("/timesheet/january") + ->assertForbidden(); + } +} diff --git a/tests/Feature/VacationRequestTest.php b/tests/Feature/VacationRequestTest.php index 07bf8a5..9df10de 100644 --- a/tests/Feature/VacationRequestTest.php +++ b/tests/Feature/VacationRequestTest.php @@ -13,6 +13,7 @@ use Tests\FeatureTestCase; use Toby\Domain\Enums\VacationType; use Toby\Domain\PolishHolidaysRetriever; use Toby\Domain\States\VacationRequest\Approved; +use Toby\Domain\States\VacationRequest\Cancelled; use Toby\Domain\States\VacationRequest\Rejected; use Toby\Domain\States\VacationRequest\WaitingForAdministrative; use Toby\Domain\States\VacationRequest\WaitingForTechnical; @@ -430,4 +431,179 @@ class VacationRequestTest extends FeatureTestCase "vacationRequest" => __("The vacation request cannot be created at the turn of the year."), ]); } + + public function testEmployeeCanSeeOnlyHisVacationRequests(): void + { + $user = User::factory()->createQuietly(); + + $currentYearPeriod = YearPeriod::current(); + + VacationRequest::factory() + ->count(10) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + $this->actingAs($user) + ->get("/vacation-requests") + ->assertRedirect("/vacation-requests/me"); + } + + public function testEmployeeCannotCreateVacationRequestForAnotherEmployee(): void + { + $user = User::factory()->createQuietly(); + $anotherUser = User::factory()->createQuietly(); + + $currentYearPeriod = YearPeriod::current(); + + $this->actingAs($user) + ->post("/vacation-requests", [ + "user" => $anotherUser->id, + "type" => VacationType::Vacation->value, + "from" => Carbon::create($currentYearPeriod->year, 2, 7)->toDateString(), + "to" => Carbon::create($currentYearPeriod->year, 2, 11)->toDateString(), + "comment" => "Comment for the vacation request.", + ]) + ->assertForbidden(); + } + + public function testEmployeeCanCancelVacationRequestWithWaitingForAdministrativeStatus(): void + { + $user = User::factory()->createQuietly(); + $currentYearPeriod = YearPeriod::current(); + + VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + /** @var VacationRequest $vacationRequest */ + $vacationRequest = VacationRequest::factory([ + "state" => WaitingForAdministrative::class, + "type" => VacationType::Vacation, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + $this->actingAs($user) + ->post("/vacation-requests/{$vacationRequest->id}/cancel") + ->assertSessionHasNoErrors(); + + $vacationRequest->refresh(); + + $this->assertTrue($vacationRequest->state->equals(Cancelled::class)); + } + + public function testEmployeeCannotCancelVacationRequestWithApprovedStatus(): void + { + $user = User::factory()->createQuietly(); + $currentYearPeriod = YearPeriod::current(); + + VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + /** @var VacationRequest $vacationRequest */ + $vacationRequest = VacationRequest::factory([ + "state" => Approved::class, + "type" => VacationType::Vacation, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + $this->actingAs($user) + ->post("/vacation-requests/{$vacationRequest->id}/cancel") + ->assertStatus(403); + } + + public function testAdministrativeApproverCanCancelVacationRequestWithApprovedStatus(): void + { + $user = User::factory()->createQuietly(); + $administrativeApprover = User::factory()->administrativeApprover()->createQuietly(); + $currentYearPeriod = YearPeriod::current(); + + VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + /** @var VacationRequest $vacationRequest */ + $vacationRequest = VacationRequest::factory([ + "state" => Approved::class, + "type" => VacationType::Vacation, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + $this->actingAs($administrativeApprover) + ->post("/vacation-requests/{$vacationRequest->id}/cancel") + ->assertSessionHasNoErrors(); + + $vacationRequest->refresh(); + + $this->assertTrue($vacationRequest->state->equals(Cancelled::class)); + } + + public function testEmployeeCanDownloadHisVacationRequestAsPdf(): void + { + $user = User::factory()->createQuietly(); + $currentYearPeriod = YearPeriod::current(); + + VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + /** @var VacationRequest $vacationRequest */ + $vacationRequest = VacationRequest::factory([ + "state" => WaitingForTechnical::class, + "type" => VacationType::Vacation, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + $this->actingAs($user) + ->get("/vacation-requests/{$vacationRequest->id}/download") + ->assertSessionHasNoErrors(); + } + + public function testEmployeeCannotDownloadAnotherEmployeesVacationRequestAsPdf(): void + { + $user = User::factory()->createQuietly(); + $anotherUser = User::factory()->createQuietly(); + $currentYearPeriod = YearPeriod::current(); + + VacationLimit::factory([ + "days" => 20, + ]) + ->for($anotherUser) + ->for($currentYearPeriod) + ->create(); + + /** @var VacationRequest $vacationRequest */ + $vacationRequest = VacationRequest::factory([ + "state" => WaitingForTechnical::class, + "type" => VacationType::Vacation, + ]) + ->for($anotherUser) + ->for($currentYearPeriod) + ->create(); + + $this->actingAs($user) + ->get("/vacation-requests/{$vacationRequest->id}/download") + ->assertForbidden(); + } } -- 2.52.0 From 435158f426edb7b2811ebc52826d408ce89dff1c Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Tue, 29 Mar 2022 10:59:48 +0200 Subject: [PATCH 2/5] - cr fix --- tests/Feature/VacationRequestTest.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/Feature/VacationRequestTest.php b/tests/Feature/VacationRequestTest.php index 9df10de..2612fcb 100644 --- a/tests/Feature/VacationRequestTest.php +++ b/tests/Feature/VacationRequestTest.php @@ -436,14 +436,6 @@ class VacationRequestTest extends FeatureTestCase { $user = User::factory()->createQuietly(); - $currentYearPeriod = YearPeriod::current(); - - VacationRequest::factory() - ->count(10) - ->for($user) - ->for($currentYearPeriod) - ->create(); - $this->actingAs($user) ->get("/vacation-requests") ->assertRedirect("/vacation-requests/me"); @@ -520,7 +512,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($user) ->post("/vacation-requests/{$vacationRequest->id}/cancel") - ->assertStatus(403); + ->assertForbidden(); } public function testAdministrativeApproverCanCancelVacationRequestWithApprovedStatus(): void -- 2.52.0 From 6605febce71e079c7b8974d3895b708ec0460d3b Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Wed, 30 Mar 2022 09:20:13 +0200 Subject: [PATCH 3/5] - cr fix --- app/Infrastructure/Http/Controllers/GoogleController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Infrastructure/Http/Controllers/GoogleController.php b/app/Infrastructure/Http/Controllers/GoogleController.php index 7733e7c..6f15e8d 100644 --- a/app/Infrastructure/Http/Controllers/GoogleController.php +++ b/app/Infrastructure/Http/Controllers/GoogleController.php @@ -36,6 +36,6 @@ class GoogleController extends Controller $auth->guard()->login($user, true); - return redirect()->intended(); + return redirect()->route("dashboard"); } } -- 2.52.0 From 5aa031355a34b6097bb9c7ccd4d60b5885bb1c59 Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Wed, 30 Mar 2022 09:33:02 +0200 Subject: [PATCH 4/5] - cr fix --- tests/Feature/VacationCalendarTest.php | 1 - tests/Feature/VacationRequestTest.php | 18 +++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/Feature/VacationCalendarTest.php b/tests/Feature/VacationCalendarTest.php index e2e6f39..54d7959 100644 --- a/tests/Feature/VacationCalendarTest.php +++ b/tests/Feature/VacationCalendarTest.php @@ -14,7 +14,6 @@ class VacationCalendarTest extends FeatureTestCase public function testAdministrativeApproverCanDownloadTimesheet(): void { - $user = User::factory()->createQuietly(); $administrativeApprover = User::factory()->administrativeApprover()->createQuietly(); $this->actingAs($administrativeApprover) diff --git a/tests/Feature/VacationRequestTest.php b/tests/Feature/VacationRequestTest.php index 2612fcb..27ad6c9 100644 --- a/tests/Feature/VacationRequestTest.php +++ b/tests/Feature/VacationRequestTest.php @@ -80,7 +80,7 @@ class VacationRequestTest extends FeatureTestCase "to" => Carbon::create($currentYearPeriod->year, 2, 11)->toDateString(), "comment" => "Comment for the vacation request.", ]) - ->assertSessionHasNoErrors(); + ->assertOk(); $this->assertDatabaseHas("vacation_requests", [ "user_id" => $user->id, @@ -115,7 +115,7 @@ class VacationRequestTest extends FeatureTestCase "to" => Carbon::create($currentYearPeriod->year, 2, 11)->toDateString(), "comment" => "Comment for the vacation request.", ]) - ->assertSessionHasNoErrors(); + ->assertOk(); $this->assertDatabaseHas("vacation_requests", [ "user_id" => $user->id, @@ -152,7 +152,7 @@ class VacationRequestTest extends FeatureTestCase "comment" => "Comment for the vacation request.", "flowSkipped" => true, ]) - ->assertSessionHasNoErrors(); + ->assertOk(); $this->assertDatabaseHas("vacation_requests", [ "user_id" => $user->id, @@ -182,7 +182,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($technicalApprover) ->post("/vacation-requests/{$vacationRequest->id}/accept-as-technical") - ->assertSessionHasNoErrors(); + ->assertOk(); $vacationRequest->refresh(); @@ -205,7 +205,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($administrativeApprover) ->post("/vacation-requests/{$vacationRequest->id}/accept-as-administrative") - ->assertSessionHasNoErrors(); + ->assertOk(); $vacationRequest->refresh(); @@ -236,7 +236,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($technicalApprover) ->post("/vacation-requests/{$vacationRequest->id}/reject") - ->assertSessionHasNoErrors(); + ->assertOk(); $vacationRequest->refresh(); @@ -482,7 +482,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($user) ->post("/vacation-requests/{$vacationRequest->id}/cancel") - ->assertSessionHasNoErrors(); + ->assertOk(); $vacationRequest->refresh(); @@ -539,7 +539,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($administrativeApprover) ->post("/vacation-requests/{$vacationRequest->id}/cancel") - ->assertSessionHasNoErrors(); + ->assertOk(); $vacationRequest->refresh(); @@ -569,7 +569,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($user) ->get("/vacation-requests/{$vacationRequest->id}/download") - ->assertSessionHasNoErrors(); + ->assertOk(); } public function testEmployeeCannotDownloadAnotherEmployeesVacationRequestAsPdf(): void -- 2.52.0 From cb51840e814a72a9b8ea428b1e27970223ce73fe Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Wed, 30 Mar 2022 09:47:00 +0200 Subject: [PATCH 5/5] - cr fix --- tests/Feature/VacationRequestTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Feature/VacationRequestTest.php b/tests/Feature/VacationRequestTest.php index 27ad6c9..0335f95 100644 --- a/tests/Feature/VacationRequestTest.php +++ b/tests/Feature/VacationRequestTest.php @@ -80,7 +80,7 @@ class VacationRequestTest extends FeatureTestCase "to" => Carbon::create($currentYearPeriod->year, 2, 11)->toDateString(), "comment" => "Comment for the vacation request.", ]) - ->assertOk(); + ->assertRedirect(); $this->assertDatabaseHas("vacation_requests", [ "user_id" => $user->id, @@ -115,7 +115,7 @@ class VacationRequestTest extends FeatureTestCase "to" => Carbon::create($currentYearPeriod->year, 2, 11)->toDateString(), "comment" => "Comment for the vacation request.", ]) - ->assertOk(); + ->assertRedirect(); $this->assertDatabaseHas("vacation_requests", [ "user_id" => $user->id, @@ -152,7 +152,7 @@ class VacationRequestTest extends FeatureTestCase "comment" => "Comment for the vacation request.", "flowSkipped" => true, ]) - ->assertOk(); + ->assertRedirect(); $this->assertDatabaseHas("vacation_requests", [ "user_id" => $user->id, @@ -182,7 +182,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($technicalApprover) ->post("/vacation-requests/{$vacationRequest->id}/accept-as-technical") - ->assertOk(); + ->assertRedirect(); $vacationRequest->refresh(); @@ -205,7 +205,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($administrativeApprover) ->post("/vacation-requests/{$vacationRequest->id}/accept-as-administrative") - ->assertOk(); + ->assertRedirect(); $vacationRequest->refresh(); @@ -236,7 +236,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($technicalApprover) ->post("/vacation-requests/{$vacationRequest->id}/reject") - ->assertOk(); + ->assertRedirect(); $vacationRequest->refresh(); @@ -482,7 +482,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($user) ->post("/vacation-requests/{$vacationRequest->id}/cancel") - ->assertOk(); + ->assertRedirect(); $vacationRequest->refresh(); @@ -539,7 +539,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($administrativeApprover) ->post("/vacation-requests/{$vacationRequest->id}/cancel") - ->assertOk(); + ->assertRedirect(); $vacationRequest->refresh(); @@ -569,7 +569,7 @@ class VacationRequestTest extends FeatureTestCase $this->actingAs($user) ->get("/vacation-requests/{$vacationRequest->id}/download") - ->assertOk(); + ->assertSuccessful(); } public function testEmployeeCannotDownloadAnotherEmployeesVacationRequestAsPdf(): void -- 2.52.0