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:
@@ -586,8 +586,9 @@ class DevSeeder extends Seeder
|
||||
// Person with unique email (no match expected)
|
||||
Person::create(['event_id' => $festival->id, 'crowd_type_id' => $vol, 'first_name' => 'Unique', 'last_name' => 'Persoon', 'email' => 'unique.persoon@nowhere.test', 'phone' => '+31612345044', 'status' => 'pending']);
|
||||
|
||||
$linked = $this->linkUsersToApprovedPersons($festival);
|
||||
$personCount = Person::where('event_id', $festival->id)->count();
|
||||
$this->command->info(" {$personCount} persons created");
|
||||
$this->command->info(" {$personCount} persons created ({$linked} user accounts linked)");
|
||||
|
||||
// ── Named shift assignments (22) ──
|
||||
|
||||
@@ -975,6 +976,8 @@ class DevSeeder extends Seeder
|
||||
Person::factory()->count(3)->create(['event_id' => $braderie->id, 'crowd_type_id' => $vol, 'status' => 'pending']);
|
||||
Person::factory()->count(2)->create(['event_id' => $braderie->id, 'crowd_type_id' => $vol, 'status' => 'applied']);
|
||||
|
||||
$this->linkUsersToApprovedPersons($braderie);
|
||||
|
||||
$this->command->info(' Braderie Dorpstown 2026 complete');
|
||||
});
|
||||
}
|
||||
@@ -1094,6 +1097,8 @@ class DevSeeder extends Seeder
|
||||
Person::factory()->count(2)->create(['event_id' => $ijsbaan->id, 'crowd_type_id' => $crewType, 'status' => 'pending']);
|
||||
Person::factory()->count(5)->approved()->create(['event_id' => $ijsbaan->id, 'crowd_type_id' => $guestType]);
|
||||
|
||||
$this->linkUsersToApprovedPersons($ijsbaan);
|
||||
|
||||
// ── Shift assignments (~80) ──
|
||||
|
||||
$openShifts = collect($allShifts)->filter(fn (Shift $shift) => $shift->status === 'open' && $shift->slots_open_for_claiming > 0);
|
||||
@@ -1241,6 +1246,8 @@ class DevSeeder extends Seeder
|
||||
// 2 suppliers
|
||||
Person::factory()->count(2)->approved()->create(['event_id' => $koningsdag->id, 'crowd_type_id' => $supplierType]);
|
||||
|
||||
$this->linkUsersToApprovedPersons($koningsdag);
|
||||
|
||||
// ── Shift assignments (~150) ──
|
||||
|
||||
// 120 completed + 12 cancelled + 8 no-show + 5 rejected + 5 pending
|
||||
@@ -1348,6 +1355,36 @@ class DevSeeder extends Seeder
|
||||
// Helpers
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Create User accounts for approved/no_show persons that lack one.
|
||||
* Mirrors the production approval flow (PersonController::approve).
|
||||
*/
|
||||
private function linkUsersToApprovedPersons(Event $event): int
|
||||
{
|
||||
$linked = 0;
|
||||
|
||||
Person::withoutGlobalScopes()
|
||||
->where('event_id', $event->id)
|
||||
->whereIn('status', ['approved', 'no_show'])
|
||||
->whereNull('user_id')
|
||||
->each(function (Person $person) use (&$linked): void {
|
||||
$user = User::firstOrCreate(
|
||||
['email' => strtolower($person->email)],
|
||||
[
|
||||
'first_name' => $person->first_name,
|
||||
'last_name' => $person->last_name,
|
||||
'password' => Hash::make('password'),
|
||||
]
|
||||
);
|
||||
|
||||
$person->user_id = $user->id;
|
||||
$person->save();
|
||||
$linked++;
|
||||
});
|
||||
|
||||
return $linked;
|
||||
}
|
||||
|
||||
private function createCrowdList(
|
||||
Event $event,
|
||||
string $name,
|
||||
|
||||
Reference in New Issue
Block a user