Initialer Laravel Commit für BetiX
This commit is contained in:
59
tests/Feature/Gateway/SocialControllerTest.php
Normal file
59
tests/Feature/Gateway/SocialControllerTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Gateway;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SocialControllerTest extends TestCase
|
||||
{
|
||||
private function base(): string
|
||||
{
|
||||
return rtrim((string) config('services.backend.base'), '/');
|
||||
}
|
||||
|
||||
private function actingUser($overrides = [])
|
||||
{
|
||||
return User::factory()->create(array_merge(['username' => 'socialuser', 'role' => 'User', 'email_verified_at' => now()], $overrides));
|
||||
}
|
||||
|
||||
public function test_search_success_normalizes_minimal_fields()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/users/search*' => Http::response([
|
||||
'users' => [
|
||||
['id' => 1, 'username' => 'do', 'avatar_url' => null, 'vip_level' => 3],
|
||||
['id' => 2, 'username' => 'dolo', 'avatar' => 'http://a/av.png'],
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/users/search?q=do');
|
||||
$res->assertStatus(200)
|
||||
->assertJsonStructure([
|
||||
[ 'id','username','avatar','vip_level' ]
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_profile_show_404_is_forwarded()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/users/unknown' => Http::response(['message' => 'User not found.'], 404),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')->get('/profile/unknown');
|
||||
$res->assertStatus(404);
|
||||
}
|
||||
|
||||
public function test_tip_client_error_is_mapped_to_errors_bag()
|
||||
{
|
||||
$user = $this->actingUser(['balance' => 0.0]); // Set balance to 0 to trigger local error
|
||||
$target = User::factory()->create();
|
||||
|
||||
$res = $this->actingAs($user, 'web')->post("/profile/{$target->id}/tip", [
|
||||
'currency' => 'USD', 'amount' => 1.0
|
||||
]);
|
||||
$res->assertSessionHasErrors(['amount']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user