61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\AdWallet;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
|
|
/**
|
|
* GET /api/advertising/wallet — статус рекламного кошелька для баннера
|
|
* «пополните рекламный кошелёк» (Task 9, часть B).
|
|
*/
|
|
beforeEach(function () {
|
|
$this->tenant = Tenant::factory()->create();
|
|
$this->user = User::factory()->create(['tenant_id' => $this->tenant->id]);
|
|
$this->actingAs($this->user);
|
|
});
|
|
|
|
it('returns solvent=false and free_rub when balance does not cover frozen', function () {
|
|
AdWallet::create(['tenant_id' => $this->tenant->id, 'balance_rub' => '100.00', 'frozen_rub' => '2500.00']);
|
|
|
|
$response = $this->getJson('/api/advertising/wallet');
|
|
|
|
$response->assertOk()->assertJson([
|
|
'solvent' => false,
|
|
'balance_rub' => '100.00',
|
|
'frozen_rub' => '2500.00',
|
|
'free_rub' => '-2400.00',
|
|
]);
|
|
});
|
|
|
|
it('returns solvent=true and free_rub when balance covers frozen', function () {
|
|
AdWallet::create(['tenant_id' => $this->tenant->id, 'balance_rub' => '3000.00', 'frozen_rub' => '2500.00']);
|
|
|
|
$response = $this->getJson('/api/advertising/wallet');
|
|
|
|
$response->assertOk()->assertJson([
|
|
'solvent' => true,
|
|
'balance_rub' => '3000.00',
|
|
'frozen_rub' => '2500.00',
|
|
'free_rub' => '500.00',
|
|
]);
|
|
});
|
|
|
|
it('returns solvent=true and zero values when tenant has no wallet row yet', function () {
|
|
$response = $this->getJson('/api/advertising/wallet');
|
|
|
|
$response->assertOk()->assertJson([
|
|
'solvent' => true,
|
|
'balance_rub' => '0.00',
|
|
'frozen_rub' => '0.00',
|
|
'free_rub' => '0.00',
|
|
]);
|
|
});
|
|
|
|
it('returns 401 without auth', function () {
|
|
auth()->logout();
|
|
|
|
$this->getJson('/api/advertising/wallet')->assertStatus(401);
|
|
});
|