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:
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormFieldType;
|
||||
use App\Enums\FormBuilder\FormPurpose;
|
||||
use App\Enums\FormBuilder\FormSubmissionStatus;
|
||||
use App\Exceptions\FormBuilder\FieldValidationException;
|
||||
use App\Models\Event;
|
||||
use App\Models\FestivalSection;
|
||||
use App\Models\FormBuilder\FormField;
|
||||
use App\Models\FormBuilder\FormSchema;
|
||||
use App\Models\FormBuilder\FormSubmission;
|
||||
use App\Models\Organisation;
|
||||
use App\Services\FormBuilder\FormValueService;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Contract tests for SECTION_PRIORITY shape validation introduced in
|
||||
* FormValueService::upsertMany. Applies to both public and authenticated
|
||||
* paths; we drive the service directly with a public-style submission
|
||||
* (no actor) because the rules live below the request layer.
|
||||
*/
|
||||
final class SectionPriorityValueValidationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Organisation $org;
|
||||
|
||||
private Event $event;
|
||||
|
||||
/** @var array<int, FestivalSection> */
|
||||
private array $sections;
|
||||
|
||||
private FormSchema $schema;
|
||||
|
||||
private FormField $field;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed(RoleSeeder::class);
|
||||
|
||||
$this->org = Organisation::factory()->create();
|
||||
$this->event = Event::factory()->create([
|
||||
'organisation_id' => $this->org->id,
|
||||
'event_type' => 'event',
|
||||
]);
|
||||
|
||||
$this->sections = [];
|
||||
foreach (['Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot'] as $i => $name) {
|
||||
$this->sections[] = FestivalSection::factory()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'name' => $name,
|
||||
'sort_order' => $i + 1,
|
||||
'show_in_registration' => true,
|
||||
'type' => 'standard',
|
||||
]);
|
||||
}
|
||||
|
||||
$this->schema = FormSchema::factory()->create([
|
||||
'organisation_id' => $this->org->id,
|
||||
'owner_type' => 'event',
|
||||
'owner_id' => $this->event->id,
|
||||
'purpose' => FormPurpose::EVENT_REGISTRATION,
|
||||
]);
|
||||
|
||||
$this->field = FormField::factory()->create([
|
||||
'form_schema_id' => $this->schema->id,
|
||||
'field_type' => FormFieldType::SECTION_PRIORITY->value,
|
||||
'slug' => 'sectie_voorkeur',
|
||||
'is_portal_visible' => true,
|
||||
'is_admin_only' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
private function newDraftSubmission(): FormSubmission
|
||||
{
|
||||
return FormSubmission::create([
|
||||
'form_schema_id' => $this->schema->id,
|
||||
'subject_type' => null,
|
||||
'subject_id' => null,
|
||||
'status' => FormSubmissionStatus::DRAFT->value,
|
||||
'is_test' => false,
|
||||
'submitted_in_locale' => 'nl',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_happy_path_three_unique_entries_passes(): void
|
||||
{
|
||||
$submission = $this->newDraftSubmission();
|
||||
|
||||
app(FormValueService::class)->upsertMany(
|
||||
$submission,
|
||||
['sectie_voorkeur' => [
|
||||
['section_id' => $this->sections[0]->id, 'priority' => 1],
|
||||
['section_id' => $this->sections[1]->id, 'priority' => 2],
|
||||
['section_id' => $this->sections[2]->id, 'priority' => 3],
|
||||
]],
|
||||
null,
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('form_values', [
|
||||
'form_submission_id' => $submission->id,
|
||||
'form_field_id' => $this->field->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_duplicate_section_id_fails_validation(): void
|
||||
{
|
||||
$submission = $this->newDraftSubmission();
|
||||
|
||||
try {
|
||||
app(FormValueService::class)->upsertMany(
|
||||
$submission,
|
||||
['sectie_voorkeur' => [
|
||||
['section_id' => $this->sections[0]->id, 'priority' => 1],
|
||||
['section_id' => $this->sections[0]->id, 'priority' => 2],
|
||||
]],
|
||||
null,
|
||||
);
|
||||
$this->fail('Expected FieldValidationException for duplicate section_id.');
|
||||
} catch (FieldValidationException $e) {
|
||||
$this->assertSame('VALIDATION_FAILED', $e->publicCode);
|
||||
$this->assertArrayHasKey('sectie_voorkeur', $e->fieldErrors);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_duplicate_priority_fails_validation(): void
|
||||
{
|
||||
$submission = $this->newDraftSubmission();
|
||||
|
||||
try {
|
||||
app(FormValueService::class)->upsertMany(
|
||||
$submission,
|
||||
['sectie_voorkeur' => [
|
||||
['section_id' => $this->sections[0]->id, 'priority' => 1],
|
||||
['section_id' => $this->sections[1]->id, 'priority' => 1],
|
||||
]],
|
||||
null,
|
||||
);
|
||||
$this->fail('Expected FieldValidationException for duplicate priority.');
|
||||
} catch (FieldValidationException $e) {
|
||||
$this->assertSame('VALIDATION_FAILED', $e->publicCode);
|
||||
$this->assertArrayHasKey('sectie_voorkeur', $e->fieldErrors);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_out_of_range_priority_fails_validation(): void
|
||||
{
|
||||
$submission = $this->newDraftSubmission();
|
||||
|
||||
$this->expectException(FieldValidationException::class);
|
||||
app(FormValueService::class)->upsertMany(
|
||||
$submission,
|
||||
['sectie_voorkeur' => [
|
||||
['section_id' => $this->sections[0]->id, 'priority' => 6],
|
||||
]],
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
public function test_more_than_five_entries_fails_validation(): void
|
||||
{
|
||||
$submission = $this->newDraftSubmission();
|
||||
|
||||
$this->expectException(FieldValidationException::class);
|
||||
app(FormValueService::class)->upsertMany(
|
||||
$submission,
|
||||
['sectie_voorkeur' => [
|
||||
['section_id' => $this->sections[0]->id, 'priority' => 1],
|
||||
['section_id' => $this->sections[1]->id, 'priority' => 2],
|
||||
['section_id' => $this->sections[2]->id, 'priority' => 3],
|
||||
['section_id' => $this->sections[3]->id, 'priority' => 4],
|
||||
['section_id' => $this->sections[4]->id, 'priority' => 5],
|
||||
['section_id' => $this->sections[5]->id, 'priority' => 1],
|
||||
]],
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
public function test_section_id_outside_event_scope_fails_validation(): void
|
||||
{
|
||||
$submission = $this->newDraftSubmission();
|
||||
|
||||
$otherEvent = Event::factory()->create(['organisation_id' => $this->org->id]);
|
||||
$alienSection = FestivalSection::factory()->create([
|
||||
'event_id' => $otherEvent->id,
|
||||
'name' => 'Alien',
|
||||
'show_in_registration' => true,
|
||||
'type' => 'standard',
|
||||
]);
|
||||
|
||||
try {
|
||||
app(FormValueService::class)->upsertMany(
|
||||
$submission,
|
||||
['sectie_voorkeur' => [
|
||||
['section_id' => $alienSection->id, 'priority' => 1],
|
||||
]],
|
||||
null,
|
||||
);
|
||||
$this->fail('Expected FieldValidationException for out-of-scope section_id.');
|
||||
} catch (FieldValidationException $e) {
|
||||
$this->assertSame('VALIDATION_FAILED', $e->publicCode);
|
||||
$this->assertArrayHasKey('sectie_voorkeur', $e->fieldErrors);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_malformed_element_fails_validation(): void
|
||||
{
|
||||
$submission = $this->newDraftSubmission();
|
||||
|
||||
$this->expectException(FieldValidationException::class);
|
||||
app(FormValueService::class)->upsertMany(
|
||||
$submission,
|
||||
['sectie_voorkeur' => [
|
||||
'not-an-object',
|
||||
['section_id' => $this->sections[0]->id], // missing priority
|
||||
]],
|
||||
null,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user