90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Gateway;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class VaultControllerTest extends TestCase
|
|
{
|
|
private function base(): string
|
|
{
|
|
return rtrim((string) config('services.backend.base'), '/');
|
|
}
|
|
|
|
private function actingUser()
|
|
{
|
|
return User::factory()->create([
|
|
'username' => 'vaultuser',
|
|
'email_verified_at' => now(),
|
|
'balance' => 11.0000,
|
|
'vault_balance' => 5.0000,
|
|
'vault_pin_hash' => \Illuminate\Support\Facades\Hash::make('1234'),
|
|
]);
|
|
}
|
|
|
|
public function test_show_success_maps_shape()
|
|
{
|
|
$user = $this->actingUser();
|
|
\App\Models\WalletTransfer::create([
|
|
'user_id' => $user->id,
|
|
'type' => 'deposit',
|
|
'amount' => 1.00,
|
|
'currency' => 'BTX',
|
|
'balance_before' => 12.00,
|
|
'balance_after' => 11.00,
|
|
'vault_before' => 4.00,
|
|
'vault_after' => 5.00,
|
|
]);
|
|
|
|
$res = $this->actingAs($user, 'web')->get('/api/wallet/vault');
|
|
$res->assertStatus(200)
|
|
->assertJson([
|
|
'balance' => '11.0000',
|
|
'vault_balance' => '5.0000',
|
|
'currency' => 'BTX',
|
|
])
|
|
->assertJsonStructure(['transfers', 'now']);
|
|
}
|
|
|
|
public function test_show_client_error_not_applicable_for_local_show()
|
|
{
|
|
// Der lokale VaultController->show() wirft keinen 400er Client-Fehler wie der Proxy
|
|
$this->assertTrue(true);
|
|
}
|
|
|
|
public function test_show_server_error_not_applicable_for_local_show()
|
|
{
|
|
// Der lokale VaultController->show() wirft keinen 503er Service-Fehler wie der Proxy
|
|
$this->assertTrue(true);
|
|
}
|
|
|
|
public function test_deposit_success_maps_balances()
|
|
{
|
|
$user = $this->actingUser();
|
|
|
|
$res = $this->actingAs($user, 'web')
|
|
->postJson('/api/wallet/vault/deposit', [ 'amount' => '1.0000', 'pin' => '1234' ]);
|
|
|
|
$res->assertStatus(201)
|
|
->assertJson([
|
|
'balances' => [ 'balance' => '10.0000', 'vault_balance' => '6.0000' ],
|
|
])
|
|
->assertJsonStructure(['data', 'balances']);
|
|
}
|
|
|
|
public function test_withdraw_success_maps_balances()
|
|
{
|
|
$user = $this->actingUser();
|
|
|
|
$res = $this->actingAs($user, 'web')
|
|
->postJson('/api/wallet/vault/withdraw', [ 'amount' => '1.0000', 'pin' => '1234' ]);
|
|
|
|
$res->assertStatus(201)
|
|
->assertJson([
|
|
'balances' => [ 'balance' => '12.0000', 'vault_balance' => '4.0000' ],
|
|
]);
|
|
}
|
|
}
|