feat(api): extend registration endpoints with dynamic fields and section preferences

- PublicRegistrationData now returns registration_fields (portal-visible only),
  form toggles, and available_tags for tag_picker fields
- Volunteer registration accepts field_values and section_preferences with
  festival_section_id, processed via existing services
- PortalMe eager-loads fieldValues and sectionPreferences
- Section preferences now use the proper relational table instead of custom_fields JSON

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 23:44:26 +02:00
parent a9dcee0fc7
commit 73c8e6c466
6 changed files with 395 additions and 9 deletions

View File

@@ -8,6 +8,8 @@ use App\Models\CrowdType;
use App\Models\Event;
use App\Models\FestivalSection;
use App\Models\Organisation;
use App\Models\PersonTag;
use App\Models\RegistrationFormField;
use App\Models\TimeSlot;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
@@ -199,4 +201,132 @@ class PublicRegistrationDataTest extends TestCase
->assertJsonCount(1, 'data.sections')
->assertJsonPath('data.sections.0.name', 'Bar');
}
// ─── Registration Fields ───────────────────────────────────────────
public function test_registration_data_includes_registration_fields(): void
{
$event = Event::factory()->create([
'organisation_id' => $this->organisation->id,
'status' => 'registration_open',
'slug' => 'fields-event',
]);
$field = RegistrationFormField::factory()->selectField()->create([
'event_id' => $event->id,
'is_portal_visible' => true,
'is_admin_only' => false,
'sort_order' => 0,
]);
RegistrationFormField::factory()->textareaField()->create([
'event_id' => $event->id,
'is_portal_visible' => true,
'is_admin_only' => false,
'sort_order' => 1,
]);
$response = $this->getJson('/api/v1/public/events/fields-event/registration-data');
$response->assertOk()
->assertJsonCount(2, 'data.registration_fields')
->assertJsonPath('data.registration_fields.0.slug', $field->slug)
->assertJsonPath('data.registration_fields.0.field_type', 'select')
->assertJsonPath('data.registration_fields.0.is_required', false);
}
public function test_registration_data_excludes_admin_only_fields(): void
{
$event = Event::factory()->create([
'organisation_id' => $this->organisation->id,
'status' => 'registration_open',
'slug' => 'admin-fields-event',
]);
RegistrationFormField::factory()->create([
'event_id' => $event->id,
'label' => 'Public field',
'slug' => 'public-field',
'is_portal_visible' => true,
'is_admin_only' => false,
]);
// Admin-only field (should be excluded)
RegistrationFormField::factory()->create([
'event_id' => $event->id,
'label' => 'Admin only field',
'slug' => 'admin-only-field',
'is_portal_visible' => true,
'is_admin_only' => true,
]);
// Not portal visible (should be excluded)
RegistrationFormField::factory()->create([
'event_id' => $event->id,
'label' => 'Hidden field',
'slug' => 'hidden-field',
'is_portal_visible' => false,
'is_admin_only' => false,
]);
$response = $this->getJson('/api/v1/public/events/admin-fields-event/registration-data');
$response->assertOk()
->assertJsonCount(1, 'data.registration_fields')
->assertJsonPath('data.registration_fields.0.slug', 'public-field');
}
public function test_registration_data_includes_form_toggles(): void
{
$event = Event::factory()->create([
'organisation_id' => $this->organisation->id,
'status' => 'registration_open',
'slug' => 'toggles-event',
'registration_show_section_preferences' => true,
'registration_show_availability' => false,
]);
$response = $this->getJson('/api/v1/public/events/toggles-event/registration-data');
$response->assertOk()
->assertJsonPath('data.event.registration_show_section_preferences', true)
->assertJsonPath('data.event.registration_show_availability', false);
}
public function test_registration_data_includes_available_tags_for_tag_picker(): void
{
$event = Event::factory()->create([
'organisation_id' => $this->organisation->id,
'status' => 'registration_open',
'slug' => 'tags-event',
]);
$tag = PersonTag::factory()->create([
'organisation_id' => $this->organisation->id,
'name' => 'EHBO',
'category' => 'Certificaat',
'is_active' => true,
]);
PersonTag::factory()->create([
'organisation_id' => $this->organisation->id,
'name' => 'Barervaring',
'category' => 'Ervaring',
'is_active' => true,
]);
RegistrationFormField::factory()->tagPickerField()->create([
'event_id' => $event->id,
'tag_category' => 'Certificaat',
'is_portal_visible' => true,
'is_admin_only' => false,
]);
$response = $this->getJson('/api/v1/public/events/tags-event/registration-data');
$response->assertOk()
->assertJsonCount(1, 'data.registration_fields')
->assertJsonCount(1, 'data.registration_fields.0.available_tags')
->assertJsonPath('data.registration_fields.0.available_tags.0.name', 'EHBO');
}
}