- 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>
88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?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'));
|
|
}
|
|
}
|