create(); AdWallet::create(['tenant_id' => $tenant->id, 'balance_rub' => '3000.00', 'frozen_rub' => '0.00']); $svc = app(AdWalletService::class); $svc->freeze($tenant->id, channel: 'yandex', sourceType: 'campaign', sourceId: 1, amountRub: '2500.00'); $wallet = AdWallet::where('tenant_id', $tenant->id)->first(); expect($wallet->frozen_rub)->toBe('2500.00'); // свободно 500 < 2500 → нельзя заморозить второй раз expect(fn () => $svc->freeze($tenant->id, 'yandex', 'campaign', 2, '2500.00')) ->toThrow(InsufficientBalanceException::class); }); it('releases a hold back to free balance', function () { $tenant = Tenant::factory()->create(); AdWallet::create(['tenant_id' => $tenant->id, 'balance_rub' => '3000.00', 'frozen_rub' => '0.00']); $svc = app(AdWalletService::class); $svc->freeze($tenant->id, 'yandex', 'campaign', 1, '2500.00'); $svc->release($tenant->id, 'yandex', 'campaign', 1); expect(AdWallet::where('tenant_id', $tenant->id)->first()->frozen_rub)->toBe('0.00'); });