Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#235 - e-mail notification for administrative approval to fill benefits #344

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions app/Domain/Notifications/BenefitsReportCreationNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Toby\Domain\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;

class BenefitsReportCreationNotification extends QueuedNotification
{
use Queueable;

public function via(): array
{
return [Channels::MAIL];
}

public function toMail(Notifiable $notifiable): MailMessage
{
$url = route("assigned-benefits.index");

return $this->buildMailMessage($notifiable, $url);
}

protected function buildMailMessage(Notifiable $notifiable, string $url): MailMessage
{
$user = $notifiable->profile->first_name;

$message = (new MailMessage())
->greeting(
__("Hi :user!", [
"user" => $user,
]),
)
->subject(__("Reminder to create benefit report"))
->line(__("This message is a reminder to create a report for benefits for this month. If a report has already been created, please ignore this message."));

return $message
->action(__("Benefits reports"), $url);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Toby\Infrastructure\Console\Commands;

use Illuminate\Console\Command;
use Toby\Domain\Enums\Role;
use Toby\Domain\Notifications\BenefitsReportCreationNotification;
use Toby\Eloquent\Models\User;

class SendNotificationAboutBenefitsReportCreation extends Command
{
protected $signature = "toby:send-notification-about-benefits-report-creation";
protected $description = "Send notifications about benefits report creation.";

public function handle(): void
{
$usersToNotify = User::query()
->whereIn("role", [Role::AdministrativeApprover])
->get();

foreach ($usersToNotify as $user) {
$user->notify(new BenefitsReportCreationNotification());
}
}
}
5 changes: 5 additions & 0 deletions app/Infrastructure/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Psr\Container\NotFoundExceptionInterface;
use Toby\Infrastructure\Console\Commands\Database\BackupPostgresDatabase;
use Toby\Infrastructure\Console\Commands\SendDailySummaryToSlack;
use Toby\Infrastructure\Console\Commands\SendNotificationAboutBenefitsReportCreation;
use Toby\Infrastructure\Console\Commands\SendNotificationAboutUpcomingAndOverdueMedicalExams;
use Toby\Infrastructure\Console\Commands\SendNotificationAboutUpcomingAndOverdueOhsTraining;
use Toby\Infrastructure\Console\Commands\SendVacationRequestSummariesToApprovers;
Expand Down Expand Up @@ -48,6 +49,10 @@ protected function schedule(Schedule $schedule): void
->monthlyOn(1, "08:00")
->onOneServer();

$schedule->command(SendNotificationAboutBenefitsReportCreation::class)
->lastDayOfMonth("08:00")
->onOneServer();

$schedule->job(CheckYearPeriod::class)
->yearlyOn(1, 1, "01:00")
->onOneServer();
Expand Down
5 changes: 4 additions & 1 deletion lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,8 @@
"The deadline for OHS training for some employees is about to expire.": "Niedługo mija termin szkolenia BHP dla części pracowników.",
"Below is a list of employees with upcoming OHS training:": "Poniżej znajduje się lista pracowników ze zbliżającym się terminem szkolenia BHP:",
"The deadline for OHS training for some employees has passed.": "Termin szkolenia BHP dla części pracowników minął.",
"Below is a list of employees with overdue OHS training:": "Poniżej znajduje się lista pracowników z przeterminowanym szkoleniem BHP:"
"Below is a list of employees with overdue OHS training:": "Poniżej znajduje się lista pracowników z przeterminowanym szkoleniem BHP:",
"Reminder to create benefit report": "Przypomnienie o utworzeniu raportu benefitów",
"This message is a reminder to create a report for benefits for this month. If a report has already been created, please ignore this message.": "Ta wiadomość jest przypomnieniem o utworzeniu raportu dla benefitów za obecny miesiąc. Jeśli raport już został utworzony, zignoruj tę wiadomość.",
"Benefits reports": "Raporty benefitów"
}
43 changes: 43 additions & 0 deletions tests/Unit/BenefitsReportCreationNotificationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Tests\Unit;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
use Toby\Domain\Enums\Role;
use Toby\Domain\Notifications\BenefitsReportCreationNotification;
use Toby\Eloquent\Models\User;
use Toby\Infrastructure\Console\Commands\SendNotificationAboutBenefitsReportCreation;

class BenefitsReportCreationNotificationTest extends TestCase
{
use DatabaseMigrations;

public function testSendingNotificationAboutBenefitsReportCreation(): 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();

$this->artisan(SendNotificationAboutBenefitsReportCreation::class)
->execute();

Notification::assertSentTo($administrativeApprover, BenefitsReportCreationNotification::class);
Notification::assertNotSentTo([$user, $technicalApprover, $admin], BenefitsReportCreationNotification::class);
}
}
Loading