Fix: Scope should have its own where clause
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Philipp Lang 2023-06-29 12:58:05 +02:00
parent e37219b1ca
commit 9b2364bc34
3 changed files with 73 additions and 27 deletions

View File

@ -48,36 +48,36 @@ class FilterScope extends Filter
*/
public function apply(Builder $query): Builder
{
$query->orWhere(function ($query) {
if ($this->ausstand) {
$query->whereAusstand();
}
return $query->where(function ($query) {
$query->orWhere(function ($query) {
if ($this->ausstand) {
$query->whereAusstand();
}
if ($this->billKind) {
$query->where('bill_kind', BillKind::fromValue($this->billKind));
}
if ($this->billKind) {
$query->where('bill_kind', BillKind::fromValue($this->billKind));
}
if (count($this->groupIds)) {
$query->whereIn('group_id', $this->groupIds);
}
if (count($this->groupIds)) {
$query->whereIn('group_id', $this->groupIds);
}
if (count($this->subactivityIds) + count($this->activityIds) > 0) {
$query->whereHas('memberships', function ($q) {
$q->active();
if (count($this->subactivityIds)) {
$q->whereIn('subactivity_id', $this->subactivityIds);
}
if (count($this->activityIds)) {
$q->whereIn('activity_id', $this->activityIds);
}
});
}
})->orWhere(function ($query) {
if (count($this->additional)) {
$query->whereIn('id', $this->additional);
}
if (count($this->subactivityIds) + count($this->activityIds) > 0) {
$query->whereHas('memberships', function ($q) {
$q->active();
if (count($this->subactivityIds)) {
$q->whereIn('subactivity_id', $this->subactivityIds);
}
if (count($this->activityIds)) {
$q->whereIn('activity_id', $this->activityIds);
}
});
}
})->orWhere(function ($query) {
if (count($this->additional)) {
$query->whereIn('id', $this->additional);
}
});
});
return $query;
}
}

View File

@ -13,6 +13,9 @@
<testsuite name="NamiUnit">
<directory suffix="Test.php">./packages/laravel-nami/tests/Unit</directory>
</testsuite>
<testsuite name="EndToEnd">
<directory suffix="Test.php">./tests/EndToEnd</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">

View File

@ -0,0 +1,43 @@
<?php
namespace Tests\EndToEnd;
use App\Group;
use App\Member\Member;
use App\Payment\Payment;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\RequestFactories\Child;
use Tests\TestCase;
class MemberIndexTest extends TestCase
{
use DatabaseMigrations;
public function testItHandlesFullTextSearch(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$group = Group::factory()->create();
Member::factory()->defaults()->for($group)->create(['firstname' => '::firstname::']);
Member::factory()->defaults()->for($group)->create(['firstname' => '::gggname::']);
$response = $this->callFilter('member.index', ['search' => '::firstname::']);
$this->assertCount(1, $this->inertia($response, 'data.data'));
}
public function testItFiltersForSearchButNotForPayments(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$group = Group::factory()->create();
Member::factory()->defaults()->for($group)
->has(Payment::factory()->notPaid()->subscription('tollerbeitrag', [
new Child('a', 5400),
]))
->create(['firstname' => '::firstname::']);
Member::factory()->defaults()->for($group)->create(['firstname' => '::firstname::']);
$response = $this->callFilter('member.index', ['search' => '::firstname::', 'ausstand' => true]);
$this->assertCount(1, $this->inertia($response, 'data.data'));
}
}