Fix member search for membership when one param is empty
This commit is contained in:
parent
a25d983de0
commit
d29f7b6e8a
|
@ -2,8 +2,11 @@
|
|||
|
||||
namespace App\Member;
|
||||
|
||||
use App\Activity;
|
||||
use App\Group;
|
||||
use App\Invoice\BillKind;
|
||||
use App\Lib\Filter;
|
||||
use App\Subactivity;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Scout\Builder;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
|
@ -139,6 +142,9 @@ class FilterScope extends Filter
|
|||
*/
|
||||
protected function possibleValuesForMembership(array $membership): Collection
|
||||
{
|
||||
$membership['group_ids'] = count($membership['group_ids']) === 0 ? Group::pluck('id')->toArray() : $membership['group_ids'];
|
||||
$membership['activity_ids'] = count($membership['activity_ids']) === 0 ? Activity::pluck('id')->toArray() : $membership['activity_ids'];
|
||||
$membership['subactivity_ids'] = count($membership['subactivity_ids']) === 0 ? Subactivity::pluck('id')->toArray() : $membership['subactivity_ids'];
|
||||
return $this->combinations($membership['group_ids'], $membership['activity_ids'], $membership['subactivity_ids'])
|
||||
->map(fn ($combination) => collect($combination)->implode('|'));
|
||||
}
|
||||
|
|
|
@ -199,6 +199,26 @@ class MemberIndexTest extends EndToEndTestCase
|
|||
]])->assertInertiaCount('data.data', 1);
|
||||
}
|
||||
|
||||
public function testGroupOfMembershipsFilterCanBeEmpty(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$mitglied = Activity::factory()->create();
|
||||
$woelfling = Subactivity::factory()->create();
|
||||
$group = Group::factory()->create();
|
||||
Member::factory()->defaults()->has(Membership::factory()->for($mitglied)->for($woelfling)->for($group))->create();
|
||||
|
||||
sleep(1);
|
||||
$this->callFilter('member.index', ['memberships' => [
|
||||
['group_ids' => [], 'activity_ids' => [$mitglied->id], 'subactivity_ids' => [$woelfling->id]],
|
||||
]])->assertInertiaCount('data.data', 1);
|
||||
$this->callFilter('member.index', ['memberships' => [
|
||||
['group_ids' => [$group->id], 'activity_ids' => [], 'subactivity_ids' => [$woelfling->id]],
|
||||
]])->assertInertiaCount('data.data', 1);
|
||||
$this->callFilter('member.index', ['memberships' => [
|
||||
['group_ids' => [$group->id], 'activity_ids' => [$mitglied->id], 'subactivity_ids' => []],
|
||||
]])->assertInertiaCount('data.data', 1);
|
||||
}
|
||||
|
||||
public function testItFiltersForSearchButNotForPayments(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
|
|
Loading…
Reference in New Issue