adrema/tests/EndToEnd/Member/IndexTest.php

198 lines
7.9 KiB
PHP
Raw Permalink Normal View History

2021-07-17 15:58:38 +02:00
<?php
2024-02-02 01:41:25 +01:00
namespace Tests\EndToEnd\Member;
2021-07-17 15:58:38 +02:00
2022-03-20 16:33:56 +01:00
use App\Activity;
2024-08-30 20:06:10 +02:00
use App\Country;
use App\Group;
2021-07-17 15:58:38 +02:00
use App\Member\Member;
2022-03-20 16:33:56 +01:00
use App\Member\Membership;
use App\Subactivity;
2024-02-02 01:41:25 +01:00
use Tests\EndToEndTestCase;
2021-07-17 15:58:38 +02:00
2024-02-02 01:41:25 +01:00
class IndexTest extends EndToEndTestCase
2021-07-17 15:58:38 +02:00
{
2024-08-30 20:06:10 +02:00
public function setUp(): void
{
parent::setUp();
Country::factory()->create(['name' => 'Deutschland']);
}
2021-07-17 15:58:38 +02:00
public function testItGetsMembers(): void
{
2022-11-16 22:28:42 +01:00
$this->withoutExceptionHandling()->login()->loginNami();
$group = Group::factory()->create();
2023-10-13 15:48:29 +02:00
$member = Member::factory()->defaults()->for($group)
->create([
'firstname' => '::firstname::',
'address' => 'Kölner Str 3',
'zip' => 33333,
'location' => 'Hilden',
]);
2021-07-17 15:58:38 +02:00
2024-01-28 11:42:32 +01:00
sleep(1);
2024-06-27 17:50:18 +02:00
$response = $this->get('/member')->assertComponent('member/VIndex');
2022-02-12 00:41:52 +01:00
$this->assertInertiaHas('::firstname::', $response, 'data.data.0.firstname');
2023-05-09 01:34:19 +02:00
$this->assertInertiaHas(false, $response, 'data.data.0.has_nami');
2022-11-23 23:24:32 +01:00
$this->assertInertiaHas('Kölner Str 3, 33333 Hilden', $response, 'data.data.0.full_address');
$this->assertInertiaHas($group->id, $response, 'data.data.0.group_id');
2023-09-12 16:54:13 +02:00
$this->assertInertiaHas(null, $response, 'data.data.0.memberships');
2023-10-16 12:52:59 +02:00
$this->assertInertiaHas(url("/member/{$member->id}/membership"), $response, 'data.data.0.links.membership_index');
2023-12-17 21:13:52 +01:00
$this->assertInertiaHas(url("/member/{$member->id}/invoice-position"), $response, 'data.data.0.links.invoiceposition_index');
2023-10-18 01:11:36 +02:00
$this->assertInertiaHas(url("/member/{$member->id}/course"), $response, 'data.data.0.links.course_index');
2023-10-13 15:48:29 +02:00
$this->assertInertiaHas([
'id' => $member->subscription->id,
'name' => $member->subscription->name,
], $response, 'data.data.0.subscription');
2021-07-17 15:58:38 +02:00
}
2022-03-20 16:33:56 +01:00
2023-03-06 00:26:17 +01:00
public function testFieldsCanBeNull(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$group = Group::factory()->create();
Member::factory()->defaults()->for($group)->create([
'birthday' => null,
'address' => null,
'zip' => null,
'location' => null,
]);
2024-01-28 11:42:32 +01:00
sleep(1);
2023-03-06 00:26:17 +01:00
$response = $this->get('/member');
$this->assertInertiaHas(null, $response, 'data.data.0.birthday');
$this->assertInertiaHas(null, $response, 'data.data.0.address');
$this->assertInertiaHas(null, $response, 'data.data.0.zip');
$this->assertInertiaHas(null, $response, 'data.data.0.location');
}
2022-03-20 16:33:56 +01:00
public function testItShowsEfzForEfzMembership(): void
{
2022-11-16 22:28:42 +01:00
$this->withoutExceptionHandling()->login()->loginNami();
2022-03-20 16:33:56 +01:00
$member = Member::factory()
->defaults()
2022-11-16 22:28:42 +01:00
->has(Membership::factory()->in('€ LeiterIn', 455, 'Pfadfinder', 15))
2022-03-20 16:33:56 +01:00
->create(['lastname' => 'A']);
Member::factory()
->defaults()
2022-11-16 22:28:42 +01:00
->has(Membership::factory()->in('€ Mitglied', 456, 'Pfadfinder', 16))
2022-03-20 16:33:56 +01:00
->create(['lastname' => 'B']);
2024-03-07 21:24:12 +01:00
$emptyMember = Member::factory()
2022-03-20 16:33:56 +01:00
->defaults()
->create(['lastname' => 'C']);
2024-01-28 11:42:32 +01:00
sleep(1);
2022-03-20 16:33:56 +01:00
$response = $this->get('/member');
$this->assertInertiaHas(url("/member/{$member->id}/efz"), $response, 'data.data.0.efz_link');
2024-03-07 21:24:12 +01:00
$this->assertInertiaHas(url("/member/{$emptyMember->id}/efz"), $response, 'data.data.2.efz_link');
2022-09-06 01:25:04 +02:00
$this->assertInertiaHas(true, $response, 'data.data.0.is_leader');
$this->assertInertiaHas(false, $response, 'data.data.1.is_leader');
$this->assertInertiaHas(false, $response, 'data.data.2.is_leader');
2022-03-20 16:33:56 +01:00
}
2022-11-16 16:30:23 +01:00
2023-07-24 16:55:07 +02:00
public function testItHasNoEfzLinkWhenAddressIsMissing(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()
->defaults()
->has(Membership::factory()->in('€ LeiterIn', 455, 'Pfadfinder', 15))
->create(['address' => null]);
$response = $this->get('/member');
$this->assertInertiaHas(null, $response, 'data.data.0.efz_link');
}
2022-11-16 16:30:23 +01:00
public function testItShowsAgeGroupIcon(): void
{
2022-11-16 22:28:42 +01:00
$this->withoutExceptionHandling()->login()->loginNami();
2022-11-16 16:30:23 +01:00
$member = Member::factory()
->defaults()
2022-11-16 22:28:42 +01:00
->has(Membership::factory()->in('€ Mitglied', 123, 'Wölfling', 12))
2022-11-16 16:30:23 +01:00
->create();
2024-01-28 11:42:32 +01:00
sleep(1);
2022-11-16 16:30:23 +01:00
$response = $this->get('/member');
$this->assertInertiaHas('woelfling', $response, 'data.data.0.age_group_icon');
}
2023-07-24 16:55:07 +02:00
public function testAgeIsNullWhenBirthdayIsNull(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
2024-01-28 11:42:32 +01:00
Member::factory()->defaults()->create(['birthday' => null]);
2023-07-24 16:55:07 +02:00
$response = $this->get('/member');
$this->assertInertiaHas(null, $response, 'data.data.0.age');
$this->assertInertiaHas(null, $response, 'data.data.0.birthday');
}
2022-11-16 16:30:23 +01:00
public function testItShowsActivitiesAndSubactivities(): void
{
2022-11-16 22:28:42 +01:00
$this->withoutExceptionHandling()->login()->loginNami();
$activity = Activity::factory()->hasAttached(Subactivity::factory()->name('Biber'))->name('€ Mitglied')->create();
2022-11-16 16:30:23 +01:00
$subactivity = $activity->subactivities->first();
2024-01-28 11:42:32 +01:00
sleep(1);
$this->get('/member')
->assertInertiaPath("data.meta.formSubactivities.{$activity->id}.{$subactivity->id}", 'Biber')
->assertInertiaPath("data.meta.filterSubactivities.{$subactivity->id}", 'Biber')
->assertInertiaPath("data.meta.formActivities.{$activity->id}", '€ Mitglied');
2022-11-16 22:28:42 +01:00
}
2022-12-06 23:11:57 +01:00
public function testItCanFilterForBillKinds(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults()->emailBillKind()->create();
Member::factory()->defaults()->postBillKind()->create();
2023-03-14 23:27:15 +01:00
Member::factory()->defaults()->postBillKind()->create();
2022-12-06 23:11:57 +01:00
2024-01-28 11:42:32 +01:00
sleep(1);
$this->callFilter('member.index', ['bill_kind' => 'E-Mail'])
->assertInertiaCount('data.data', 1)
->assertInertiaPath('data.meta.filter.bill_kind', 'E-Mail');
$this->callFilter('member.index', ['bill_kind' => 'Post'])
->assertInertiaCount('data.data', 2);
2023-03-14 23:27:15 +01:00
}
2023-04-25 00:28:44 +02:00
public function testItCanFilterForGroups(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$group1 = Group::factory()->create();
$group2 = Group::factory()->create();
Member::factory()->defaults()->for($group1)->create();
Member::factory()->defaults()->for($group1)->create();
Member::factory()->defaults()->for($group1)->create();
2024-01-28 11:42:32 +01:00
sleep(1);
2023-06-15 00:12:20 +02:00
$oneResponse = $this->callFilter('member.index', ['group_ids' => [$group1->id]]);
$twoResponse = $this->callFilter('member.index', ['group_ids' => [$group2->id]]);
2023-04-25 00:28:44 +02:00
$this->assertCount(3, $this->inertia($oneResponse, 'data.data'));
$this->assertCount(0, $this->inertia($twoResponse, 'data.data'));
2023-06-15 00:12:20 +02:00
$this->assertInertiaHas([$group1->id], $oneResponse, 'data.meta.filter.group_ids');
2023-04-25 00:28:44 +02:00
}
public function testItLoadsGroups(): void
{
2024-01-26 15:33:12 +01:00
$this->withoutExceptionHandling();
2023-04-25 00:28:44 +02:00
$parent1 = Group::factory()->name('par1')->create();
$child1 = Group::factory()->name('ch1')->for($parent1, 'parent')->create();
$child2 = Group::factory()->name('ch2')->for($parent1, 'parent')->create();
$parent2 = Group::factory()->name('par2')->create();
$this->withoutExceptionHandling()->login()->loginNami(12345, 'password', $parent1);
2024-01-28 11:42:32 +01:00
sleep(1);
$response = $this->get('/member');
2024-01-26 15:33:12 +01:00
$response->assertOk();
2023-04-25 00:28:44 +02:00
$this->assertInertiaHas('par1', $response, 'data.meta.groups.0.name');
$this->assertInertiaHas('- ch1', $response, 'data.meta.groups.1.name');
$this->assertInertiaHas('- ch2', $response, 'data.meta.groups.2.name');
$this->assertInertiaHas('par2', $response, 'data.meta.groups.3.name');
}
2021-07-17 15:58:38 +02:00
}