53 lines
1.4 KiB
PHP
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']);
|
|
}
|
|
}
|