6832fba852
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
22 lines
896 B
PHP
22 lines
896 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\AdWallet;
|
|
use App\Models\Tenant;
|
|
use App\Services\Advertising\AdWalletService;
|
|
|
|
it('charges actual spend from balance idempotently', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
AdWallet::create(['tenant_id' => $tenant->id, 'balance_rub' => '3000.00', 'frozen_rub' => '2500.00']);
|
|
$svc = app(AdWalletService::class);
|
|
|
|
$svc->charge($tenant->id, channel: 'yandex', relatedType: 'campaign', relatedId: 1,
|
|
amountRub: '260.00', externalKey: 'yandex:1:2026-07-24');
|
|
// повтор того же события — не списывает второй раз
|
|
$svc->charge($tenant->id, 'yandex', 'campaign', 1, '260.00', 'yandex:1:2026-07-24');
|
|
|
|
$wallet = AdWallet::where('tenant_id', $tenant->id)->first();
|
|
expect($wallet->balance_rub)->toBe('2740.00'); // 3000 − 260, списано ОДИН раз
|
|
});
|