~30 new tests + 6 modified covering D2 deliverables. NEW test files: - FormSubmissionSubmittedListenerOrderTest: rewritten — flips identity-match assertion from sync to ShouldQueue + adds AST-level structural guard that every queued listener has the apply_status=COMPLETED gate as an early statement (form-builder.queued-listener.skipped_apply_failed log line + ApplyStatus::COMPLETED check). - TriggerPersonIdentityMatchOnFormSubmitTest: rewritten — drops failsafe-pad assertions; adds gate-skip tests (null/PENDING/PARTIAL/FAILED); invariant-violation throw test; broadcast-dispatch test. - ApplyBindingsOnFormSubmitTest: extended — initial identity_match_status='pending' write, apply_completed_at on both paths, classifier-derived failure_response_code per exception subclass, unknown_error fallback, deadline wrapper invocation captured by test double, outer-transaction failure record. - SyncTagPickerSelectionsOnSubmitGateTest (NEW): canonical skip-log assertion for null/PENDING/PARTIAL/FAILED apply_status; no-skip-log assertion for COMPLETED. Uses Log::spy because FormTagSyncService is final and can't be Mockery-mocked. - FormBindingApplicatorDeadlineTest (NEW): withDeadline returns clone; no-deadline path; generous-deadline path; timeout exception thrown with correct submissionId + reasonCode (temporary_error inherited via FormBindingInfraException). Uses incident_report purpose for anonymous-allowed branch to avoid PersonProvisioner constraints. - RetryServiceFailureClassifierTest (NEW): per-subclass failure_response_code mapping in recordFailure; apply_completed_at symmetry-fix coverage. - SubmissionChannelAuthTest (NEW): submitter authorised, other user denied, missing submission denied, org admin currently denied (locks v1 contract per BACKLOG TECH-CHANNEL-AUTH-ORG-ADMIN). - FormSubmissionResourceIdentityMatchTest: extended — DataProvider iterates over all six non-person purposes asserting identity_match=null per RFC §Q2 v1.3 contract. MODIFIED to fit v1.3 layout: - IdentityMatchOnSubmitTest: rewritten — directly invokes the listener with apply_status=COMPLETED pre-set, mirroring ApplyBindings' happy-path output (the test fixtures lack an identity-key binding so going through full event dispatch fails at PersonProvisioner). Drops the failsafe-pad assertion in test_public_submission_marked_pending; replaces with v1.3 contract: subject_type=null leaves identity_match_status untouched. - TagPickerSyncListenerTest: same fix — sets apply_status=COMPLETED on the submission and invokes the listener directly. Full suite: 1621 passing (4281 assertions). Larastan: 0 errors. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
152 lines
5.2 KiB
PHP
152 lines
5.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\FormBuilder;
|
|
|
|
use App\Enums\FormBuilder\FormPurpose;
|
|
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 PHPUnit\Framework\Attributes\DataProvider;
|
|
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');
|
|
}
|
|
|
|
/**
|
|
* Per RFC-WS-6 §Q2 v1.3 — for non-person purposes the identity_match
|
|
* block is null. ApplyBindings only writes identity_match_status='pending'
|
|
* when the subject is a person; non-person purposes leave the column
|
|
* NULL and the resource emits null. This test pins the contract per
|
|
* non-person purpose so a future refactor can't silently drift.
|
|
*
|
|
* `event_registration` is intentionally excluded — that purpose IS
|
|
* person-typed and identity_match is non-null after ApplyBindings runs.
|
|
*
|
|
* @return array<string, array{0: FormPurpose}>
|
|
*/
|
|
public static function nonPersonPurposes(): array
|
|
{
|
|
return [
|
|
'signature_contract' => [FormPurpose::SIGNATURE_CONTRACT],
|
|
'user_profile' => [FormPurpose::USER_PROFILE],
|
|
'incident_report' => [FormPurpose::INCIDENT_REPORT],
|
|
'post_event_evaluation' => [FormPurpose::POST_EVENT_EVALUATION],
|
|
'supplier_intake' => [FormPurpose::SUPPLIER_INTAKE],
|
|
'artist_advance' => [FormPurpose::ARTIST_ADVANCE],
|
|
];
|
|
}
|
|
|
|
#[DataProvider('nonPersonPurposes')]
|
|
public function test_identity_match_is_null_for_non_person_purpose(FormPurpose $purpose): void
|
|
{
|
|
$schema = FormSchema::factory()->create([
|
|
'organisation_id' => $this->org->id,
|
|
'purpose' => $purpose->value,
|
|
]);
|
|
|
|
$submission = FormSubmission::create([
|
|
'form_schema_id' => $schema->id,
|
|
'status' => FormSubmissionStatus::SUBMITTED->value,
|
|
'submitted_at' => now(),
|
|
'is_test' => false,
|
|
// identity_match_status intentionally not set; for non-person
|
|
// purposes the column stays NULL.
|
|
]);
|
|
|
|
$array = $this->toArray($submission);
|
|
|
|
$this->assertNull(
|
|
$array['identity_match'],
|
|
"FormSubmissionResource.identity_match must be null for non-person purpose '{$purpose->value}' per RFC-WS-6 §Q2 v1.3.",
|
|
);
|
|
}
|
|
}
|