Initialer Laravel Commit für BetiX
This commit is contained in:
69
tests/Feature/Gateway/AdminControllerTest.php
Normal file
69
tests/Feature/Gateway/AdminControllerTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Gateway;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminControllerTest extends TestCase
|
||||
{
|
||||
private function base(): string { return rtrim((string) config('services.backend.base'), '/'); }
|
||||
|
||||
private function adminUser()
|
||||
{
|
||||
return User::factory()->create([
|
||||
'username' => 'admin',
|
||||
'role' => 'Admin',
|
||||
'email_verified_at' => now()
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_index_renders_for_admin()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/admin/overview' => Http::response([
|
||||
'users' => [ ['id'=>1,'username'=>'u1','balance'=>0] ],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->adminUser(), 'web')->get('/admin/casino');
|
||||
$res->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_update_user_success_sets_flash()
|
||||
{
|
||||
$userToUpdate = User::factory()->create();
|
||||
|
||||
Http::fake([
|
||||
$this->base() . '/admin/users/' . $userToUpdate->id => Http::response(['message' => 'User aktualisiert.'], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->adminUser(), 'web')
|
||||
->post('/admin/users/' . $userToUpdate->id, [
|
||||
'username' => 'newname',
|
||||
'email' => 'new@example.com',
|
||||
'vip_level' => 2
|
||||
]);
|
||||
|
||||
$res->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function test_update_user_client_error_sets_error()
|
||||
{
|
||||
$userToUpdate = User::factory()->create();
|
||||
|
||||
Http::fake([
|
||||
$this->base() . '/admin/users/' . $userToUpdate->id => Http::response(['message' => 'Invalid'], 400),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->adminUser(), 'web')
|
||||
->post('/admin/users/' . $userToUpdate->id, [
|
||||
'username' => 'newname',
|
||||
'email' => 'invalid-email',
|
||||
'vip_level' => 999
|
||||
]);
|
||||
|
||||
$res->assertSessionHasErrors();
|
||||
}
|
||||
}
|
||||
59
tests/Feature/Gateway/AdminSupportAdminControllerTest.php
Normal file
59
tests/Feature/Gateway/AdminSupportAdminControllerTest.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 AdminSupportAdminControllerTest extends TestCase
|
||||
{
|
||||
private function base(): string { return rtrim((string) config('services.backend.base'), '/'); }
|
||||
|
||||
private function adminUser()
|
||||
{
|
||||
if (class_exists(User::class) && method_exists(User::class, 'factory')) {
|
||||
return User::factory()->make(['id' => 1201, 'username' => 'admin', 'role' => 'Admin', 'email_verified_at' => now()]);
|
||||
}
|
||||
return new class { public $id=1201; public $username='admin'; public $role='Admin'; };
|
||||
}
|
||||
|
||||
public function test_index_renders_with_threads()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/admin/support' => Http::response([
|
||||
'enabled' => true,
|
||||
'threads' => [ ['id' => 't-1', 'status' => 'ai'] ],
|
||||
'ollama' => ['healthy' => true],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->adminUser())->get('/admin/support');
|
||||
$res->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_settings_success_sets_flash()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/admin/support/settings' => Http::response(['message' => 'OK'], 200),
|
||||
]);
|
||||
$res = $this->actingAs($this->adminUser())->post('/admin/support/settings', ['enabled' => true]);
|
||||
$res->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function test_reply_and_close_success_set_flash()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/admin/support/threads/t-1/message' => Http::response(['message' => 'Sent'], 200),
|
||||
$this->base() . '/admin/support/threads/t-1/close' => Http::response(['message' => 'Closed'], 200),
|
||||
]);
|
||||
|
||||
$this->actingAs($this->adminUser())
|
||||
->post('/admin/support/threads/t-1/message', ['text' => 'hi'])
|
||||
->assertSessionHas('success');
|
||||
|
||||
$this->actingAs($this->adminUser())
|
||||
->post('/admin/support/threads/t-1/close')
|
||||
->assertSessionHas('success');
|
||||
}
|
||||
}
|
||||
64
tests/Feature/Gateway/BonusesControllerTest.php
Normal file
64
tests/Feature/Gateway/BonusesControllerTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
||||
166
tests/Feature/Gateway/ChatControllerTest.php
Normal file
166
tests/Feature/Gateway/ChatControllerTest.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Gateway;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ChatControllerTest extends TestCase
|
||||
{
|
||||
// use RefreshDatabase; // Not required for proxy tests; uncomment if your auth relies on DB
|
||||
|
||||
private function base(): string
|
||||
{
|
||||
return rtrim((string) config('services.backend.base'), '/');
|
||||
}
|
||||
|
||||
private function actingUser()
|
||||
{
|
||||
return User::factory()->create(['username' => 'tester', 'email_verified_at' => now()]);
|
||||
}
|
||||
|
||||
public function test_get_chat_success_maps_messages_and_last_id()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/chat*' => Http::response([
|
||||
'messages' => [
|
||||
[
|
||||
'id' => 1,
|
||||
'user_id' => 12,
|
||||
'username' => 'dolo',
|
||||
'avatar' => 'http://a/1.png',
|
||||
'message' => 'hi',
|
||||
'reply_to_id' => null,
|
||||
'reactions' => ['🔥' => 2, '😂' => 1],
|
||||
'created_at' => now()->toIso8601String(),
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'user_id' => 13,
|
||||
'username' => 'sara',
|
||||
'avatar' => null,
|
||||
'message' => 'yo',
|
||||
'reply_to_id' => 1,
|
||||
'reactions' => [],
|
||||
'created_at' => now()->toIso8601String(),
|
||||
],
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')
|
||||
->get('/api/chat?limit=2');
|
||||
|
||||
$res->assertStatus(200)
|
||||
->assertJsonStructure([
|
||||
'data' => [
|
||||
['id', 'user_id', 'message', 'reply_to_id', 'created_at', 'user' => ['id', 'username', 'avatar_url'], 'reactions_agg'],
|
||||
],
|
||||
'last_id',
|
||||
]);
|
||||
|
||||
$json = $res->json();
|
||||
$this->assertEquals(2, $json['last_id']);
|
||||
$this->assertCount(2, $json['data']);
|
||||
$this->assertEquals('dolo', $json['data'][0]['user']['username']);
|
||||
}
|
||||
|
||||
public function test_get_chat_client_error_is_mapped()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/chat*' => Http::response(['message' => 'Invalid request'], 422),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')
|
||||
->get('/api/chat?limit=0');
|
||||
|
||||
$res->assertStatus(422)
|
||||
->assertJson([
|
||||
'error' => 'client_error',
|
||||
'message' => 'Invalid request',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_get_chat_server_error_maps_to_503()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/chat*' => Http::response(['message' => 'Upstream failed'], 500),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')
|
||||
->get('/api/chat?limit=50');
|
||||
|
||||
$res->assertStatus(503)
|
||||
->assertJson([
|
||||
'error' => 'service_unavailable',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_get_chat_timeout_maps_to_502()
|
||||
{
|
||||
Http::fake(function () {
|
||||
throw new \Illuminate\Http\Client\ConnectionException('timeout');
|
||||
});
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')
|
||||
->get('/api/chat?limit=50');
|
||||
|
||||
$res->assertStatus(502)
|
||||
->assertJson([
|
||||
'error' => 'bad_gateway',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_post_chat_success_returns_minimal_message()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/chat' => Http::response(['success' => true, 'message_id' => 123], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')
|
||||
->postJson('/api/chat', [
|
||||
'message' => 'Hello world',
|
||||
]);
|
||||
|
||||
$res->assertStatus(201)
|
||||
->assertJsonStructure(['data' => ['id', 'user_id', 'message', 'created_at', 'user' => ['id', 'username', 'avatar_url'], 'reactions_agg']]);
|
||||
|
||||
$this->assertEquals(123, data_get($res->json(), 'data.id'));
|
||||
$this->assertEquals('Hello world', data_get($res->json(), 'data.message'));
|
||||
}
|
||||
|
||||
public function test_post_chat_client_error_is_mapped()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/chat' => Http::response(['message' => 'Too long'], 422),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')
|
||||
->postJson('/api/chat', [
|
||||
'message' => str_repeat('x', 400),
|
||||
]);
|
||||
|
||||
$res->assertStatus(422)
|
||||
->assertJson([
|
||||
'error' => 'client_error',
|
||||
'message' => 'Too long',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_react_success_returns_200()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/chat/55/react' => Http::response(['ok' => true], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')
|
||||
->postJson('/api/chat/55/react', [ 'emoji' => '🔥' ]);
|
||||
|
||||
$res->assertStatus(200)
|
||||
->assertJson([
|
||||
'data' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
69
tests/Feature/Gateway/GuildActionControllerTest.php
Normal file
69
tests/Feature/Gateway/GuildActionControllerTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Gateway;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GuildActionControllerTest extends TestCase
|
||||
{
|
||||
private function base(): string
|
||||
{
|
||||
return rtrim((string) config('services.backend.base'), '/');
|
||||
}
|
||||
|
||||
private function actingUser()
|
||||
{
|
||||
if (class_exists(User::class) && method_exists(User::class, 'factory')) {
|
||||
return User::factory()->make(['id' => 802, 'username' => 'guilduser', 'email_verified_at' => now()]);
|
||||
}
|
||||
return new class {
|
||||
public $id = 802; public $username = 'guilduser'; public $role = 'User';
|
||||
};
|
||||
}
|
||||
|
||||
public function test_store_success()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/guilds' => Http::response([
|
||||
'data' => ['id' => 1, 'name' => 'NewGuild', 'invite_code' => 'ABCDEF']
|
||||
], 201),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser())
|
||||
->postJson('/guilds', [
|
||||
'name' => 'NewGuild',
|
||||
'tag' => 'ABCD',
|
||||
]);
|
||||
|
||||
$res->assertStatus(201)
|
||||
->assertJsonStructure(['data']);
|
||||
}
|
||||
|
||||
public function test_join_success()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/guilds/join' => Http::response(['success' => true], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser())
|
||||
->postJson('/guilds/join', [ 'invite_code' => 'AAAAAA' ]);
|
||||
|
||||
$res->assertStatus(200)
|
||||
->assertJson(['success' => true]);
|
||||
}
|
||||
|
||||
public function test_update_client_error_maps_to_client_error()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/guilds' => Http::response(['message' => 'Forbidden'], 403),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser())
|
||||
->patchJson('/guilds', [ 'name' => 'x' ]);
|
||||
|
||||
$res->assertStatus(403)
|
||||
->assertJson(['message' => 'Forbidden']);
|
||||
}
|
||||
}
|
||||
53
tests/Feature/Gateway/GuildControllerTest.php
Normal file
53
tests/Feature/Gateway/GuildControllerTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Gateway;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GuildControllerTest extends TestCase
|
||||
{
|
||||
private function base(): string
|
||||
{
|
||||
return rtrim((string) config('services.backend.base'), '/');
|
||||
}
|
||||
|
||||
private function actingUser()
|
||||
{
|
||||
if (class_exists(User::class) && method_exists(User::class, 'factory')) {
|
||||
return User::factory()->make(['id' => 801, 'username' => 'guilduser']);
|
||||
}
|
||||
return new class {
|
||||
public $id = 801; public $username = 'guilduser'; public $role = 'User';
|
||||
};
|
||||
}
|
||||
|
||||
public function test_index_renders_with_upstream_data()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/guilds' => Http::response([
|
||||
'guild' => ['id' => 1, 'name' => 'Testers'],
|
||||
'myRole' => 'member',
|
||||
'canManage' => false,
|
||||
'invite' => 'AAAAAA',
|
||||
'wager' => ['value' => 0],
|
||||
'topPlayers' => [],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser())->get('/guilds');
|
||||
$res->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_top_renders_list()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/guilds/top' => Http::response([
|
||||
'guilds' => [ ['id' => 1, 'name' => 'A'], ['id' => 2, 'name' => 'B'] ],
|
||||
], 200),
|
||||
]);
|
||||
$res = $this->actingAs($this->actingUser())->get('/guilds/top');
|
||||
$res->assertStatus(200);
|
||||
}
|
||||
}
|
||||
52
tests/Feature/Gateway/PromoControllerTest.php
Normal file
52
tests/Feature/Gateway/PromoControllerTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
||||
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']);
|
||||
}
|
||||
}
|
||||
116
tests/Feature/Gateway/SupportChatControllerTest.php
Normal file
116
tests/Feature/Gateway/SupportChatControllerTest.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Gateway;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SupportChatControllerTest extends TestCase
|
||||
{
|
||||
private function base(): string
|
||||
{
|
||||
return rtrim((string) config('services.backend.base'), '/');
|
||||
}
|
||||
|
||||
private function actingUser()
|
||||
{
|
||||
return User::factory()->create(['email_verified_at' => now()]);
|
||||
}
|
||||
|
||||
public function test_status_success_passthrough()
|
||||
{
|
||||
$user = $this->actingUser();
|
||||
Http::fake([
|
||||
$this->base() . '/support/status' => Http::response([
|
||||
'thread_id' => 't-1',
|
||||
'status' => 'ai',
|
||||
'messages' => [],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($user, 'web')->get('/api/support/status');
|
||||
|
||||
$res->assertStatus(200)
|
||||
->assertJson([
|
||||
'thread_id' => 't-1',
|
||||
'status' => 'ai',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_status_client_error_maps_to_client_error()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/support/status' => Http::response(['message' => 'Invalid'], 400),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/support/status');
|
||||
$res->assertStatus(400)
|
||||
->assertJson([
|
||||
'error' => 'client_error',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_status_server_error_maps_to_503()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/support/status' => Http::response(['message' => 'Oops'], 500),
|
||||
]);
|
||||
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/support/status');
|
||||
$res->assertStatus(503)
|
||||
->assertJson([
|
||||
'error' => 'service_unavailable',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_start_success()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/support/start' => Http::response([
|
||||
'thread_id' => 't-2',
|
||||
'status' => 'ai',
|
||||
], 200),
|
||||
]);
|
||||
$res = $this->actingAs($this->actingUser(), 'web')->postJson('/api/support/start', ['topic' => 'Konto']);
|
||||
$res->assertStatus(200)->assertJson([
|
||||
'thread_id' => 't-2',
|
||||
'status' => 'ai',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_message_success()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/support/message' => Http::response(['ok' => true], 200),
|
||||
]);
|
||||
$res = $this->actingAs($this->actingUser(), 'web')->postJson('/api/support/message', ['text' => 'Hallo']);
|
||||
$res->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_stop_handoff_close_success()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/support/stop' => Http::response(['success' => true], 200),
|
||||
$this->base() . '/support/handoff' => Http::response(['success' => true], 200),
|
||||
$this->base() . '/support/close' => Http::response(['success' => true], 200),
|
||||
]);
|
||||
|
||||
$this->actingAs($this->actingUser(), 'web')->postJson('/api/support/stop')->assertStatus(200);
|
||||
$this->actingAs($this->actingUser(), 'web')->postJson('/api/support/handoff')->assertStatus(200);
|
||||
$this->actingAs($this->actingUser(), 'web')->postJson('/api/support/close')->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_stream_failure_maps_to_503()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/support/stream' => Http::response(['message' => 'Down'], 500),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/support/stream');
|
||||
|
||||
$res->assertStatus(503)
|
||||
->assertJson([
|
||||
'error' => 'service_unavailable',
|
||||
]);
|
||||
}
|
||||
}
|
||||
55
tests/Feature/Gateway/UserBonusControllerTest.php
Normal file
55
tests/Feature/Gateway/UserBonusControllerTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Gateway;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserBonusControllerTest 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_index_success_normalizes_data()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/users/me/bonuses' => Http::response([
|
||||
'bonuses' => [
|
||||
[
|
||||
'id' => 9,
|
||||
'amount' => 12.5,
|
||||
'wager_required' => 100,
|
||||
'wager_progress' => 40,
|
||||
'expires_at' => now()->addDay()->toIso8601String(),
|
||||
'is_active' => true,
|
||||
'promo' => [ 'code' => 'WELCOME', 'wager_multiplier' => 40 ],
|
||||
],
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/user/bonuses');
|
||||
|
||||
$res->assertStatus(200)
|
||||
->assertJsonStructure(['data' => [[
|
||||
'id','amount','wager_required','wager_progress','expires_at','is_active','completed_at','promo'
|
||||
]]]);
|
||||
}
|
||||
|
||||
public function test_index_server_error_maps_to_503()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/users/me/bonuses' => Http::response(['message' => 'Down'], 500),
|
||||
]);
|
||||
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/user/bonuses');
|
||||
$res->assertStatus(503)->assertJson(['error' => 'service_unavailable']);
|
||||
}
|
||||
}
|
||||
89
tests/Feature/Gateway/VaultControllerTest.php
Normal file
89
tests/Feature/Gateway/VaultControllerTest.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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' ],
|
||||
]);
|
||||
}
|
||||
}
|
||||
50
tests/Feature/Gateway/VaultPinControllerTest.php
Normal file
50
tests/Feature/Gateway/VaultPinControllerTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Gateway;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class VaultPinControllerTest extends TestCase
|
||||
{
|
||||
private function base(): string
|
||||
{
|
||||
return rtrim((string) config('services.backend.base'), '/');
|
||||
}
|
||||
|
||||
private function actingUser()
|
||||
{
|
||||
return User::factory()->create([
|
||||
'username' => 'pinuser',
|
||||
'email_verified_at' => now(),
|
||||
'vault_pin_hash' => \Illuminate\Support\Facades\Hash::make('4321'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_set_success()
|
||||
{
|
||||
$user = $this->actingUser();
|
||||
// Da ein PIN gesetzt ist, müssen wir current_pin mitsenden
|
||||
$res = $this->actingAs($user, 'web')
|
||||
->postJson('/api/wallet/vault/pin/set', [ 'pin' => '1234', 'current_pin' => '4321' ]);
|
||||
|
||||
$res->assertStatus(200)
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_verify_success()
|
||||
{
|
||||
$user = $this->actingUser();
|
||||
// Der actingUser() hat PIN 4321
|
||||
$res = $this->actingAs($user, 'web')
|
||||
->postJson('/api/wallet/vault/pin/verify', [ 'pin' => '4321' ]);
|
||||
|
||||
$res->assertStatus(200)
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
44
tests/Feature/Gateway/VipControllerTest.php
Normal file
44
tests/Feature/Gateway/VipControllerTest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Gateway;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class VipControllerTest extends TestCase
|
||||
{
|
||||
private function base(): string { return rtrim((string) config('services.backend.base'), '/'); }
|
||||
|
||||
private function actingUser()
|
||||
{
|
||||
if (class_exists(User::class) && method_exists(User::class, 'factory')) {
|
||||
return User::factory()->make(['id' => 1001, 'username' => 'vipuser']);
|
||||
}
|
||||
return new class { public $id=1001; public $username='vipuser'; public $role='User'; };
|
||||
}
|
||||
|
||||
public function test_index_renders()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/vip-levels' => Http::response([
|
||||
'claimedLevels' => [1,2],
|
||||
'rewards' => [],
|
||||
'stats' => ['wagered' => 0],
|
||||
'vip_level' => 3,
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$res = $this->actingAs($this->actingUser())->get('/vip-levels');
|
||||
$res->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_claim_success_sets_flash()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/vip-levels/claim' => Http::response(['message' => 'Reward claimed successfully!'], 200),
|
||||
]);
|
||||
$res = $this->actingAs($this->actingUser())->post('/vip-levels/claim', ['level' => 2]);
|
||||
$res->assertSessionHas('success');
|
||||
}
|
||||
}
|
||||
32
tests/Feature/Gateway/WalletControllerTest.php
Normal file
32
tests/Feature/Gateway/WalletControllerTest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Gateway;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WalletControllerTest extends TestCase
|
||||
{
|
||||
private function base(): string { return rtrim((string) config('services.backend.base'), '/'); }
|
||||
|
||||
private function actingUser()
|
||||
{
|
||||
if (class_exists(User::class) && method_exists(User::class, 'factory')) {
|
||||
return User::factory()->make(['id' => 901, 'username' => 'walletuser']);
|
||||
}
|
||||
return new class { public $id=901; public $username='walletuser'; public $role='User'; };
|
||||
}
|
||||
|
||||
public function test_index_renders_with_upstream_data()
|
||||
{
|
||||
Http::fake([
|
||||
$this->base() . '/wallet' => Http::response([
|
||||
'wallets' => [ ['code' => 'USD', 'balance' => 10] ],
|
||||
'btxBalance' => 10,
|
||||
], 200),
|
||||
]);
|
||||
$res = $this->actingAs($this->actingUser())->get('/wallet');
|
||||
$res->assertStatus(200);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user