diff --git a/app/Domain/Notifications/VacationRequestsSummaryNotification.php b/app/Domain/Notifications/VacationRequestsSummaryNotification.php index a56d12a..e5132b7 100644 --- a/app/Domain/Notifications/VacationRequestsSummaryNotification.php +++ b/app/Domain/Notifications/VacationRequestsSummaryNotification.php @@ -30,7 +30,7 @@ class VacationRequestsSummaryNotification extends Notification public function toSlack(): SlackMessage { return (new SlackMessage()) - ->text("Lista wniosków oczekujących na Twoją akcję - stan na dzień {$this->day->toDisplayString()}:") + ->text("Wnioski oczekujące na Twoją akcję - stan na dzień {$this->day->toDisplayString()}:") ->withAttachment(new VacationRequestsAttachment($this->vacationRequests)); } diff --git a/tests/Unit/SendVacationRequestSummariesTest.php b/tests/Unit/SendVacationRequestSummariesTest.php new file mode 100644 index 0000000..e1dabb5 --- /dev/null +++ b/tests/Unit/SendVacationRequestSummariesTest.php @@ -0,0 +1,128 @@ +createCurrentYearPeriod(); + } + + public function testSummariesAreSentOnlyToProperApprovers(): void + { + $currentYearPeriod = YearPeriod::current(); + + $user = User::factory([ + "role" => Role::Employee, + ])->create(); + $technicalApprover = User::factory([ + "role" => Role::TechnicalApprover, + ])->create(); + $administrativeApprover = User::factory([ + "role" => Role::AdministrativeApprover, + ])->create(); + $admin = User::factory([ + "role" => Role::Administrator, + ])->create(); + + VacationRequest::factory() + ->for($user) + ->for($currentYearPeriod) + ->create(["state" => WaitingForTechnical::class]); + + $this->artisan(SendVacationRequestSummariesToApprovers::class) + ->execute(); + + Notification::assertSentTo([$technicalApprover, $admin], VacationRequestsSummaryNotification::class); + } + + public function testSummariesAreSentOnlyIfVacationRequestWaitingForActionExists(): void + { + $currentYearPeriod = YearPeriod::current(); + + $user = User::factory([ + "role" => Role::Employee, + ])->create(); + $technicalApprover = User::factory([ + "role" => Role::TechnicalApprover, + ])->create(); + $admin = User::factory([ + "role" => Role::Administrator, + ])->create(); + + VacationRequest::factory() + ->for($user) + ->for($currentYearPeriod) + ->create(["state" => WaitingForTechnical::class]); + + $this->artisan(SendVacationRequestSummariesToApprovers::class) + ->execute(); + + Notification::assertSentTo([$technicalApprover, $admin], VacationRequestsSummaryNotification::class); + } + + public function testSummariesAreNotSendIfTherAreNoWaitingForActionVacationRequests(): void + { + $currentYearPeriod = YearPeriod::current(); + + $user = User::factory([ + "role" => Role::Employee, + ])->create(); + $technicalApprover = User::factory([ + "role" => Role::TechnicalApprover, + ])->create(); + $admin = User::factory([ + "role" => Role::Administrator, + ])->create(); + + VacationRequest::factory() + ->for($user) + ->for($currentYearPeriod) + ->create(["state" => Approved::class]); + + VacationRequest::factory() + ->for($user) + ->for($currentYearPeriod) + ->create(["state" => Cancelled::class]); + + VacationRequest::factory() + ->for($user) + ->for($currentYearPeriod) + ->create(["state" => Rejected::class]); + + VacationRequest::factory() + ->for($user) + ->for($currentYearPeriod) + ->create(["state" => Created::class]); + + $this->artisan(SendVacationRequestSummariesToApprovers::class) + ->execute(); + + Notification::assertNotSentTo([$technicalApprover, $admin], VacationRequestsSummaryNotification::class); + } +}