-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into #231-add-new-tab-to-menu-about-benefits-report
- Loading branch information
Showing
9 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
app/Domain/Notifications/BenefitsReportCreationNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/Infrastructure/Console/Commands/SendNotificationAboutBenefitsReportCreation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Infrastructure\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Spatie\Permission\Models\Permission; | ||
use Toby\Domain\Notifications\BenefitsReportCreationNotification; | ||
|
||
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 = Permission::findByName("receiveBenefitsReportCreationNotification")->users()->get(); | ||
|
||
foreach ($usersToNotify as $user) { | ||
$user->notify(new BenefitsReportCreationNotification()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Unit; | ||
|
||
use Illuminate\Foundation\Testing\DatabaseMigrations; | ||
use Illuminate\Support\Facades\Notification; | ||
use Tests\TestCase; | ||
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()->employee()->create(); | ||
$technicalApprover = User::factory()->technicalApprover()->create(); | ||
$administrativeApprover = User::factory()->administrativeApprover()->create(); | ||
$admin = User::factory()->admin()->create(); | ||
|
||
$this->artisan(SendNotificationAboutBenefitsReportCreation::class) | ||
->execute(); | ||
|
||
Notification::assertSentTo($administrativeApprover, BenefitsReportCreationNotification::class); | ||
Notification::assertNotSentTo([$user, $technicalApprover, $admin], BenefitsReportCreationNotification::class); | ||
} | ||
} |