test(forms): model tests, multi-tenancy, migration rollback (Phase 9)
UserProfileTest: belongs-to user, fillable/non-fillable boundaries, settings cast, lastSubmittedAt accessor (null + max from user-subject submissions only, ignoring drafts and is_test rows). FormSchemaTest: ULID PK, OrganisationScope filtering, polymorphic owner resolution to Event, purpose enum cast, hasMany fields/submissions, and logSchemaChange() actually creates an activity-log entry. FormFieldTest: belongs-to schema, field_type stored as string (not DB enum), binding/translations array casts, hasMany values, soft-delete preserves historical values, logFieldChange() creates an entry. FormSubmissionTest: belongs-to schema, polymorphic subject resolution, status enum cast, schema_snapshot array cast, hasMany values. FormValueTest: belongs-to submission/field, value array cast, hasMany options pivot rebuilt by observer, unique-pair DB constraint enforced. MultiTenancyTest: OrganisationScope correctly filters FormSchema / FormTemplate / FormFieldLibrary by route-resolved organisation. Pins the FormSchemaWebhook un-scoped behaviour explicitly so a future scope addition is an intentional decision, not an accident. MigrationRollbackTest (group 'slow'): full migrate:fresh → rollback 14 S1 steps → assert all 13 form-builder tables dropped + legacy tables intentionally retained → re-migrate and assert table list matches snapshot. Plus a separate test exercising the populate-user-profiles migration's down(). Supporting tweaks: - UserProfile::lastSubmittedAt accessor now returns Carbon|null instead of a raw timestamp string — testable, and matches Eloquent convention. - UserProfileFactory cooperates with UserObserver via newModel override (updates the auto-created row instead of inserting a duplicate). - AppServiceProvider morph map extended with all 12 form-builder model keys so logSchemaChange/logFieldChange resolve under enforceMorphMap. Suite: 945 passed (was 911), 2671 assertions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -34,7 +34,18 @@ use App\Models\User;
|
||||
use App\Models\UserInvitation;
|
||||
use App\Models\UserOrganisationTag;
|
||||
use App\Models\UserProfile;
|
||||
use App\Models\FormBuilder\FormField;
|
||||
use App\Models\FormBuilder\FormFieldLibrary;
|
||||
use App\Models\FormBuilder\FormSchema;
|
||||
use App\Models\FormBuilder\FormSchemaSection;
|
||||
use App\Models\FormBuilder\FormSchemaWebhook;
|
||||
use App\Models\FormBuilder\FormSubmission;
|
||||
use App\Models\FormBuilder\FormSubmissionDelegation;
|
||||
use App\Models\FormBuilder\FormSubmissionSectionStatus;
|
||||
use App\Models\FormBuilder\FormTemplate;
|
||||
use App\Models\FormBuilder\FormValue;
|
||||
use App\Models\FormBuilder\FormValueOption;
|
||||
use App\Models\FormBuilder\FormWebhookDelivery;
|
||||
use App\Models\VolunteerAvailability;
|
||||
use App\Observers\FormBuilder\FormValueObserver;
|
||||
use App\Observers\PersonObserver;
|
||||
@@ -95,6 +106,22 @@ class AppServiceProvider extends ServiceProvider
|
||||
'user_invitation' => UserInvitation::class,
|
||||
'user_organisation_tag' => UserOrganisationTag::class,
|
||||
'volunteer_availability' => VolunteerAvailability::class,
|
||||
|
||||
// Form-builder models — used as activity-log subjects via the
|
||||
// logSchemaChange / logFieldChange helpers, and (in S2+) as
|
||||
// polymorphic webhook payload subjects.
|
||||
'form_schema' => FormSchema::class,
|
||||
'form_schema_section' => FormSchemaSection::class,
|
||||
'form_field' => FormField::class,
|
||||
'form_field_library' => FormFieldLibrary::class,
|
||||
'form_submission' => FormSubmission::class,
|
||||
'form_submission_section_status' => FormSubmissionSectionStatus::class,
|
||||
'form_submission_delegation' => FormSubmissionDelegation::class,
|
||||
'form_value' => FormValue::class,
|
||||
'form_value_option' => FormValueOption::class,
|
||||
'form_template' => FormTemplate::class,
|
||||
'form_schema_webhook' => FormSchemaWebhook::class,
|
||||
'form_webhook_delivery' => FormWebhookDelivery::class,
|
||||
]);
|
||||
|
||||
Person::observe(PersonObserver::class);
|
||||
|
||||
Reference in New Issue
Block a user