createCurrentYearPeriod(); } public function testAfterChangingVacationRequestStateNotificationAreSentToUsers(): void { Notification::fake(); $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(); $currentYearPeriod = YearPeriod::current(); /** @var VacationRequest $vacationRequest */ $vacationRequest = VacationRequest::factory([ "type" => VacationType::Vacation->value, "state" => Created::class, "from" => Carbon::create($currentYearPeriod->year, 2, 1)->toDateString(), "to" => Carbon::create($currentYearPeriod->year, 2, 4)->toDateString(), "comment" => "Comment for the vacation request.", ]) ->for($user) ->for($currentYearPeriod) ->create(); $waitForTechApprovalAction = $this->app->make(WaitForTechApprovalAction::class); $waitForTechApprovalAction->execute($vacationRequest); Notification::assertSentTo([$technicalApprover, $admin], VacationRequestWaitsForApprovalNotification::class); Notification::assertNotSentTo([$user, $administrativeApprover], VacationRequestWaitsForApprovalNotification::class); } public function testNotificationIsSentOnceToUser(): void { Notification::fake(); $technicalApprover = User::factory([ "role" => Role::TechnicalApprover, ])->create(); $administrativeApprover = User::factory([ "role" => Role::AdministrativeApprover, ])->create(); $admin = User::factory([ "role" => Role::Administrator, ])->create(); $currentYearPeriod = YearPeriod::current(); /** @var VacationRequest $vacationRequest */ $vacationRequest = VacationRequest::factory([ "type" => VacationType::Vacation->value, "state" => WaitingForTechnical::class, "from" => Carbon::create($currentYearPeriod->year, 2, 1)->toDateString(), "to" => Carbon::create($currentYearPeriod->year, 2, 4)->toDateString(), "comment" => "Comment for the vacation request.", ]) ->for($administrativeApprover) ->for($currentYearPeriod) ->create(); $rejectAction = $this->app->make(RejectAction::class); $rejectAction->execute($vacationRequest, $technicalApprover); Notification::assertSentTo([$technicalApprover, $admin, $administrativeApprover], VacationRequestStatusChangedNotification::class); Notification::assertTimesSent(3, VacationRequestStatusChangedNotification::class); } }