feat(form-builder): per-schema default_crowd_type_id replaces silent oldest() heuristic (WS-6)
Session 2's PersonProvisioner picked CrowdType::oldest() for the org — silently wrong for multi-crowd_type orgs (Volunteer + Crew + Press are three distinct crowd_types in one org). Schemas now declare their target crowd_type explicitly via form_schemas.default_crowd_type_id. RequiresDefaultCrowdType publish guard prevents misconfigured event_registration schemas from publishing. PersonProvisioner: oldest() fallback removed entirely. Misconfiguration throws no_default_crowd_type at runtime; publish guard prevents it at config time. Migration uses a plain ulid() column without DB-level FK because SQLite's table-rebuild on ALTER ADD FOREIGN KEY cascade-deletes form_fields rows (form_fields.form_schema_id has cascadeOnDelete on form_schemas). Application-level integrity via FormSchema::defaultCrowdType() belongsTo + the publish guard + the runtime failsafe — three load-bearing checks, none of which require the DB-level constraint. Three pre-existing migration backfill tests bumped step counts +1 to account for the new migration sitting between WS-5c and WS-5d: FormFieldBindingMigrationTest (16→17, 14→15), FormFieldConfigBackfillAndDropTest (11→12), FormFieldValidationRuleBackfillTest (14→15), ConditionalLogicBackfillTest (5→6). Six event_registration test fixtures updated to set default_crowd_type_id to satisfy the new publish guard. FormBuilderDevSeeder.resolveDefaultCrowdTypeId() — VOLUNTEER → first-active → create-as-needed fallback chain; documented contract for future seeders. SCHEMA.md updated to v2.7. Refs: RFC-WS-6.md v1.1 §3 Q8 addendum (Task 4 of this session) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -67,12 +67,45 @@ final class EventRegistrationGuardsIntegrationTest extends TestCase
|
||||
$this->assertInstanceOf(EventRegistrationGuards::class, $provider);
|
||||
}
|
||||
|
||||
public function test_requires_default_crowd_type_is_in_guard_list(): void
|
||||
{
|
||||
$provider = $this->app->make(EventRegistrationGuards::class);
|
||||
$codes = array_map(
|
||||
static fn (\App\FormBuilder\Publishing\PublishGuard $g): string => $g->code(),
|
||||
$provider->publishGuards(),
|
||||
);
|
||||
$this->assertContains('requires_default_crowd_type', $codes);
|
||||
}
|
||||
|
||||
public function test_missing_default_crowd_type_fails_specific_guard(): void
|
||||
{
|
||||
$schema = $this->buildValidSchema();
|
||||
$schema->default_crowd_type_id = null;
|
||||
$schema->save();
|
||||
|
||||
$provider = $this->app->make(EventRegistrationGuards::class);
|
||||
$failedCodes = [];
|
||||
foreach ($provider->publishGuards() as $guard) {
|
||||
$result = $guard->evaluate($schema);
|
||||
if (! $result->passed) {
|
||||
$failedCodes[] = $guard->code();
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertContains('requires_default_crowd_type', $failedCodes);
|
||||
}
|
||||
|
||||
private function buildValidSchema(): FormSchema
|
||||
{
|
||||
$schema = FormSchema::factory()->create([
|
||||
'purpose' => FormPurpose::EVENT_REGISTRATION->value,
|
||||
'section_level_submit' => false,
|
||||
]);
|
||||
$crowdType = \App\Models\CrowdType::factory()->create([
|
||||
'organisation_id' => $schema->organisation_id,
|
||||
]);
|
||||
$schema->default_crowd_type_id = $crowdType->id;
|
||||
$schema->save();
|
||||
|
||||
$emailField = FormField::factory()->create([
|
||||
'form_schema_id' => $schema->id,
|
||||
|
||||
Reference in New Issue
Block a user