2026-07-24 21:11:51 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Mail\AdWalletLowBalanceNotification;
|
|
|
|
|
use App\Models\AdWallet;
|
|
|
|
|
use App\Models\Tenant;
|
|
|
|
|
use App\Services\Advertising\AdStopAllService;
|
2026-08-02 01:15:44 +03:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2026-07-24 21:11:51 +03:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
|
2026-08-02 01:15:44 +03:00
|
|
|
// Откат после теста. Без него записи файла остаются в базе и роняют ЧУЖИЕ тесты:
|
|
|
|
|
// 01.08.2026 девятнадцать чужих проводок уронили денежную проверку приёмника МТС.
|
|
|
|
|
uses(DatabaseTransactions::class);
|
|
|
|
|
|
2026-07-24 21:11:51 +03:00
|
|
|
/**
|
|
|
|
|
* Письмо владельцу тенанта при остановке рекламы из-за нехватки денег
|
|
|
|
|
* на рекламном кошельке (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();
|
|
|
|
|
});
|