Files
portal/app/tests/Feature/Advertising/AdWalletLowBalanceMailTest.php
T

35 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
use App\Mail\AdWalletLowBalanceNotification;
use App\Models\AdWallet;
use App\Models\Tenant;
use App\Services\Advertising\AdStopAllService;
use Illuminate\Support\Facades\Mail;
/**
* Письмо владельцу тенанта при остановке рекламы из-за нехватки денег
* на рекламном кошельке (Task 9, часть A).
*/
it('queues AdWalletLowBalanceNotification to tenant contact email when advertising is stopped', function () {
Mail::fake();
$tenant = Tenant::factory()->create(['contact_email' => 'owner@example.com']);
AdWallet::create(['tenant_id' => $tenant->id, 'balance_rub' => '100.00', 'frozen_rub' => '2500.00']);
app(AdStopAllService::class)->stopAll($tenant->id);
Mail::assertQueued(
AdWalletLowBalanceNotification::class,
fn ($mail) => $mail->hasTo($tenant->contact_email)
);
});
it('skips mail (no crash) when tenant does not exist', function () {
Mail::fake();
app(AdStopAllService::class)->stopAll(999999);
Mail::assertNothingQueued();
});