Initialer Laravel Commit für BetiX
This commit is contained in:
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']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user