Files
BetiX/tests/Feature/Gateway/PromoControllerTest.php
Dolo 0280278978
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
Initialer Laravel Commit für BetiX
2026-04-04 18:01:50 +02:00

53 lines
1.4 KiB
PHP

<?php
namespace Tests\Feature\Gateway;
use App\Models\User;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class PromoControllerTest extends TestCase
{
private function base(): string
{
return rtrim((string) config('services.backend.base'), '/');
}
private function actingUser()
{
return User::factory()->create(['username' => 'promouser', 'email_verified_at' => now()]);
}
public function test_apply_success_passes_message()
{
Http::fake([
$this->base() . '/promos/apply' => Http::response([
'success' => true,
'message' => 'Applied',
], 200),
]);
$res = $this->actingAs($this->actingUser(), 'web')
->postJson('/api/promos/apply', ['code' => 'WELCOME']);
$res->assertStatus(200)
->assertJson([
'success' => true,
'message' => 'Applied',
]);
}
public function test_apply_client_error_maps_to_client_error()
{
Http::fake([
$this->base() . '/promos/apply' => Http::response(['message' => 'Invalid code'], 400),
]);
$res = $this->actingAs($this->actingUser(), 'web')
->postJson('/api/promos/apply', ['code' => 'bad!']);
$res->assertStatus(400)
->assertJson(['error' => 'client_error']);
}
}