41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Packages;
|
|
|
|
use App\Jobs\Packages\SendTenantCreditsLowNotification;
|
|
use App\Models\Tenant;
|
|
use App\Notifications\Packages\TenantCreditsLowNotification;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Tests\TestCase;
|
|
|
|
class SendTenantCreditsLowNotificationTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_logs_successful_notification(): void
|
|
{
|
|
Notification::fake();
|
|
|
|
$tenant = Tenant::factory()->create([
|
|
'contact_email' => 'admin@example.com',
|
|
]);
|
|
|
|
$job = new SendTenantCreditsLowNotification($tenant->id, balance: 5, threshold: 10);
|
|
$job->handle();
|
|
|
|
Notification::assertSentOnDemand(TenantCreditsLowNotification::class, function ($notification, $channels, $notifiable) {
|
|
return in_array('mail', $channels, true) && ($notifiable->routes['mail'] ?? null) === 'admin@example.com';
|
|
});
|
|
|
|
$tenant->refresh();
|
|
|
|
$this->assertCount(1, $tenant->notificationLogs);
|
|
$log = $tenant->notificationLogs()->first();
|
|
$this->assertSame('credits_low', $log->type);
|
|
$this->assertSame('sent', $log->status);
|
|
$this->assertSame('admin@example.com', $log->recipient);
|
|
$this->assertNotNull($log->sent_at);
|
|
}
|
|
}
|