test(form-builder): cover purpose registry and morph-map alignment
- PurposeRegistryTest: all seven purposes load with expected shape; `get()` throws PurposeNotFoundException on unknown slug; `allSubjectTypes()` returns exactly [artist, company, person, user]; `publicAccessibleSlugs()` is only `[event_registration]`. - PurposeSchemaLifecycleTest: data-provider-driven create → publish for all seven purposes; negative tests for event_registration (three missing bindings) and supplier_intake (company.name missing); partial binding test reports only the missing subset. - CustomPurposeEscapeRemovedTest: column gone, config file gone, FormPurpose::CUSTOM gone, store endpoint rejects `'custom'`, resource payload omits the field. - SubjectTypeRegistryConsolidationTest: submission validation accepts registry subject types, rejects everything else including the legacy `event` alias that used to be allowed. - MorphMapAlignmentTest: compile-time guard that every PurposeRegistry::allSubjectTypes() alias appears in the morph-map and in AppServiceProvider::PURPOSE_SUBJECT_FQCN. - FormPurposeTest rewritten to cover the seven v1.0 cases and the registry-delegation helpers (now extends Tests\TestCase for the container). - Public/listener tests swap the removed PUBLIC_RSVP / PUBLIC_COMPLAINT / FEEDBACK references for valid v1.0 purposes, preserving their negative-path assertions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -139,7 +139,7 @@ final class IdentityMatchOnSubmitTest extends TestCase
|
||||
{
|
||||
$otherSchema = FormSchema::factory()->create([
|
||||
'organisation_id' => $this->org->id,
|
||||
'purpose' => FormPurpose::FEEDBACK,
|
||||
'purpose' => FormPurpose::INCIDENT_REPORT,
|
||||
]);
|
||||
$submission = FormSubmission::factory()->create([
|
||||
'form_schema_id' => $otherSchema->id,
|
||||
|
||||
@@ -31,7 +31,7 @@ final class PublicFormDraftLifecycleTest extends TestCase
|
||||
$org = Organisation::factory()->create();
|
||||
$this->schema = FormSchema::factory()->create([
|
||||
'organisation_id' => $org->id,
|
||||
'purpose' => FormPurpose::PUBLIC_RSVP,
|
||||
'purpose' => FormPurpose::EVENT_REGISTRATION,
|
||||
'is_published' => true,
|
||||
'public_token' => (string) Str::ulid(),
|
||||
'version' => 1,
|
||||
|
||||
@@ -28,7 +28,7 @@ final class PublicFormSubmissionResourceTest extends TestCase
|
||||
$org = Organisation::factory()->create();
|
||||
$schema = FormSchema::factory()->create([
|
||||
'organisation_id' => $org->id,
|
||||
'purpose' => FormPurpose::PUBLIC_RSVP,
|
||||
'purpose' => FormPurpose::EVENT_REGISTRATION,
|
||||
'is_published' => true,
|
||||
'public_token' => (string) Str::ulid(),
|
||||
]);
|
||||
|
||||
@@ -31,7 +31,7 @@ final class PublicFormValidationTest extends TestCase
|
||||
$org = Organisation::factory()->create();
|
||||
$this->schema = FormSchema::factory()->create([
|
||||
'organisation_id' => $org->id,
|
||||
'purpose' => FormPurpose::PUBLIC_RSVP,
|
||||
'purpose' => FormPurpose::EVENT_REGISTRATION,
|
||||
'is_published' => true,
|
||||
'public_token' => (string) Str::ulid(),
|
||||
]);
|
||||
|
||||
@@ -79,7 +79,7 @@ final class FormSchemaApiTest extends TestCase
|
||||
|
||||
$this->postJson("/api/v1/organisations/{$this->org->id}/forms/schemas", [
|
||||
'name' => 'Blocked',
|
||||
'purpose' => FormPurpose::FEEDBACK->value,
|
||||
'purpose' => FormPurpose::INCIDENT_REPORT->value,
|
||||
])->assertStatus(403);
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ final class TriggerPersonIdentityMatchOnFormSubmitTest extends TestCase
|
||||
{
|
||||
$otherSchema = FormSchema::factory()->create([
|
||||
'organisation_id' => $this->org->id,
|
||||
'purpose' => FormPurpose::PUBLIC_COMPLAINT,
|
||||
'purpose' => FormPurpose::INCIDENT_REPORT,
|
||||
'owner_type' => 'event',
|
||||
'owner_id' => $this->event->id,
|
||||
]);
|
||||
|
||||
60
api/tests/Feature/FormBuilder/MorphMapAlignmentTest.php
Normal file
60
api/tests/Feature/FormBuilder/MorphMapAlignmentTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder;
|
||||
|
||||
use App\FormBuilder\Purposes\PurposeRegistry;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Compile-time guard: PurposeRegistry subject types MUST be registered in
|
||||
* the morph-map; otherwise polymorphic writes to form_submissions would
|
||||
* blow up at runtime. See ARCH-CONSOLIDATION-ADDENDUM-2026-04-24.md Q6.
|
||||
*
|
||||
* The reverse direction is NOT asserted end-to-end: the morph-map also
|
||||
* contains non-purpose domain types (owner_types, activity-log subjects)
|
||||
* and framework entries — those are intentionally broader.
|
||||
*/
|
||||
final class MorphMapAlignmentTest extends TestCase
|
||||
{
|
||||
public function test_every_purpose_subject_type_is_in_morph_map(): void
|
||||
{
|
||||
$registry = $this->app->make(PurposeRegistry::class);
|
||||
$morphMap = Relation::morphMap();
|
||||
|
||||
foreach ($registry->allSubjectTypes() as $alias) {
|
||||
$this->assertArrayHasKey(
|
||||
$alias,
|
||||
$morphMap,
|
||||
"Purpose subject_type '{$alias}' is declared in PurposeRegistry but "
|
||||
."missing from Relation::morphMap() in AppServiceProvider. "
|
||||
."Add it to the 'Domain subject types' block."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_domain_subject_types_block_matches_registry_exactly(): void
|
||||
{
|
||||
$registry = $this->app->make(PurposeRegistry::class);
|
||||
$registryAliases = $registry->allSubjectTypes();
|
||||
|
||||
// AppServiceProvider::PURPOSE_SUBJECT_FQCN is the single source of
|
||||
// truth for which aliases the domain-subject-types block can emit.
|
||||
// If the registry adds an alias not present in that lookup, boot()
|
||||
// would throw — but we also assert it here for fast feedback.
|
||||
$reflection = new \ReflectionClass(\App\Providers\AppServiceProvider::class);
|
||||
$lookup = $reflection->getConstant('PURPOSE_SUBJECT_FQCN');
|
||||
$this->assertIsArray($lookup);
|
||||
|
||||
foreach ($registryAliases as $alias) {
|
||||
$this->assertArrayHasKey(
|
||||
$alias,
|
||||
$lookup,
|
||||
"Purpose subject_type '{$alias}' has no FQCN in "
|
||||
."AppServiceProvider::PURPOSE_SUBJECT_FQCN. Register it there."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ final class PublicFormApiTest extends TestCase
|
||||
$this->org = Organisation::factory()->create();
|
||||
$this->schema = FormSchema::factory()->create([
|
||||
'organisation_id' => $this->org->id,
|
||||
'purpose' => FormPurpose::PUBLIC_RSVP,
|
||||
'purpose' => FormPurpose::EVENT_REGISTRATION,
|
||||
'is_published' => true,
|
||||
'public_token' => (string) Str::ulid(),
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder\Purposes;
|
||||
|
||||
use App\Enums\FormBuilder\FormPurpose;
|
||||
use App\Models\FormBuilder\FormSchema;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Regression guard for the WS-2 removal of the `custom` purpose escape.
|
||||
* Covers both the DB column, the resource payload, and the request
|
||||
* validation pipeline.
|
||||
*/
|
||||
final class CustomPurposeEscapeRemovedTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_form_schemas_has_no_custom_purpose_slug_column(): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
Schema::hasColumn('form_schemas', 'custom_purpose_slug'),
|
||||
'form_schemas.custom_purpose_slug must be dropped by migration 2026_04_24_100001.',
|
||||
);
|
||||
}
|
||||
|
||||
public function test_form_subjects_config_file_is_deleted(): void
|
||||
{
|
||||
$this->assertFileDoesNotExist(
|
||||
base_path('config/form_subjects.php'),
|
||||
'config/form_subjects.php must be removed in WS-2 (Q6 consolidation).',
|
||||
);
|
||||
}
|
||||
|
||||
public function test_form_purpose_enum_has_no_custom_case(): void
|
||||
{
|
||||
foreach (FormPurpose::cases() as $case) {
|
||||
$this->assertNotSame('custom', $case->value);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_store_endpoint_rejects_custom_purpose_value(): void
|
||||
{
|
||||
$this->seed(RoleSeeder::class);
|
||||
$org = Organisation::factory()->create();
|
||||
$admin = User::factory()->create();
|
||||
$org->users()->attach($admin, ['role' => 'org_admin']);
|
||||
$admin->assignRole('org_admin');
|
||||
setPermissionsTeamId($org->id);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$this->postJson("/api/v1/organisations/{$org->id}/forms/schemas", [
|
||||
'name' => 'X',
|
||||
'purpose' => 'custom',
|
||||
])->assertStatus(422);
|
||||
}
|
||||
|
||||
public function test_schema_response_omits_custom_purpose_slug(): void
|
||||
{
|
||||
$this->seed(RoleSeeder::class);
|
||||
$org = Organisation::factory()->create();
|
||||
$admin = User::factory()->create();
|
||||
$org->users()->attach($admin, ['role' => 'org_admin']);
|
||||
$admin->assignRole('org_admin');
|
||||
setPermissionsTeamId($org->id);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$schema = FormSchema::factory()->create([
|
||||
'organisation_id' => $org->id,
|
||||
'purpose' => FormPurpose::INCIDENT_REPORT,
|
||||
]);
|
||||
|
||||
$response = $this->getJson("/api/v1/organisations/{$org->id}/forms/schemas/{$schema->id}")
|
||||
->assertOk();
|
||||
|
||||
$this->assertArrayNotHasKey('custom_purpose_slug', $response->json('data'));
|
||||
}
|
||||
}
|
||||
113
api/tests/Feature/FormBuilder/Purposes/PurposeRegistryTest.php
Normal file
113
api/tests/Feature/FormBuilder/Purposes/PurposeRegistryTest.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder\Purposes;
|
||||
|
||||
use App\Enums\FormBuilder\FormSubmissionMode;
|
||||
use App\FormBuilder\Purposes\Exceptions\PurposeNotFoundException;
|
||||
use App\FormBuilder\Purposes\PurposeRegistry;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class PurposeRegistryTest extends TestCase
|
||||
{
|
||||
private function registry(): PurposeRegistry
|
||||
{
|
||||
return $this->app->make(PurposeRegistry::class);
|
||||
}
|
||||
|
||||
public function test_loads_all_seven_purposes_from_config(): void
|
||||
{
|
||||
$registry = $this->registry();
|
||||
$all = $registry->all();
|
||||
|
||||
$this->assertCount(7, $all);
|
||||
$this->assertSame(
|
||||
[
|
||||
'event_registration',
|
||||
'artist_advance',
|
||||
'supplier_intake',
|
||||
'post_event_evaluation',
|
||||
'incident_report',
|
||||
'signature_contract',
|
||||
'user_profile',
|
||||
],
|
||||
array_keys($all),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_event_registration_definition_is_complete(): void
|
||||
{
|
||||
$def = $this->registry()->get('event_registration');
|
||||
|
||||
$this->assertSame('event_registration', $def->slug);
|
||||
$this->assertSame('Aanmelding vrijwilligers/crew', $def->label);
|
||||
$this->assertSame('person', $def->subjectType);
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, $def->defaultSubmissionMode);
|
||||
$this->assertTrue($def->allowsPublicAccess);
|
||||
$this->assertSame(
|
||||
['person.email', 'person.first_name', 'person.last_name'],
|
||||
$def->requiredBindings,
|
||||
);
|
||||
}
|
||||
|
||||
public function test_artist_advance_uses_draft_single(): void
|
||||
{
|
||||
$def = $this->registry()->get('artist_advance');
|
||||
|
||||
$this->assertSame('artist', $def->subjectType);
|
||||
$this->assertSame(FormSubmissionMode::DRAFT_SINGLE, $def->defaultSubmissionMode);
|
||||
$this->assertFalse($def->allowsPublicAccess);
|
||||
$this->assertSame([], $def->requiredBindings);
|
||||
}
|
||||
|
||||
public function test_supplier_intake_requires_company_name(): void
|
||||
{
|
||||
$def = $this->registry()->get('supplier_intake');
|
||||
|
||||
$this->assertSame('company', $def->subjectType);
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, $def->defaultSubmissionMode);
|
||||
$this->assertFalse($def->allowsPublicAccess);
|
||||
$this->assertSame(['company.name'], $def->requiredBindings);
|
||||
}
|
||||
|
||||
public function test_get_throws_on_unknown_slug(): void
|
||||
{
|
||||
$this->expectException(PurposeNotFoundException::class);
|
||||
|
||||
$this->registry()->get('does_not_exist');
|
||||
}
|
||||
|
||||
public function test_has_returns_false_for_unknown_slug(): void
|
||||
{
|
||||
$this->assertFalse($this->registry()->has('does_not_exist'));
|
||||
$this->assertTrue($this->registry()->has('event_registration'));
|
||||
}
|
||||
|
||||
public function test_all_subject_types_returns_four_sorted_aliases(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
['artist', 'company', 'person', 'user'],
|
||||
$this->registry()->allSubjectTypes(),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_public_accessible_slugs_is_only_event_registration(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
['event_registration'],
|
||||
$this->registry()->publicAccessibleSlugs(),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_result_is_memoised_on_instance(): void
|
||||
{
|
||||
$registry = $this->registry();
|
||||
$first = $registry->all();
|
||||
$second = $registry->all();
|
||||
|
||||
$this->assertSame($first, $second);
|
||||
// Same PurposeDefinition instance per slug across calls.
|
||||
$this->assertSame($first['event_registration'], $second['event_registration']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder\Purposes;
|
||||
|
||||
use App\Enums\FormBuilder\FormFieldType;
|
||||
use App\Enums\FormBuilder\FormPurpose;
|
||||
use App\Exceptions\FormBuilder\PurposeRequirementsNotMetException;
|
||||
use App\Models\FormBuilder\FormField;
|
||||
use App\Models\FormBuilder\FormSchema;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\User;
|
||||
use App\Services\FormBuilder\FormSchemaService;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Smoke-tests for the seven v1.0 purposes. Each purpose must support
|
||||
* create → publish end-to-end (with required bindings present). The two
|
||||
* purposes that declare required bindings (`event_registration`,
|
||||
* `supplier_intake`) also have negative tests that assert the pre-publish
|
||||
* guard fires.
|
||||
*/
|
||||
final class PurposeSchemaLifecycleTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Organisation $org;
|
||||
|
||||
private User $actor;
|
||||
|
||||
private FormSchemaService $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed(RoleSeeder::class);
|
||||
|
||||
$this->org = Organisation::factory()->create();
|
||||
$this->actor = User::factory()->create();
|
||||
$this->org->users()->attach($this->actor, ['role' => 'org_admin']);
|
||||
$this->actor->assignRole('org_admin');
|
||||
setPermissionsTeamId($this->org->id);
|
||||
|
||||
$this->service = $this->app->make(FormSchemaService::class);
|
||||
}
|
||||
|
||||
/** @return iterable<string, array{FormPurpose}> */
|
||||
public static function purposeProvider(): iterable
|
||||
{
|
||||
foreach (FormPurpose::cases() as $case) {
|
||||
yield $case->value => [$case];
|
||||
}
|
||||
}
|
||||
|
||||
/** @dataProvider purposeProvider */
|
||||
public function test_create_and_publish_succeeds_for_purpose(FormPurpose $purpose): void
|
||||
{
|
||||
$schema = $this->service->create(
|
||||
$this->org,
|
||||
[
|
||||
'name' => 'Schema '.$purpose->value,
|
||||
'purpose' => $purpose->value,
|
||||
],
|
||||
$this->actor,
|
||||
);
|
||||
$this->seedRequiredBindings($schema, $purpose);
|
||||
|
||||
$published = $this->service->publish($schema->fresh('fields'), $this->actor);
|
||||
|
||||
$this->assertTrue((bool) $published->is_published);
|
||||
$this->assertSame($purpose->value, $published->purpose->value ?? $published->purpose);
|
||||
}
|
||||
|
||||
public function test_event_registration_without_required_bindings_fails_publish(): void
|
||||
{
|
||||
$schema = $this->service->create(
|
||||
$this->org,
|
||||
['name' => 'ER', 'purpose' => FormPurpose::EVENT_REGISTRATION->value],
|
||||
$this->actor,
|
||||
);
|
||||
|
||||
try {
|
||||
$this->service->publish($schema->fresh('fields'), $this->actor);
|
||||
$this->fail('Expected PurposeRequirementsNotMetException');
|
||||
} catch (PurposeRequirementsNotMetException $e) {
|
||||
$this->assertSame('event_registration', $e->purposeSlug);
|
||||
$this->assertSame(
|
||||
['person.email', 'person.first_name', 'person.last_name'],
|
||||
$e->missingBindings,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_supplier_intake_without_company_name_binding_fails_publish(): void
|
||||
{
|
||||
$schema = $this->service->create(
|
||||
$this->org,
|
||||
['name' => 'SI', 'purpose' => FormPurpose::SUPPLIER_INTAKE->value],
|
||||
$this->actor,
|
||||
);
|
||||
|
||||
try {
|
||||
$this->service->publish($schema->fresh('fields'), $this->actor);
|
||||
$this->fail('Expected PurposeRequirementsNotMetException');
|
||||
} catch (PurposeRequirementsNotMetException $e) {
|
||||
$this->assertSame('supplier_intake', $e->purposeSlug);
|
||||
$this->assertSame(['company.name'], $e->missingBindings);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_event_registration_partial_bindings_reports_only_missing(): void
|
||||
{
|
||||
$schema = $this->service->create(
|
||||
$this->org,
|
||||
['name' => 'ER-partial', 'purpose' => FormPurpose::EVENT_REGISTRATION->value],
|
||||
$this->actor,
|
||||
);
|
||||
$this->addBindingField($schema, 'person', 'email', 'email');
|
||||
|
||||
try {
|
||||
$this->service->publish($schema->fresh('fields'), $this->actor);
|
||||
$this->fail('Expected PurposeRequirementsNotMetException');
|
||||
} catch (PurposeRequirementsNotMetException $e) {
|
||||
$this->assertSame(
|
||||
['person.first_name', 'person.last_name'],
|
||||
$e->missingBindings,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function seedRequiredBindings(FormSchema $schema, FormPurpose $purpose): void
|
||||
{
|
||||
match ($purpose) {
|
||||
FormPurpose::EVENT_REGISTRATION => [
|
||||
$this->addBindingField($schema, 'person', 'email', 'email'),
|
||||
$this->addBindingField($schema, 'person', 'first_name', 'first_name'),
|
||||
$this->addBindingField($schema, 'person', 'last_name', 'last_name'),
|
||||
],
|
||||
FormPurpose::SUPPLIER_INTAKE => [
|
||||
$this->addBindingField($schema, 'company', 'name', 'company_name'),
|
||||
],
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
private function addBindingField(FormSchema $schema, string $entity, string $column, string $slug): FormField
|
||||
{
|
||||
return FormField::factory()->create([
|
||||
'form_schema_id' => $schema->id,
|
||||
'field_type' => FormFieldType::TEXT,
|
||||
'slug' => $slug,
|
||||
'label' => ucfirst($slug),
|
||||
'binding' => ['mode' => 'entity_owned', 'entity' => $entity, 'column' => $column],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder\Purposes;
|
||||
|
||||
use App\Enums\FormBuilder\FormPurpose;
|
||||
use App\Models\Event;
|
||||
use App\Models\FormBuilder\FormSchema;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\Person;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Q6 consolidation: `config/form_subjects.php` no longer exists and the
|
||||
* allowed `subject_type` values on `form_submissions` come from
|
||||
* PurposeRegistry::allSubjectTypes().
|
||||
*/
|
||||
final class SubjectTypeRegistryConsolidationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Organisation $org;
|
||||
|
||||
private User $admin;
|
||||
|
||||
private FormSchema $schema;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed(RoleSeeder::class);
|
||||
|
||||
$this->org = Organisation::factory()->create();
|
||||
$this->admin = User::factory()->create();
|
||||
$this->org->users()->attach($this->admin, ['role' => 'org_admin']);
|
||||
$this->admin->assignRole('org_admin');
|
||||
setPermissionsTeamId($this->org->id);
|
||||
|
||||
$this->schema = FormSchema::factory()->create([
|
||||
'organisation_id' => $this->org->id,
|
||||
'purpose' => FormPurpose::INCIDENT_REPORT,
|
||||
'is_published' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_accepts_registry_subject_types(): void
|
||||
{
|
||||
Sanctum::actingAs($this->admin);
|
||||
$event = Event::factory()->create(['organisation_id' => $this->org->id]);
|
||||
$person = Person::factory()->create(['event_id' => $event->id]);
|
||||
|
||||
$this->postJson(
|
||||
"/api/v1/organisations/{$this->org->id}/forms/schemas/{$this->schema->id}/submissions",
|
||||
[
|
||||
'subject_type' => 'person',
|
||||
'subject_id' => $person->id,
|
||||
],
|
||||
)->assertCreated();
|
||||
}
|
||||
|
||||
public function test_rejects_subject_type_not_in_registry(): void
|
||||
{
|
||||
Sanctum::actingAs($this->admin);
|
||||
|
||||
$this->postJson(
|
||||
"/api/v1/organisations/{$this->org->id}/forms/schemas/{$this->schema->id}/submissions",
|
||||
[
|
||||
'subject_type' => 'event',
|
||||
'subject_id' => (string) \Illuminate\Support\Str::ulid(),
|
||||
],
|
||||
)->assertStatus(422);
|
||||
}
|
||||
|
||||
public function test_rejects_subject_type_that_never_existed(): void
|
||||
{
|
||||
Sanctum::actingAs($this->admin);
|
||||
|
||||
$this->postJson(
|
||||
"/api/v1/organisations/{$this->org->id}/forms/schemas/{$this->schema->id}/submissions",
|
||||
[
|
||||
'subject_type' => 'unicorn',
|
||||
'subject_id' => (string) \Illuminate\Support\Str::ulid(),
|
||||
],
|
||||
)->assertStatus(422);
|
||||
}
|
||||
}
|
||||
@@ -6,96 +6,59 @@ namespace Tests\Unit\Enums\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormPurpose;
|
||||
use App\Enums\FormBuilder\FormSubmissionMode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FormPurposeTest extends TestCase
|
||||
final class FormPurposeTest extends TestCase
|
||||
{
|
||||
public function test_has_22_cases(): void
|
||||
public function test_has_seven_cases(): void
|
||||
{
|
||||
$this->assertCount(22, FormPurpose::cases());
|
||||
$this->assertCount(7, FormPurpose::cases());
|
||||
}
|
||||
|
||||
public function test_values_contains_expected_strings(): void
|
||||
public function test_values_match_v1_vocabulary(): void
|
||||
{
|
||||
$values = FormPurpose::values();
|
||||
$expected = [
|
||||
'event_registration', 'user_profile', 'artist_profile', 'company_profile',
|
||||
'artist_advance', 'supplier_intake', 'incident_report', 'feedback',
|
||||
'post_event_evaluation', 'signature_contract', 'signature_code_of_conduct',
|
||||
'signature_receipt', 'absence_report', 'check_out_inventory',
|
||||
'public_complaint', 'public_press_request', 'public_rsvp',
|
||||
'onboarding_wizard', 'event_setup_wizard', 'company_custom',
|
||||
'artist_custom', 'custom',
|
||||
];
|
||||
foreach ($expected as $v) {
|
||||
$this->assertContains($v, $values);
|
||||
}
|
||||
$this->assertSame(
|
||||
[
|
||||
'event_registration',
|
||||
'artist_advance',
|
||||
'supplier_intake',
|
||||
'post_event_evaluation',
|
||||
'incident_report',
|
||||
'signature_contract',
|
||||
'user_profile',
|
||||
],
|
||||
FormPurpose::values(),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_default_subject_type_for_person_purposes(): void
|
||||
public function test_default_submission_mode_delegates_to_registry(): void
|
||||
{
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::EVENT_REGISTRATION->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::DRAFT_SINGLE, FormPurpose::ARTIST_ADVANCE->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::SUPPLIER_INTAKE->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::MULTIPLE, FormPurpose::INCIDENT_REPORT->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::USER_PROFILE->defaultSubmissionMode());
|
||||
}
|
||||
|
||||
public function test_default_subject_type_delegates_to_registry(): void
|
||||
{
|
||||
$this->assertSame('person', FormPurpose::EVENT_REGISTRATION->defaultSubjectType());
|
||||
$this->assertSame('person', FormPurpose::POST_EVENT_EVALUATION->defaultSubjectType());
|
||||
$this->assertSame('person', FormPurpose::SIGNATURE_RECEIPT->defaultSubjectType());
|
||||
$this->assertSame('person', FormPurpose::ABSENCE_REPORT->defaultSubjectType());
|
||||
$this->assertSame('person', FormPurpose::CHECK_OUT_INVENTORY->defaultSubjectType());
|
||||
}
|
||||
|
||||
public function test_default_subject_type_for_entity_purposes(): void
|
||||
{
|
||||
$this->assertSame('user', FormPurpose::USER_PROFILE->defaultSubjectType());
|
||||
$this->assertSame('artist', FormPurpose::ARTIST_PROFILE->defaultSubjectType());
|
||||
$this->assertSame('company', FormPurpose::COMPANY_PROFILE->defaultSubjectType());
|
||||
$this->assertSame('artist', FormPurpose::ARTIST_ADVANCE->defaultSubjectType());
|
||||
$this->assertSame('company', FormPurpose::SUPPLIER_INTAKE->defaultSubjectType());
|
||||
$this->assertSame('organisation', FormPurpose::ONBOARDING_WIZARD->defaultSubjectType());
|
||||
$this->assertSame('event', FormPurpose::EVENT_SETUP_WIZARD->defaultSubjectType());
|
||||
$this->assertSame('person', FormPurpose::POST_EVENT_EVALUATION->defaultSubjectType());
|
||||
$this->assertSame('person', FormPurpose::INCIDENT_REPORT->defaultSubjectType());
|
||||
$this->assertSame('user', FormPurpose::SIGNATURE_CONTRACT->defaultSubjectType());
|
||||
$this->assertSame('user', FormPurpose::USER_PROFILE->defaultSubjectType());
|
||||
}
|
||||
|
||||
public function test_default_subject_type_is_null_for_public_and_custom(): void
|
||||
public function test_only_event_registration_allows_public_access(): void
|
||||
{
|
||||
$this->assertNull(FormPurpose::PUBLIC_COMPLAINT->defaultSubjectType());
|
||||
$this->assertNull(FormPurpose::PUBLIC_PRESS_REQUEST->defaultSubjectType());
|
||||
$this->assertNull(FormPurpose::PUBLIC_RSVP->defaultSubjectType());
|
||||
$this->assertNull(FormPurpose::CUSTOM->defaultSubjectType());
|
||||
}
|
||||
|
||||
public function test_default_submission_mode_draft_single(): void
|
||||
{
|
||||
$this->assertSame(FormSubmissionMode::DRAFT_SINGLE, FormPurpose::EVENT_REGISTRATION->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::DRAFT_SINGLE, FormPurpose::ARTIST_ADVANCE->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::DRAFT_SINGLE, FormPurpose::SUPPLIER_INTAKE->defaultSubmissionMode());
|
||||
}
|
||||
|
||||
public function test_default_submission_mode_multiple(): void
|
||||
{
|
||||
$this->assertSame(FormSubmissionMode::MULTIPLE, FormPurpose::INCIDENT_REPORT->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::MULTIPLE, FormPurpose::FEEDBACK->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::MULTIPLE, FormPurpose::PUBLIC_COMPLAINT->defaultSubmissionMode());
|
||||
}
|
||||
|
||||
public function test_default_submission_mode_single(): void
|
||||
{
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::USER_PROFILE->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::ARTIST_PROFILE->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::ONBOARDING_WIZARD->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::CUSTOM->defaultSubmissionMode());
|
||||
}
|
||||
|
||||
public function test_allows_public_access(): void
|
||||
{
|
||||
$this->assertTrue(FormPurpose::PUBLIC_COMPLAINT->allowsPublicAccess());
|
||||
$this->assertTrue(FormPurpose::PUBLIC_PRESS_REQUEST->allowsPublicAccess());
|
||||
$this->assertTrue(FormPurpose::PUBLIC_RSVP->allowsPublicAccess());
|
||||
$this->assertTrue(FormPurpose::ARTIST_ADVANCE->allowsPublicAccess());
|
||||
$this->assertTrue(FormPurpose::SUPPLIER_INTAKE->allowsPublicAccess());
|
||||
}
|
||||
|
||||
public function test_disallows_public_access(): void
|
||||
{
|
||||
$this->assertFalse(FormPurpose::EVENT_REGISTRATION->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::USER_PROFILE->allowsPublicAccess());
|
||||
$this->assertTrue(FormPurpose::EVENT_REGISTRATION->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::ARTIST_ADVANCE->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::SUPPLIER_INTAKE->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::POST_EVENT_EVALUATION->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::INCIDENT_REPORT->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::CUSTOM->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::SIGNATURE_CONTRACT->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::USER_PROFILE->allowsPublicAccess());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user