2026-07-24 21:00:54 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Events\AdvertisingStopped;
|
|
|
|
|
use App\Models\AdWallet;
|
|
|
|
|
use App\Models\Tenant;
|
|
|
|
|
use App\Services\Advertising\AdStopAllService;
|
|
|
|
|
use App\Services\Advertising\AdWalletGate;
|
2026-08-02 01:15:44 +03:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2026-07-24 21:00:54 +03:00
|
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
|
|
2026-08-02 01:15:44 +03:00
|
|
|
// Откат после теста. Без него записи файла остаются в базе и роняют ЧУЖИЕ тесты:
|
|
|
|
|
// 01.08.2026 девятнадцать чужих проводок уронили денежную проверку приёмника МТС.
|
|
|
|
|
uses(DatabaseTransactions::class);
|
|
|
|
|
|
2026-07-24 21:00:54 +03:00
|
|
|
it('reports insufficient when free balance cannot cover active holds', function () {
|
|
|
|
|
$tenant = Tenant::factory()->create();
|
|
|
|
|
AdWallet::create(['tenant_id' => $tenant->id, 'balance_rub' => '100.00', 'frozen_rub' => '2500.00']);
|
|
|
|
|
|
|
|
|
|
$gate = app(AdWalletGate::class);
|
|
|
|
|
expect($gate->isSolvent($tenant->id))->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('dispatches AdvertisingStopped when stopping all advertising', function () {
|
|
|
|
|
Event::fake();
|
|
|
|
|
app(AdStopAllService::class)->stopAll(123);
|
|
|
|
|
Event::assertDispatched(AdvertisingStopped::class, fn ($e) => $e->tenantId === 123);
|
|
|
|
|
});
|