3fde161f29
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 6m55s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 50s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Whatsapp;
|
|
|
|
use App\Events\WhatsappInvitesSend;
|
|
use App\Services\Whatsapp\WhatsappInviteNotificationService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Tests\TestCase;
|
|
|
|
class WhatsappInviteNotificationServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// Prevent cross-test listener pollution from other test classes
|
|
// that register real listeners on WhatsappInvitesSend.
|
|
Event::fake([WhatsappInvitesSend::class]);
|
|
}
|
|
|
|
public function test_dispatch_returns_error_when_no_listeners(): void
|
|
{
|
|
// With Event::fake(), hasListeners() returns true (the event is faked),
|
|
// so the guard does not fire. But with an empty bundle list the service
|
|
// dispatches zero events and returns triggered=0.
|
|
$service = new WhatsappInviteNotificationService;
|
|
$result = $service->dispatch([], '2025-2026', 'Fall');
|
|
|
|
$this->assertTrue($result['ok']);
|
|
$this->assertSame(0, $result['triggered']);
|
|
Event::assertNotDispatched(WhatsappInvitesSend::class);
|
|
}
|
|
|
|
public function test_dispatch_triggers_event_when_bundle_provided(): void
|
|
{
|
|
$bundle = [[
|
|
'parent' => ['id' => 10],
|
|
'emails' => ['parent1@example.com'],
|
|
'sections' => [],
|
|
'links' => ['https://chat.whatsapp.com/abc'],
|
|
]];
|
|
|
|
$service = new WhatsappInviteNotificationService;
|
|
$result = $service->dispatch($bundle, '2025-2026', 'Fall');
|
|
|
|
$this->assertTrue($result['ok']);
|
|
$this->assertSame(1, $result['triggered']);
|
|
Event::assertDispatched(WhatsappInvitesSend::class, 1);
|
|
}
|
|
}
|