Fix: Scope should have its own where clause

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,6 +48,7 @@ class FilterScope extends Filter
*/
public function apply(Builder $query): Builder
{
return $query->where(function ($query) {
$query->orWhere(function ($query) {
if ($this->ausstand) {
$query->whereAusstand();
@ -77,7 +78,6 @@ class FilterScope extends Filter
$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'));
}
}