You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
|
2 months ago
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Feature;
|
||
|
|
|
||
|
|
use App\Models\AdminUser;
|
||
|
|
use App\Models\Competition;
|
||
|
|
use App\Models\FormSchemaDefinition;
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
use Laravel\Sanctum\Sanctum;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
class SignupFormSchemaValidationTest extends TestCase
|
||
|
|
{
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
public function test_admin_cannot_save_signup_schema_with_unsupported_field_key(): void
|
||
|
|
{
|
||
|
|
Sanctum::actingAs(AdminUser::query()->create([
|
||
|
|
'username' => 'schema_admin',
|
||
|
|
'password_hash' => 'unused',
|
||
|
|
'name' => '管理员',
|
||
|
|
'status' => 'active',
|
||
|
|
]));
|
||
|
|
|
||
|
|
$competition = Competition::query()->create([
|
||
|
|
'slug' => 'xxf',
|
||
|
|
'name' => '测试赛',
|
||
|
|
'published' => true,
|
||
|
|
]);
|
||
|
|
|
||
|
|
$response = $this->postJson("/api/v1/admin/competitions/{$competition->id}/form-schemas", [
|
||
|
|
'purpose' => FormSchemaDefinition::PURPOSE_SIGNUP,
|
||
|
|
'name' => '含非法字段',
|
||
|
|
'schema_json' => [
|
||
|
|
[
|
||
|
|
'key' => 'field_x',
|
||
|
|
'type' => 'text',
|
||
|
|
'label' => '非法字段',
|
||
|
|
],
|
||
|
|
],
|
||
|
|
'is_published' => false,
|
||
|
|
]);
|
||
|
|
|
||
|
|
$response->assertStatus(422)
|
||
|
|
->assertJsonPath('errors.schema_json.0', fn ($msg) => is_string($msg) && str_contains($msg, 'field_x'));
|
||
|
|
}
|
||
|
|
}
|