65 lines
2.1 KiB
PHP
65 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Gateway;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class BonusesControllerTest extends TestCase
|
|
{
|
|
private function base(): string
|
|
{
|
|
return rtrim((string) config('services.backend.base'), '/');
|
|
}
|
|
|
|
private function actingUser()
|
|
{
|
|
return User::factory()->create(['username' => 'bonususer', 'email_verified_at' => now()]);
|
|
}
|
|
|
|
public function test_app_index_success_normalizes_fields()
|
|
{
|
|
Http::fake([
|
|
$this->base() . '/bonuses/app*' => Http::response([
|
|
'available' => [
|
|
[
|
|
'id' => 1,
|
|
'title' => 'Welcome Bonus',
|
|
'type' => 'deposit_match',
|
|
'amount_value' => 100,
|
|
'amount_unit' => '%',
|
|
'min_deposit' => 10,
|
|
'max_amount' => 200,
|
|
'currency' => 'USD',
|
|
'code' => 'WELCOME100',
|
|
'starts_at' => now()->subDay()->toIso8601String(),
|
|
'expires_at' => now()->addDay()->toIso8601String(),
|
|
'description' => 'Match bonus',
|
|
],
|
|
],
|
|
'active' => [],
|
|
'history' => [],
|
|
'now' => now()->toIso8601String(),
|
|
], 200),
|
|
]);
|
|
|
|
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/bonuses/app');
|
|
|
|
$res->assertStatus(200)
|
|
->assertJsonStructure([
|
|
'available' => [ [ 'id','title','type','amount_value','amount_unit','currency','code','starts_at','expires_at','description' ] ],
|
|
'active', 'history', 'now',
|
|
]);
|
|
}
|
|
|
|
public function test_app_index_server_error_maps_to_503()
|
|
{
|
|
Http::fake([
|
|
$this->base() . '/bonuses/app*' => Http::response(['message' => 'Down'], 500),
|
|
]);
|
|
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/bonuses/app');
|
|
$res->assertStatus(503)->assertJson(['error' => 'service_unavailable']);
|
|
}
|
|
}
|