Add support API validation rules
This commit is contained in:
@@ -5,6 +5,7 @@ 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;
|
||||
|
||||
@@ -34,4 +35,51 @@ class SupportApiTest extends TestCase
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user