- Seed AVAILABILITY_PICKER and SECTION_PRIORITY demo fields in the
event_registration showcase, and augment seedEchtFeesten with a
parent-level VOLUNTEER time slot pair + a standard registration-
visible section whose name duplicates a child section so the
PublicFormController dedup path is exercised end-to-end.
- Validate SECTION_PRIORITY value shape in FormValueService: arrays of
{ section_id, priority } with unique section_ids + priorities in 1..5,
max 5 entries, and section_ids scoped to the schema's event tree
(parent + children). Error envelope is the standard VALIDATION_FAILED
FieldValidationException shape so the portal renders errors next to
the field.
- Enrich admin-facing FormSubmissionResource with a nested identity_match
block mirroring the PublicFormSubmissionResource contract (status only;
leaves room for future matched_user_id / confidence).
- Lock in the FORM-05 stub contract with 6 tests against the existing
TriggerPersonIdentityMatchOnFormSubmit listener (no new listener was
needed — the current one already writes 'pending' for public
event_registration submissions per ARCH §31.1).
- 24 new backend assertions across seeder, shape validation, listener
state matrix, and resource serialisation.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
101 lines
3.1 KiB
PHP
101 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\FormBuilder;
|
|
|
|
use App\Enums\FormBuilder\FormSubmissionStatus;
|
|
use App\Http\Resources\FormBuilder\FormSubmissionResource;
|
|
use App\Models\FormBuilder\FormSchema;
|
|
use App\Models\FormBuilder\FormSubmission;
|
|
use App\Models\Organisation;
|
|
use App\Models\User;
|
|
use Database\Seeders\RoleSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Admin-facing FormSubmissionResource must surface identity_match_status
|
|
* as a nested { status } block so the organiser UI can render the same
|
|
* signal shape the portal already exposes. Keeps room for future
|
|
* matched_user_id / confidence fields without a contract break.
|
|
*/
|
|
final class FormSubmissionResourceIdentityMatchTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private Organisation $org;
|
|
|
|
private FormSchema $schema;
|
|
|
|
private User $admin;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->seed(RoleSeeder::class);
|
|
|
|
$this->org = Organisation::factory()->create();
|
|
$this->schema = FormSchema::factory()->create(['organisation_id' => $this->org->id]);
|
|
$this->admin = User::factory()->create();
|
|
$this->org->users()->attach($this->admin, ['role' => 'org_admin']);
|
|
}
|
|
|
|
private function toArray(FormSubmission $submission): array
|
|
{
|
|
$request = request();
|
|
Sanctum::actingAs($this->admin);
|
|
|
|
return (new FormSubmissionResource($submission->fresh()))->toArray($request);
|
|
}
|
|
|
|
public function test_pending_status_serialises_as_nested_object(): void
|
|
{
|
|
$submission = FormSubmission::create([
|
|
'form_schema_id' => $this->schema->id,
|
|
'status' => FormSubmissionStatus::SUBMITTED->value,
|
|
'submitted_at' => now(),
|
|
'is_test' => false,
|
|
'identity_match_status' => 'pending',
|
|
]);
|
|
|
|
$array = $this->toArray($submission);
|
|
|
|
$this->assertIsArray($array['identity_match']);
|
|
$this->assertSame(['status' => 'pending'], $array['identity_match']);
|
|
}
|
|
|
|
public function test_null_status_serialises_as_null(): void
|
|
{
|
|
$submission = FormSubmission::create([
|
|
'form_schema_id' => $this->schema->id,
|
|
'status' => FormSubmissionStatus::SUBMITTED->value,
|
|
'submitted_at' => now(),
|
|
'is_test' => false,
|
|
]);
|
|
|
|
$array = $this->toArray($submission);
|
|
|
|
$this->assertNull($array['identity_match']);
|
|
}
|
|
|
|
public function test_api_endpoint_returns_matching_shape(): void
|
|
{
|
|
Sanctum::actingAs($this->admin);
|
|
|
|
$submission = FormSubmission::create([
|
|
'form_schema_id' => $this->schema->id,
|
|
'status' => FormSubmissionStatus::SUBMITTED->value,
|
|
'submitted_at' => now(),
|
|
'is_test' => false,
|
|
'identity_match_status' => 'matched',
|
|
]);
|
|
|
|
$response = $this->getJson("/api/v1/organisations/{$this->org->id}/forms/submissions/{$submission->id}");
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('data.identity_match.status', 'matched');
|
|
}
|
|
}
|