fix: seeder creates User accounts for approved/no_show persons

The DevSeeder was creating approved persons without linked User
accounts, which can't happen in production (approval flow always
creates accounts). Added linkUsersToApprovedPersons() helper that
runs after person creation in each event seeder, creating User
accounts via firstOrCreate for approved and no_show persons that
lack user_id.

Also added safeguard tests verifying the approval flow creates
user accounts and reuses existing ones.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-16 20:42:47 +02:00
parent ef7c482b4a
commit 5d8a749cb3
2 changed files with 81 additions and 1 deletions

View File

@@ -196,4 +196,47 @@ class PersonTest extends TestCase
$response->assertUnauthorized();
}
public function test_approve_creates_user_account_for_person(): void
{
$person = Person::factory()->create([
'event_id' => $this->event->id,
'crowd_type_id' => $this->crowdType->id,
'status' => 'pending',
'email' => 'volunteer@example.com',
]);
$this->assertNull($person->user_id);
Sanctum::actingAs($this->orgAdmin);
$response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve");
$response->assertOk();
$person->refresh();
$this->assertNotNull($person->user_id);
$this->assertDatabaseHas('users', ['email' => 'volunteer@example.com']);
}
public function test_approve_reuses_existing_user_account(): void
{
$existingUser = User::factory()->create(['email' => 'existing@example.com']);
$person = Person::factory()->create([
'event_id' => $this->event->id,
'crowd_type_id' => $this->crowdType->id,
'status' => 'pending',
'email' => 'existing@example.com',
]);
Sanctum::actingAs($this->orgAdmin);
$this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve")
->assertOk();
$person->refresh();
$this->assertEquals($existingUser->id, $person->user_id);
}
}