feat(form-builder): extend public form backend for S3a PR 2

- Seed AVAILABILITY_PICKER and SECTION_PRIORITY demo fields in the
  event_registration showcase, and augment seedEchtFeesten with a
  parent-level VOLUNTEER time slot pair + a standard registration-
  visible section whose name duplicates a child section so the
  PublicFormController dedup path is exercised end-to-end.
- Validate SECTION_PRIORITY value shape in FormValueService: arrays of
  { section_id, priority } with unique section_ids + priorities in 1..5,
  max 5 entries, and section_ids scoped to the schema's event tree
  (parent + children). Error envelope is the standard VALIDATION_FAILED
  FieldValidationException shape so the portal renders errors next to
  the field.
- Enrich admin-facing FormSubmissionResource with a nested identity_match
  block mirroring the PublicFormSubmissionResource contract (status only;
  leaves room for future matched_user_id / confidence).
- Lock in the FORM-05 stub contract with 6 tests against the existing
  TriggerPersonIdentityMatchOnFormSubmit listener (no new listener was
  needed — the current one already writes 'pending' for public
  event_registration submissions per ARCH §31.1).
- 24 new backend assertions across seeder, shape validation, listener
  state matrix, and resource serialisation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-23 18:54:58 +02:00
parent d274284fd4
commit 1a87871e94
8 changed files with 957 additions and 0 deletions

View File

@@ -0,0 +1,258 @@
<?php
declare(strict_types=1);
namespace Tests\Feature\FormBuilder\Public;
use App\Enums\FormBuilder\FormFieldType;
use App\Models\Event;
use App\Models\FestivalSection;
use App\Models\FormBuilder\FormSchema;
use App\Models\Organisation;
use App\Models\TimeSlot;
use Database\Seeders\FormBuilderDevSeeder;
use Database\Seeders\RoleSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
/**
* Covers the S3a PR 2 seeder extensions end-to-end:
* - AVAILABILITY_PICKER + SECTION_PRIORITY demo fields are produced
* by FormBuilderDevSeeder::seedEventRegistrationShowcaseSchema
* - the festival mimicry (parent + children, VOLUNTEER slots on both,
* mixed registration visibility, cross_event negative case) flows
* through the public /time-slots and /sections endpoints
*/
final class PublicFormSeederTest extends TestCase
{
use RefreshDatabase;
private Organisation $org;
private Event $festival;
private Event $dag1;
private Event $dag2;
private FormSchema $schema;
protected function setUp(): void
{
parent::setUp();
$this->seed(RoleSeeder::class);
$this->org = Organisation::factory()->create();
// Festival parent + 2 children — mirrors DevSeeder::seedEchtFeesten
// so the controller's festival-aware merge is exercised.
$this->festival = Event::factory()->create([
'organisation_id' => $this->org->id,
'name' => 'Testfestival 2026',
'event_type' => 'festival',
'parent_event_id' => null,
'status' => 'registration_open',
]);
$this->dag1 = Event::factory()->create([
'organisation_id' => $this->org->id,
'parent_event_id' => $this->festival->id,
'name' => 'Dag 1',
'event_type' => 'event',
'status' => 'registration_open',
]);
$this->dag2 = Event::factory()->create([
'organisation_id' => $this->org->id,
'parent_event_id' => $this->festival->id,
'name' => 'Dag 2',
'event_type' => 'event',
'status' => 'registration_open',
]);
// Time slots — parent has 1 VOLUNTEER + 1 CREW (CREW must be
// filtered out); children have 3 VOLUNTEER slots across 2 dates.
TimeSlot::factory()->create([
'event_id' => $this->festival->id,
'name' => 'Vrijwilligers opbouw',
'person_type' => 'VOLUNTEER',
'date' => '2026-07-10',
'start_time' => '09:00:00',
'end_time' => '12:00:00',
]);
TimeSlot::factory()->create([
'event_id' => $this->festival->id,
'name' => 'Crew-only nacht',
'person_type' => 'CREW',
'date' => '2026-07-10',
'start_time' => '23:00:00',
'end_time' => '07:00:00',
]);
TimeSlot::factory()->create([
'event_id' => $this->dag1->id,
'name' => 'Dag 1 middag',
'person_type' => 'VOLUNTEER',
'date' => '2026-07-11',
'start_time' => '12:00:00',
'end_time' => '18:00:00',
]);
TimeSlot::factory()->create([
'event_id' => $this->dag1->id,
'name' => 'Dag 1 avond',
'person_type' => 'VOLUNTEER',
'date' => '2026-07-11',
'start_time' => '18:00:00',
'end_time' => '23:00:00',
]);
TimeSlot::factory()->create([
'event_id' => $this->dag2->id,
'name' => 'Dag 2 middag',
'person_type' => 'VOLUNTEER',
'date' => '2026-07-12',
'start_time' => '12:00:00',
'end_time' => '18:00:00',
]);
// Sections — positive (standard+registration) + duplicate name
// across parent/child + negative cases (cross_event, hidden).
FestivalSection::factory()->create([
'event_id' => $this->festival->id,
'name' => 'Bar',
'type' => 'standard',
'sort_order' => 1,
'show_in_registration' => true,
'registration_description' => 'Overkoepelende bar',
]);
FestivalSection::factory()->create([
'event_id' => $this->dag1->id,
'name' => 'Bar', // Duplicate name with parent
'type' => 'standard',
'sort_order' => 2,
'show_in_registration' => true,
]);
FestivalSection::factory()->create([
'event_id' => $this->dag1->id,
'name' => 'Hospitality',
'type' => 'standard',
'sort_order' => 3,
'show_in_registration' => true,
]);
FestivalSection::factory()->create([
'event_id' => $this->dag2->id,
'name' => 'Techniek',
'type' => 'standard',
'sort_order' => 4,
'show_in_registration' => true,
]);
// Negative: hidden from registration
FestivalSection::factory()->create([
'event_id' => $this->dag1->id,
'name' => 'Intern overleg',
'type' => 'standard',
'sort_order' => 10,
'show_in_registration' => false,
]);
// Negative: cross_event
FestivalSection::factory()->create([
'event_id' => $this->festival->id,
'name' => 'EHBO',
'type' => 'cross_event',
'sort_order' => 11,
'show_in_registration' => true,
]);
$this->schema = FormBuilderDevSeeder::seedEventRegistrationShowcaseSchema(
$this->org,
$this->festival,
);
}
public function test_showcase_schema_resolves_via_its_public_token(): void
{
$response = $this->getJson("/api/v1/public/forms/{$this->schema->public_token}");
$response->assertOk()
->assertJsonPath('data.id', $this->schema->id);
}
public function test_showcase_schema_contains_availability_picker_and_section_priority(): void
{
$response = $this->getJson("/api/v1/public/forms/{$this->schema->public_token}");
$response->assertOk();
$fields = collect($response->json('data.fields'))->keyBy('slug');
$this->assertArrayHasKey('beschikbaarheid', $fields);
$this->assertSame(FormFieldType::AVAILABILITY_PICKER->value, $fields['beschikbaarheid']['field_type']);
$this->assertSame('full', $fields['beschikbaarheid']['display_width']);
$this->assertArrayHasKey('sectie_voorkeur', $fields);
$this->assertSame(FormFieldType::SECTION_PRIORITY->value, $fields['sectie_voorkeur']['field_type']);
$this->assertSame('full', $fields['sectie_voorkeur']['display_width']);
$this->assertSame(['max_priorities' => 3], $fields['sectie_voorkeur']['validation_rules']);
}
public function test_time_slots_endpoint_returns_at_least_four_volunteer_rows(): void
{
$response = $this->getJson("/api/v1/public/forms/{$this->schema->public_token}/time-slots");
$response->assertOk();
$rows = $response->json('data');
$this->assertIsArray($rows);
$this->assertGreaterThanOrEqual(4, count($rows));
}
public function test_time_slots_endpoint_surfaces_both_parent_and_child_events(): void
{
$response = $this->getJson("/api/v1/public/forms/{$this->schema->public_token}/time-slots");
$response->assertOk();
$eventNames = collect($response->json('data'))->pluck('event_name')->unique()->values()->all();
$this->assertContains('Testfestival 2026', $eventNames);
$this->assertTrue(in_array('Dag 1', $eventNames, true) || in_array('Dag 2', $eventNames, true));
}
public function test_time_slots_endpoint_filters_out_non_volunteer_rows(): void
{
$response = $this->getJson("/api/v1/public/forms/{$this->schema->public_token}/time-slots");
$response->assertOk();
$names = collect($response->json('data'))->pluck('name')->all();
$this->assertNotContains('Crew-only nacht', $names);
}
public function test_sections_endpoint_returns_only_standard_registration_visible_rows(): void
{
$response = $this->getJson("/api/v1/public/forms/{$this->schema->public_token}/sections");
$response->assertOk();
$names = collect($response->json('data'))->pluck('name')->all();
$this->assertContains('Bar', $names);
$this->assertContains('Hospitality', $names);
$this->assertContains('Techniek', $names);
}
public function test_sections_endpoint_excludes_hidden_and_cross_event_rows(): void
{
$response = $this->getJson("/api/v1/public/forms/{$this->schema->public_token}/sections");
$response->assertOk();
$names = collect($response->json('data'))->pluck('name')->all();
$this->assertNotContains('Intern overleg', $names);
$this->assertNotContains('EHBO', $names);
}
public function test_sections_endpoint_dedupes_duplicate_names_across_parent_and_child(): void
{
$response = $this->getJson("/api/v1/public/forms/{$this->schema->public_token}/sections");
$response->assertOk();
$names = collect($response->json('data'))->pluck('name')->all();
$barCount = collect($names)->filter(fn ($n) => $n === 'Bar')->count();
$this->assertSame(1, $barCount, 'Duplicate "Bar" across parent and child should be deduped.');
}
}