Skip to content

Commit 97359c7

Browse files
committed
fix notifications
1 parent d753644 commit 97359c7

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

src/Notifiables/AdminNotifiable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class AdminNotifiable
1212
private static array $emails = [];
1313
private static ?string $mobile = null;
1414

15+
public function getKey(): string
16+
{
17+
return 'admin';
18+
}
19+
1520
public static function configEmails(array $emails): void
1621
{
1722
self::$emails = $emails;

src/Notifications/Admin/ReportNotification.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace DescomMarket\Common\Notifications\Admin;
44

5-
use Descom\B2b\Core\App\WhatsApp\Template;
6-
use Descom\B2b\Core\App\WhatsApp\WhatsApp;
75
use Illuminate\Bus\Queueable;
86
use Illuminate\Contracts\Queue\ShouldQueue;
97
use Illuminate\Notifications\Messages\MailMessage;
@@ -13,20 +11,14 @@ class ReportNotification extends Notification implements ShouldQueue
1311
{
1412
use Queueable;
1513

16-
private ?string $whatsAppTemplate = null;
17-
18-
public function __construct(private string $subject, private string $message, private ?string $urlAction = null)
14+
public function __construct(private string $subject, private string $message)
1915
{
2016
}
2117

2218
public function via($notifiable)
2319
{
2420
$channels = [];
2521

26-
if (WhatsApp::canNotifyByWaba($notifiable) && $notifiable->whatsAppMobile($this)) {
27-
$channels[] = 'whatsapp';
28-
}
29-
3022
if ($notifiable->routeNotificationForMail($this)) {
3123
$channels[] = 'mail';
3224
}
@@ -48,18 +40,4 @@ public function toMail($notifiable)
4840

4941
return $mailMessage;
5042
}
51-
52-
public function toWhatsapp($notifiable)
53-
{
54-
$urlPath = $this->urlAction ? str_replace([Frontend::url(''), Frontend::urlApi('')], '', $this->urlAction) : null;
55-
56-
$whatsapp = Template::build($this->whatsAppTemplate)
57-
->parameters([$this->message]);
58-
59-
if ($urlPath) {
60-
$whatsapp->link($urlPath);
61-
}
62-
63-
return $whatsapp;
64-
}
6543
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace DescomMarket\Common\Tests\Feature;
4+
5+
use DescomMarket\Common\Notifiables\AdminNotifiable;
6+
use DescomMarket\Common\Notifications\Admin\ReportNotification;
7+
use DescomMarket\Common\Tests\TestCase;
8+
use Illuminate\Support\Facades\Notification;
9+
10+
class ReportNotificationTest extends TestCase
11+
{
12+
public function testSendReportNotification()
13+
{
14+
Notification::fake();
15+
16+
AdminNotifiable::configEmails(['sample@example.com']);
17+
18+
(new AdminNotifiable())->notify(new ReportNotification('subject', 'body'));
19+
20+
Notification::assertSentTo(
21+
(new AdminNotifiable()),
22+
ReportNotification::class
23+
);
24+
}
25+
}

0 commit comments

Comments
 (0)