Skip to content

Commit

Permalink
fix: Tests for soft deleted waiting lists and fix soft deleted waitin…
Browse files Browse the repository at this point in the history
…g list behaviour when retrieving soft deleted waiting list positions (#3881)
  • Loading branch information
maxbrokman authored Nov 22, 2024
1 parent 7392f30 commit 8ddf30f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
22 changes: 15 additions & 7 deletions app/Models/Mship/Concerns/HasWaitingLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public function waitingListAccounts()
*/
public function waitingLists()
{
return $this->waitingListAccounts()
// waiting list accounts soft delete so this will exclude them
$waitingListAccounts = $this->waitingListAccounts()
->withTrashed()
->get()
->mapWithKeys(function (WaitingListAccount $waitingListAccount) {
return [$waitingListAccount->waitingList->id => $waitingListAccount->waitingList];
})
->values();
->with('waitingList')
->get();

return $this->extractListsFromWaitingListAccounts($waitingListAccounts);
}

/**
Expand All @@ -41,7 +41,15 @@ public function currentWaitingLists(): Collection
->with('waitingList')
->get();

// @fixme maybe replace with mapWithKeys
return $this->extractListsFromWaitingListAccounts($waitingListAccounts);
}

/**
* @param Collection<WaitingListAccount> $waitingListAccounts
* @return Collection<WaitingList>
*/
private function extractListsFromWaitingListAccounts(Collection $waitingListAccounts): Collection
{
$waitingLists = collect();
foreach ($waitingListAccounts as $waitingListAccount) {
$waitingList = $waitingListAccount->waitingList;
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Account/Relationships/AccountWaitingListsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@ public function itCanGetAllCurrentWaitingLists()
$this->assertCount(1, $this->user->fresh()->currentWaitingLists());
$this->assertContains($this->currentWaitingList->id, $this->user->fresh()->currentWaitingLists()->pluck('id'));
}

/** @test */
public function itCanHandleTrashedWaitingLists()
{
$trashed = factory(WaitingList::class)->create();
$trashed->addToWaitingList($this->user, $this->privacc);
$trashed->delete();
$trashed->save();

$this->assertCount(1, $this->user->fresh()->currentWaitingLists());
$this->assertCount(2, $this->user->fresh()->waitingLists());
}
}

0 comments on commit 8ddf30f

Please sign in to comment.