adrema/tests/EndToEnd/MemberIndexTest.php

290 lines
13 KiB
PHP
Raw Normal View History

<?php
namespace Tests\EndToEnd;
2024-01-28 11:42:32 +01:00
use App\Activity;
2024-08-28 13:26:30 +02:00
use App\Country;
use App\Group;
2024-01-28 11:42:32 +01:00
use App\Invoice\BillKind;
use App\Invoice\Enums\InvoiceStatus;
2023-12-19 02:00:42 +01:00
use App\Invoice\Models\Invoice;
use App\Invoice\Models\InvoicePosition;
use App\Member\Member;
2024-01-28 11:42:32 +01:00
use App\Member\Membership;
use App\Subactivity;
use Tests\EndToEndTestCase;
2024-01-28 11:42:32 +01:00
class MemberIndexTest extends EndToEndTestCase
{
2024-01-26 00:35:00 +01:00
2024-08-28 13:26:30 +02:00
public function setUp(): void
{
2024-08-28 13:26:30 +02:00
parent::setUp();
Country::factory()->create(['name' => 'Deutschland']);
$this->withoutExceptionHandling()->login()->loginNami();
2024-08-28 13:26:30 +02:00
}
public function testItHandlesFullTextSearch(): void
{
2024-01-28 11:42:32 +01:00
Member::factory()->defaults()->count(2)->create(['firstname' => 'Alexander']);
2024-01-26 14:52:33 +01:00
Member::factory()->defaults()->create(['firstname' => 'Heinrich']);
2024-01-28 11:42:32 +01:00
sleep(1);
$this->callFilter('member.index', ['search' => 'Alexander'])
->assertInertiaCount('data.data', 2);
$this->callFilter('member.index', ['search' => 'Heinrich'])
->assertInertiaCount('data.data', 1);
}
2024-08-28 22:12:05 +02:00
public function testItGetsDefault(): void
2024-08-28 13:26:30 +02:00
{
2024-08-28 22:12:05 +02:00
$this->callFilter('member.index', [])
->assertInertiaPath('data.meta.default.country_id', Country::firstWhere('name', 'Deutschland')->id)
->assertInertiaPath('data.meta.default.address', '');
2024-08-28 13:26:30 +02:00
}
2023-07-24 16:55:07 +02:00
public function testItHandlesAddress(): void
{
2024-01-26 14:52:33 +01:00
Member::factory()->defaults()->create(['address' => '']);
Member::factory()->defaults()->create(['zip' => '']);
Member::factory()->defaults()->create(['location' => '']);
2024-01-28 11:42:32 +01:00
Member::factory()->defaults()->create();
sleep(1);
$this->callFilter('member.index', ['has_full_address' => false])
->assertInertiaCount('data.data', 3)
->assertInertiaPath('data.meta.total', 3)
->assertInertiaPath('data.meta.from', 1)
->assertInertiaPath('data.meta.to', 3);
$this->callFilter('member.index', ['has_full_address' => true])
->assertInertiaCount('data.data', 1)
->assertInertiaPath('data.meta.total', 1)
->assertInertiaPath('data.meta.from', 1)
->assertInertiaPath('data.meta.to', 1);
}
2023-07-24 16:55:07 +02:00
2024-01-28 11:42:32 +01:00
public function testItHandlesBirthday(): void
{
Member::factory()->defaults()->create(['birthday' => null]);
Member::factory()->defaults()->count(2)->create();
sleep(1);
$this->callFilter('member.index', ['has_birthday' => true])
->assertInertiaCount('data.data', 2);
$this->callFilter('member.index', ['has_birthday' => false])
->assertInertiaCount('data.data', 1);
}
2023-07-24 16:55:07 +02:00
2024-01-28 11:42:32 +01:00
public function testItHandlesBillKind(): void
{
Member::factory()->defaults()->postBillKind()->create();
Member::factory()->defaults()->emailBillKind()->count(2)->create();
sleep(1);
$this->callFilter('member.index', ['bill_kind' => BillKind::POST->value])
->assertInertiaCount('data.data', 1);
$this->callFilter('member.index', ['bill_kind' => BillKind::EMAIL->value])
->assertInertiaCount('data.data', 2);
$this->callFilter('member.index', [])
->assertInertiaCount('data.data', 3);
2023-07-24 16:55:07 +02:00
}
2024-01-28 11:42:32 +01:00
public function testItHandlesGroupIds(): void
2023-07-24 16:55:07 +02:00
{
2024-01-28 11:42:32 +01:00
$group = Group::factory()->create();
$otherGroup = Group::factory()->create();
$thirdGroup = Group::factory()->create();
Member::factory()->defaults()->for($group)->create();
Member::factory()->defaults()->count(2)->for($otherGroup)->create();
Member::factory()->defaults()->count(3)->for($thirdGroup)->create();
sleep(1);
$this->callFilter('member.index', ['group_ids' => [$group->id]])
->assertInertiaCount('data.data', 1);
$this->callFilter('member.index', ['group_ids' => [$otherGroup->id]])
->assertInertiaCount('data.data', 2);
$this->callFilter('member.index', ['group_ids' => [$otherGroup->id, $thirdGroup->id]])
->assertInertiaCount('data.data', 5);
$this->callFilter('member.index', [])
->assertInertiaCount('data.data', 6);
}
public function testItHandlesActivitiesAndSubactivities(): void
{
$mitglied = Activity::factory()->name('€ Mitglied')->create();
$schnuppermitglied = Activity::factory()->name('Schnuppermitgliedschaft')->create();
$woelfling = Subactivity::factory()->name('Wölfling')->create();
$rover = Subactivity::factory()->name('Rover')->create();
Member::factory()->defaults()->create();
Member::factory()->defaults()->count(2)->has(Membership::factory()->for($mitglied)->for($woelfling))->create();
Member::factory()->defaults()->count(3)->has(Membership::factory()->for($schnuppermitglied)->for($rover))->create();
sleep(1);
$this->callFilter('member.index', ['activity_ids' => [$mitglied->id]])
->assertInertiaCount('data.data', 2);
$this->callFilter('member.index', ['subactivity_ids' => [$woelfling->id]])
->assertInertiaCount('data.data', 2);
$this->callFilter('member.index', ['subactivity_ids' => [$rover->id]])
->assertInertiaCount('data.data', 3);
$this->callFilter('member.index', ['activity_ids' => [$schnuppermitglied->id], 'subactivity_ids' => [$woelfling->id]])
->assertInertiaCount('data.data', 0);
$this->callFilter('member.index', ['activity_ids' => [$schnuppermitglied->id], 'subactivity_ids' => [$rover->id]])
->assertInertiaCount('data.data', 3);
$this->callFilter('member.index', [])
->assertInertiaCount('data.data', 6);
}
2023-07-24 16:55:07 +02:00
2024-01-28 11:42:32 +01:00
public function testItHandlesActivityAndSubactivityForSingleMembership(): void
{
$mitglied = Activity::factory()->name('€ Mitglied')->create();
$schnuppermitglied = Activity::factory()->name('Schnuppermitgliedschaft')->create();
$woelfling = Subactivity::factory()->name('Wölfling')->create();
$rover = Subactivity::factory()->name('Rover')->create();
Member::factory()->defaults()
->has(Membership::factory()->for($mitglied)->for($woelfling))
->has(Membership::factory()->for($schnuppermitglied)->for($rover))
->create();
2023-07-24 16:55:07 +02:00
2024-01-28 11:42:32 +01:00
sleep(1);
$this->callFilter('member.index', ['activity_ids' => [$mitglied->id, 5, 6], 'subactivity_ids' => [$rover->id, 8, 9]])
->assertInertiaCount('data.data', 0);
}
public function testItIgnoresInactiveMemberships(): void
{
$mitglied = Activity::factory()->name('€ Mitglied')->create();
$woelfling = Subactivity::factory()->name('Wölfling')->create();
Member::factory()->defaults()->has(Membership::factory()->for($mitglied)->for($woelfling)->ended())->create();
sleep(1);
$this->callFilter('member.index', ['activity_ids' => [$mitglied->id]])
->assertInertiaCount('data.data', 0);
$this->callFilter('member.index', ['subactivity_ids' => [$woelfling->id]])
->assertInertiaCount('data.data', 0);
}
public function testItListensForMembershipDeletion(): void
{
$mitglied = Activity::factory()->name('€ Mitglied')->create();
$member = Member::factory()->defaults()->has(Membership::factory()->for($mitglied))->create();
$member->memberships->first()->delete();
sleep(1);
$this->callFilter('member.index', ['activity_ids' => [$mitglied->id]])
->assertInertiaCount('data.data', 0);
2023-07-24 16:55:07 +02:00
}
2024-01-29 00:13:03 +01:00
public function testItFiltersForMemberships(): void
{
$mitglied = Activity::factory()->create();
$woelfling = Subactivity::factory()->create();
$juffi = Subactivity::factory()->create();
$group = Group::factory()->create();
Member::factory()->defaults()->has(Membership::factory()->for($mitglied)->for($woelfling)->for($group))->create();
Member::factory()->defaults()->has(Membership::factory()->for($mitglied)->for($juffi)->for($group))->create();
Member::factory()->defaults()
->has(Membership::factory()->for($mitglied)->for($woelfling)->for($group))
->has(Membership::factory()->for($mitglied)->for($juffi)->for($group))
->create();
sleep(1);
$this->callFilter('member.index', ['memberships' => [
['group_ids' => [$group->id], 'activity_ids' => [$mitglied->id], 'subactivity_ids' => [$woelfling->id]]
]])->assertInertiaCount('data.data', 2);
$this->callFilter('member.index', ['memberships' => [
['group_ids' => [$group->id], 'activity_ids' => [$mitglied->id], 'subactivity_ids' => [$juffi->id]]
]])->assertInertiaCount('data.data', 2);
$this->callFilter('member.index', ['memberships' => [
['group_ids' => [$group->id], 'activity_ids' => [$mitglied->id], 'subactivity_ids' => [$juffi->id, $woelfling->id]],
]])->assertInertiaCount('data.data', 3);
$this->callFilter('member.index', ['memberships' => [
['group_ids' => [$group->id], 'activity_ids' => [$mitglied->id], 'subactivity_ids' => [$woelfling->id]],
['group_ids' => [$group->id], 'activity_ids' => [$mitglied->id], 'subactivity_ids' => [$juffi->id]],
]])->assertInertiaCount('data.data', 1);
}
public function testGroupOfMembershipsFilterCanBeEmpty(): void
{
$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
{
2024-01-26 14:52:33 +01:00
Member::factory()->defaults()
2023-12-19 02:00:42 +01:00
->has(InvoicePosition::factory()->for(Invoice::factory()))
2024-01-28 11:42:32 +01:00
->create(['firstname' => 'firstname']);
Member::factory()->defaults()->create(['firstname' => 'firstname']);
sleep(1);
$this->callFilter('member.index', ['search' => 'firstname', 'ausstand' => true])
->assertInertiaCount('data.data', 1);
}
public function testItIgnoresPaidInvoices(): void
{
Member::factory()->defaults()
->has(InvoicePosition::factory()->for(Invoice::factory()->status(InvoiceStatus::PAID)))
->create();
sleep(1);
$this->callFilter('member.index', ['ausstand' => true])
->assertInertiaCount('data.data', 0);
}
public function testItIncludesMembers(): void
{
$member = Member::factory()->defaults()->create(['birthday' => null, 'location' => '']);
sleep(1);
$this->callFilter('member.index', ['hasBirthday' => true, 'hasFullAddress' => false])
->assertInertiaCount('data.data', 0);
$this->callFilter('member.index', ['hasBirthday' => true, 'hasFullAddress' => false, 'include' => [$member->id]])
->assertInertiaCount('data.data', 1);
}
2024-01-28 11:42:32 +01:00
public function testItExcludesMembers(): void
{
$member = Member::factory()->defaults()->create(['birthday' => null]);
2024-01-28 11:42:32 +01:00
sleep(1);
$this->callFilter('member.index', ['hasBirthday' => false, 'exclude' => [$member->id]])
->assertInertiaCount('data.data', 0);
}
2024-08-28 22:12:05 +02:00
public function testItDisplaysActivityMeta(): void
{
$activity = Activity::factory()->inNami(5)->hasAttached(Subactivity::factory()->inNami(23)->name('Biber'))->name('€ Mitglied')->create();
$subactivity = $activity->subactivities->first();
$this->callFilter('member.index', [])
->assertInertiaPath("data.meta.formSubactivities.{$activity->id}.{$subactivity->id}", 'Biber')
->assertInertiaPath("data.meta.formActivities.{$activity->id}", '€ Mitglied')
->assertInertiaPath('data.meta.billKinds.0', ['id' => 'E-Mail', 'name' => 'E-Mail']);
}
public function testItDoesntDisplayActivitiesAndSubactivitiesNotInNami(): void
{
Activity::factory()->hasAttached(Subactivity::factory()->name('Biber'))->name('€ Mitglied')->create();
$this->callFilter('member.index', [])
->assertInertiaCount('data.meta.formCreateSubactivities', 0)
->assertInertiaCount('data.meta.formCreateActivities', 0);
}
}