Files
fotospiel-app/tests/Feature/Support/SupportApiTest.php
Codex Agent 981df2ee45
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
Add support API validation rules
2026-01-28 19:42:28 +01:00

86 lines
2.3 KiB
PHP

<?php
namespace Tests\Feature\Support;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class SupportApiTest extends TestCase
{
use RefreshDatabase;
public function test_support_resources_require_authentication(): void
{
$response = $this->getJson('/api/v1/support/tenants');
$response->assertStatus(401);
}
public function test_support_resources_allow_super_admin_tokens(): void
{
$user = User::factory()->create([
'role' => 'super_admin',
]);
Tenant::factory()->create();
Sanctum::actingAs($user, ['support-admin', 'support:read']);
$response = $this->getJson('/api/v1/support/tenants');
$response->assertOk()
->assertJsonStructure(['data', 'meta']);
}
public function test_support_resource_update_rejects_invalid_fields(): void
{
$user = User::factory()->create([
'role' => 'super_admin',
]);
$tenant = Tenant::factory()->create();
Sanctum::actingAs($user, ['support-admin', 'support:write']);
$response = $this->patchJson('/api/v1/support/tenants/'.$tenant->id, [
'data' => [
'name' => 'Unauthorized',
],
]);
$response->assertStatus(422)
->assertJsonPath('error.code', 'support_invalid_fields');
}
public function test_support_data_export_create_sets_user_and_dispatches_job(): void
{
$user = User::factory()->create([
'role' => 'super_admin',
]);
$tenant = Tenant::factory()->create();
Bus::fake();
Sanctum::actingAs($user, ['support-admin', 'support:ops']);
$response = $this->postJson('/api/v1/support/data-exports', [
'data' => [
'scope' => 'tenant',
'tenant_id' => $tenant->id,
'include_media' => true,
],
]);
$response->assertCreated()
->assertJsonPath('data.status', 'pending')
->assertJsonPath('data.user_id', $user->id)
->assertJsonPath('data.event_id', null);
Bus::assertDispatched(\App\Jobs\GenerateDataExport::class);
}
}