create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); $field = FormField::factory()->create([ 'form_schema_id' => $schema->id, 'field_type' => FormFieldType::TEXT->value, ]); FormFieldValidationRule::factory()->forField($field) ->ofType(FormFieldValidationRuleType::MinLength, ['value' => 3])->create(); FormFieldValidationRule::factory()->forField($field) ->ofType(FormFieldValidationRuleType::MaxLength, ['value' => 40])->create(); $rendered = (new FormFieldResource($field->fresh()))->toArray(request()); $this->assertSame([ 'min_length' => 3, 'max_length' => 40, ], $rendered['validation_rules']); } public function test_form_field_resource_emits_null_when_no_rules(): void { $org = Organisation::factory()->create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); $field = FormField::factory()->create(['form_schema_id' => $schema->id]); $rendered = (new FormFieldResource($field->fresh()))->toArray(request()); $this->assertNull($rendered['validation_rules']); } public function test_form_field_library_resource_emits_canonical_shape(): void { $org = Organisation::factory()->create(); $library = FormFieldLibrary::factory()->create(['organisation_id' => $org->id]); FormFieldValidationRule::factory()->forLibrary($library) ->ofType(FormFieldValidationRuleType::AllowedMimeTypes, ['mime_types' => ['image/png', 'image/jpeg']])->create(); $rendered = (new FormFieldLibraryResource($library->fresh()))->toArray(request()); $this->assertSame([ 'allowed_mime_types' => ['image/png', 'image/jpeg'], ], $rendered['validation_rules']); } }