seed(RoleSeeder::class); $this->org = Organisation::factory()->create(); $this->event = Event::factory()->create(['organisation_id' => $this->org->id]); $this->crowdType = CrowdType::factory()->systemType('VOLUNTEER')->create([ 'organisation_id' => $this->org->id, ]); $this->schema = FormSchema::factory()->create([ 'organisation_id' => $this->org->id, 'purpose' => FormPurpose::EVENT_REGISTRATION, 'owner_type' => 'event', 'owner_id' => $this->event->id, ]); FormField::factory()->create([ 'form_schema_id' => $this->schema->id, 'field_type' => FormFieldType::TEXT->value, 'slug' => 'naam', 'is_portal_visible' => true, ]); } public function test_event_registration_triggers_matched_when_person_has_user(): void { $user = User::factory()->create(); $person = Person::factory()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->crowdType->id, 'user_id' => $user->id, ]); $submission = FormSubmission::factory()->create([ 'form_schema_id' => $this->schema->id, 'subject_type' => 'person', 'subject_id' => $person->id, 'status' => 'submitted', 'submitted_at' => now(), ]); FormSubmissionSubmitted::dispatch($submission->fresh()); $this->assertSame('matched', $submission->fresh()->identity_match_status); } public function test_event_registration_triggers_none_when_person_unlinked_no_match(): void { $person = Person::factory()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->crowdType->id, 'user_id' => null, 'email' => 'nobody@nowhere.test', 'first_name' => 'Xyz', 'last_name' => 'NoMatch', ]); $submission = FormSubmission::factory()->create([ 'form_schema_id' => $this->schema->id, 'subject_type' => 'person', 'subject_id' => $person->id, 'status' => 'submitted', 'submitted_at' => now(), ]); FormSubmissionSubmitted::dispatch($submission->fresh()); $this->assertSame('none', $submission->fresh()->identity_match_status); } public function test_event_registration_triggers_pending_when_matcher_finds_candidate(): void { // Pre-seed a User with a specific email, then a Person in the same // org with the matching email → detectMatches should create a // PersonIdentityMatch with status=pending. $user = User::factory()->create(['email' => 'match@example.test']); $this->org->users()->attach($user, ['role' => 'org_member']); $person = Person::factory()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->crowdType->id, 'user_id' => null, 'email' => 'match@example.test', 'first_name' => 'Anne', 'last_name' => 'Match', ]); $submission = FormSubmission::factory()->create([ 'form_schema_id' => $this->schema->id, 'subject_type' => 'person', 'subject_id' => $person->id, 'status' => 'submitted', 'submitted_at' => now(), ]); FormSubmissionSubmitted::dispatch($submission->fresh()); $this->assertSame('pending', $submission->fresh()->identity_match_status); } public function test_non_event_registration_purpose_does_not_trigger(): void { $otherSchema = FormSchema::factory()->create([ 'organisation_id' => $this->org->id, 'purpose' => FormPurpose::FEEDBACK, ]); $submission = FormSubmission::factory()->create([ 'form_schema_id' => $otherSchema->id, 'subject_type' => null, 'subject_id' => null, 'status' => 'submitted', 'submitted_at' => now(), ]); FormSubmissionSubmitted::dispatch($submission->fresh()); $this->assertNull($submission->fresh()->identity_match_status); } public function test_public_submission_marked_pending(): void { $submission = FormSubmission::factory()->create([ 'form_schema_id' => $this->schema->id, 'subject_type' => null, 'subject_id' => null, 'status' => 'submitted', 'submitted_at' => now(), ]); FormSubmissionSubmitted::dispatch($submission->fresh()); $this->assertSame('pending', $submission->fresh()->identity_match_status); } }