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

@@ -10,6 +10,7 @@ use App\Models\Event;
use App\Models\FestivalSection;
use App\Models\Organisation;
use App\Models\Person;
use App\Models\RegistrationFormField;
use App\Models\TimeSlot;
use App\Models\User;
use Database\Seeders\RoleSeeder;
@@ -156,7 +157,7 @@ class VolunteerRegistrationTest extends TestCase
'tshirt_size' => 'XL',
'motivation' => 'Ik vind festivals geweldig.',
'section_preferences' => [
['section_name' => $this->section->name, 'priority' => 1],
['festival_section_id' => $this->section->id, 'priority' => 1],
],
]);
@@ -167,7 +168,12 @@ class VolunteerRegistrationTest extends TestCase
$this->assertEquals('XL', $customFields['tshirt_size']);
$this->assertEquals('Ik vind festivals geweldig.', $customFields['motivation']);
$this->assertNotEmpty($customFields['section_preferences']);
$this->assertDatabaseHas('person_section_preferences', [
'person_id' => $person->id,
'festival_section_id' => $this->section->id,
'priority' => 1,
]);
}
public function test_volunteer_can_register_with_date_of_birth(): void
@@ -428,4 +434,156 @@ class VolunteerRegistrationTest extends TestCase
$response->assertStatus(401);
}
// ─── Dynamic Field Values ──────────────────────────────────────────
public function test_volunteer_can_register_with_field_values(): void
{
$selectField = RegistrationFormField::factory()->selectField()->create([
'event_id' => $this->event->id,
'sort_order' => 0,
]);
$textField = RegistrationFormField::factory()->textareaField()->create([
'event_id' => $this->event->id,
'sort_order' => 1,
]);
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
'first_name' => 'Noor',
'last_name' => 'Janssen',
'email' => 'noor@voorbeeld.nl',
'field_values' => [
$selectField->slug => 'L',
$textField->slug => 'Ik ben een ervaren vrijwilliger',
],
]);
$response->assertStatus(201);
$person = Person::where('email', 'noor@voorbeeld.nl')->first();
$this->assertDatabaseHas('person_field_values', [
'person_id' => $person->id,
'registration_form_field_id' => $selectField->id,
'value' => 'L',
]);
$this->assertDatabaseHas('person_field_values', [
'person_id' => $person->id,
'registration_form_field_id' => $textField->id,
'value' => 'Ik ben een ervaren vrijwilliger',
]);
}
public function test_volunteer_can_register_with_section_preferences(): void
{
$section1 = FestivalSection::factory()->create([
'event_id' => $this->event->id,
'name' => 'Hoofdpodium Bar',
]);
$section2 = FestivalSection::factory()->create([
'event_id' => $this->event->id,
'name' => 'EHBO Post',
]);
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
'first_name' => 'Rick',
'last_name' => 'Peters',
'email' => 'rick@voorbeeld.nl',
'section_preferences' => [
['festival_section_id' => $section1->id, 'priority' => 1],
['festival_section_id' => $section2->id, 'priority' => 2],
],
]);
$response->assertStatus(201);
$person = Person::where('email', 'rick@voorbeeld.nl')->first();
$this->assertDatabaseHas('person_section_preferences', [
'person_id' => $person->id,
'festival_section_id' => $section1->id,
'priority' => 1,
]);
$this->assertDatabaseHas('person_section_preferences', [
'person_id' => $person->id,
'festival_section_id' => $section2->id,
'priority' => 2,
]);
}
public function test_volunteer_can_register_with_multiselect_field_values(): void
{
$multiselectField = RegistrationFormField::factory()->multiselectField()->create([
'event_id' => $this->event->id,
]);
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
'first_name' => 'Femke',
'last_name' => 'de Jong',
'email' => 'femke@voorbeeld.nl',
'field_values' => [
$multiselectField->slug => ['Vegetarisch', 'Glutenvrij'],
],
]);
$response->assertStatus(201);
$person = Person::where('email', 'femke@voorbeeld.nl')->first();
$this->assertDatabaseHas('person_field_values', [
'person_id' => $person->id,
'registration_form_field_id' => $multiselectField->id,
]);
$value = $person->fieldValues()
->where('registration_form_field_id', $multiselectField->id)
->first();
$this->assertEquals(['Vegetarisch', 'Glutenvrij'], $value->selected_options);
}
public function test_portal_me_includes_field_values_and_section_preferences(): void
{
$user = User::factory()->create(['first_name' => 'Lotte', 'last_name' => 'Vos']);
$this->organisation->users()->attach($user, ['role' => 'org_member']);
$person = Person::factory()->create([
'event_id' => $this->event->id,
'crowd_type_id' => $this->volunteerCrowdType->id,
'user_id' => $user->id,
'email' => $user->email,
]);
$field = RegistrationFormField::factory()->selectField()->create([
'event_id' => $this->event->id,
]);
\App\Models\PersonFieldValue::create([
'person_id' => $person->id,
'registration_form_field_id' => $field->id,
'value' => 'M',
]);
\App\Models\PersonSectionPreference::create([
'person_id' => $person->id,
'festival_section_id' => $this->section->id,
'priority' => 1,
]);
Sanctum::actingAs($user);
$response = $this->getJson("/api/v1/portal/me?event_id={$this->event->id}");
$response->assertStatus(200)
->assertJsonCount(1, 'data.field_values')
->assertJsonPath('data.field_values.0.field_slug', $field->slug)
->assertJsonPath('data.field_values.0.value', 'M')
->assertJsonCount(1, 'data.section_preferences')
->assertJsonPath('data.section_preferences.0.festival_section_id', $this->section->id)
->assertJsonPath('data.section_preferences.0.priority', 1);
}
}