From 55b3bc7fe9cbbecbe3da744545b378e045612da3 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 12 Jun 2025 16:55:16 +0200 Subject: [PATCH] Fix tests --- app/Member/Actions/MemberShowAction.php | 24 +- app/Member/MemberResource.php | 12 +- phpstan.neon | 5 - tests/Feature/Member/CreateTest.php | 5 - tests/Feature/Member/ShowTest.php | 343 +++++++++++++++--------- tests/TestCase.php | 12 + 6 files changed, 241 insertions(+), 160 deletions(-) diff --git a/app/Member/Actions/MemberShowAction.php b/app/Member/Actions/MemberShowAction.php index f3b4b0ad..a1671d60 100644 --- a/app/Member/Actions/MemberShowAction.php +++ b/app/Member/Actions/MemberShowAction.php @@ -17,19 +17,19 @@ class MemberShowAction */ public function handle(Member $member): array { + $member = Member::withPendingPayment()->with([ + 'memberships.activity', + 'memberships.subactivity', + 'invoicePositions.invoice', + 'nationality', + 'region', + 'subscription', + 'courses.course', + 'bankAccount', + ])->find($member->id); + return [ - 'data' => new MemberResource( - $member - ->load([ - 'memberships.activity', - 'memberships.subactivity', - 'invoicePositions.invoice', - 'nationality', - 'region', - 'subscription', - 'courses.course' - ]) - ), + 'data' => new MemberResource($member), 'meta' => MemberResource::meta(), ]; } diff --git a/app/Member/MemberResource.php b/app/Member/MemberResource.php index cc185dd3..b7efba56 100644 --- a/app/Member/MemberResource.php +++ b/app/Member/MemberResource.php @@ -138,7 +138,7 @@ class MemberResource extends JsonResource return [ 'filterActivities' => Activity::where('is_filterable', true)->get()->map(fn($a) => ['id' => $a->id, 'name' => $a->name]), 'filterSubactivities' => Subactivity::where('is_filterable', true)->get()->map(fn($a) => ['id' => $a->id, 'name' => $a->name]), - 'formActivities' => $activities->pluck('name', 'id'), + 'formActivities' => $activities->map(fn($a) => ['id' => $a->id, 'name' => $a->name]), 'formSubactivities' => $activities->map(function (Activity $activity) { return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id]; })->pluck('subactivities', 'id'), @@ -148,11 +148,11 @@ class MemberResource extends JsonResource })->pluck('subactivities', 'id'), 'groups' => NestedGroup::cacheForSelect(), 'filter' => FilterScope::fromRequest(request()->input('filter', '')), - 'courses' => Course::pluck('name', 'id'), - 'regions' => Region::forSelect(), - 'subscriptions' => Subscription::pluck('name', 'id'), - 'countries' => Country::pluck('name', 'id'), - 'genders' => Gender::pluck('name', 'id'), + 'courses' => Course::get()->map(fn($a) => ['id' => $a->id, 'name' => $a->name]), + 'regions' => Region::get()->map(fn($a) => ['id' => $a->id, 'name' => $a->name]), + 'subscriptions' => Subscription::get()->map(fn($a) => ['id' => $a->id, 'name' => $a->name]), + 'countries' => Country::get()->map(fn($c) => ['id' => $c->id, 'name' => $c->name]), + 'genders' => Gender::get()->map(fn($c) => ['id' => $c->id, 'name' => $c->name]), 'billKinds' => BillKind::forSelect(), 'nationalities' => Nationality::pluck('name', 'id'), 'members' => Member::ordered()->get()->map(fn($member) => ['id' => $member->id, 'name' => $member->fullname]), diff --git a/phpstan.neon b/phpstan.neon index 3d85785d..0271ef9e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -68,11 +68,6 @@ parameters: count: 1 path: app/Member/MemberRequest.php - - - message: "#^Method App\\\\Membership\\\\MembershipResource\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: app/Membership/MembershipResource.php - - message: "#^Method App\\\\Payment\\\\SubscriptionResource\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 diff --git a/tests/Feature/Member/CreateTest.php b/tests/Feature/Member/CreateTest.php index a2098688..3e02bec1 100644 --- a/tests/Feature/Member/CreateTest.php +++ b/tests/Feature/Member/CreateTest.php @@ -33,11 +33,6 @@ class CreateTest extends TestCase $this->assertInertiaHas(['name' => 'E-Mail', 'id' => 'E-Mail'], $response, 'meta.billKinds.0'); $this->assertInertiaHas([ - 'efz' => null, - 'ps_at' => null, - 'more_ps_at' => null, - 'without_education_at' => null, - 'without_efz_at' => null, 'address' => '', ], $response, 'meta.default'); } diff --git a/tests/Feature/Member/ShowTest.php b/tests/Feature/Member/ShowTest.php index 63efc7ab..ff3eb458 100644 --- a/tests/Feature/Member/ShowTest.php +++ b/tests/Feature/Member/ShowTest.php @@ -2,174 +2,253 @@ namespace Tests\Feature\Member; +use App\Activity; +use App\Confession; use App\Country; use App\Course\Models\Course; use App\Course\Models\CourseMember; use App\Gender; use App\Group; +use App\Invoice\BillKind; use App\Invoice\Models\Invoice; use App\Invoice\Models\InvoicePosition; -use App\Member\Data\MembershipData; use App\Member\Member; +use App\Member\MemberResource; use App\Member\Membership; use App\Nationality; use App\Payment\Subscription; use App\Region; +use App\Subactivity; use Carbon\Carbon; use Illuminate\Foundation\Testing\DatabaseTransactions; uses(DatabaseTransactions::class); -covers(MembershipData::class); beforeEach(function () { Country::factory()->create(['name' => 'Deutschland']); }); -it('testItShowsSingleMember', function () { +mutates(MemberResource::class); + +it('shows courses', function () { + $this->withoutExceptionHandling()->login()->loginNami(); + $member = Member::factory() + ->defaults() + ->has( + CourseMember::factory() + ->for(Course::factory()->name(' Baustein 2e - Gewalt gegen Kinder und Jugendliche: Vertiefung, Prävention ')) + ->state(['organizer' => 'DPSG', 'event_name' => 'Wochenende', 'completed_at' => '2022-03-03']), + 'courses' + ) + ->create(); + + $this->get("/member/{$member->id}") + ->assertInertiaPath('data.courses.0.organizer', 'DPSG') + ->assertInertiaPath('data.courses.0.event_name', 'Wochenende') + ->assertInertiaPath('data.courses.0.completed_at_human', '03.03.2022') + ->assertInertiaPath('data.courses.0.course.name', ' Baustein 2e - Gewalt gegen Kinder und Jugendliche: Vertiefung, Prävention ') + ->assertInertiaPath('data.courses.0.course.short_name', '2e'); +}); + +it('shows default', function () { + $this->withoutExceptionHandling()->login()->loginNami(); + $activity = Activity::factory()->name('€ Mitglied')->create(); + $subactivity = Subactivity::factory()->name('Jungpfadfinder')->create(); + $activity->subactivities()->attach($subactivity); + $course = Course::factory()->name('LL')->create(); + $region = Region::factory()->name('LLa')->create(); + $member = Member::factory()->male()->defaults()->create(); + + $this->get("/member/{$member->id}") + ->assertInertiaPath('meta.default.address', '') + ->assertInertiaPath('meta.filterActivities.0.name', '€ Mitglied') + ->assertInertiaPath('meta.filterActivities.0.id', $activity->id) + ->assertInertiaPath('meta.filterSubactivities.0.name', 'Jungpfadfinder') + ->assertInertiaPath('meta.filterSubactivities.0.id', $subactivity->id) + ->assertInertiaPath('meta.formActivities.0.name', '€ Mitglied') + ->assertInertiaPath('meta.formActivities.0.id', $activity->id) + ->assertInertiaPath("meta.formSubactivities.{$activity->id}.{$subactivity->id}", "Jungpfadfinder") + ->assertInertiaPath('meta.default.has_nami', false) + ->assertInertiaPath('meta.default.send_newspaper', false) + ->assertInertiaPath('meta.groups.0.id', $member->group->id) + ->assertInertiaPath('meta.default.fax', '') + ->assertInertiaPath('meta.filter.search', '') + ->assertInertiaPath('meta.billKinds.0.id', 'E-Mail') + ->assertInertiaPath('meta.courses.0.id', $course->id) + ->assertInertiaPath('meta.courses.0.name', 'LL') + ->assertInertiaPath('meta.regions.0.name', 'LLa') + ->assertInertiaPath('meta.regions.0.id', $region->id) + ->assertInertiaPath('meta.subscriptions.0.id', $member->subscription->id) + ->assertInertiaPath('meta.subscriptions.0.name', $member->subscription->name) + ->assertInertiaPath('meta.links.create', route('member.create')) + ->assertInertiaPath('meta.links.index', route('member.index')) + ->assertInertiaPath('meta.countries.0.id', $member->country->id) + ->assertInertiaPath('meta.countries.0.name', $member->country->name) + ->assertInertiaPath('meta.genders.0.id', $member->gender->id) + ->assertInertiaPath('meta.genders.0.name', $member->gender->name) + ->assertInertiaPath('meta.default.bank_account.iban', '') + ->assertInertiaPath('meta.default_membership_filter.group_ids', []) + ->assertInertiaPath('meta.default_membership_filter.activity_ids', []) + ->assertInertiaPath('meta.default_membership_filter.subactivity_ids', []) + ->assertInertiaPath('meta.default.bank_account.bic', '') + ->assertInertiaPath('meta.default.bank_account.blz', '') + ->assertInertiaPath('meta.default.bank_account.bank_name', '') + ->assertInertiaPath('meta.default.bank_account.person', '') + ->assertInertiaPath('meta.default.bank_account.account_number', '') + ->assertInertiaPath('meta.default.letter_address', '') + ->assertInertiaPath('meta.default.email', '') + ->assertInertiaPath('meta.default.has_vk', false) + ->assertInertiaPath('meta.default.has_svk', false) + ->assertInertiaPath('meta.default.multiply_pv', false) + ->assertInertiaPath('meta.default.multiply_more_pv', false) + ->assertInertiaPath('meta.default.email_parents', '') + ->assertInertiaPath('meta.default.children_phone', '') + ->assertInertiaPath('meta.default.work_phone', '') + ->assertInertiaPath('meta.default.mobile_phone', '') + ->assertInertiaPath('meta.default.main_phone', '') + ->assertInertiaPath('meta.default.other_country', '') + ->assertInertiaPath('meta.default.birthday', '') + ->assertInertiaPath('meta.default.location', '') + ->assertInertiaPath('meta.default.zip', '') + ->assertInertiaPath('meta.default.address', '') + ->assertInertiaPath('meta.default.further_address', '') + ->assertInertiaPath('meta.default.firstname', '') + ->assertInertiaPath('meta.default.comment', '') + ->assertInertiaPath('meta.default.joined_at', now()->format('Y-m-d')) + ->assertInertiaPath('meta.default.lastname', '') + ->assertInertiaPath('meta.default.ps_at', null) + ->assertInertiaPath('meta.default.more_ps_at', null) + ->assertInertiaPath('meta.default.without_education_at', null) + ->assertInertiaPath('meta.default.without_efz_at', null) + ->assertInertiaPath('meta.default.efz', null); +}); + +it('shows efz link', function () { + $this->withoutExceptionHandling()->login()->loginNami(); + $member = Member::factory()->defaults()->create(); + + $this->get("/member/{$member->id}") + ->assertInertiaPath('data.efz_link', route('efz', $member)); +}); + +it('shows memberships', function () { Carbon::setTestNow(Carbon::parse('2006-01-01 15:00:00')); $this->withoutExceptionHandling()->login()->loginNami(); $member = Member::factory() ->defaults() ->for(Group::factory()->name('Stamm Beispiel')) - ->has(Membership::factory()->promise(now())->in('€ LeiterIn', 5, 'Jungpfadfinder', 88)->from('2022-11-19')) - ->has(InvoicePosition::factory()->for(Invoice::factory())->price(1050)->description('uu')) - ->for(Gender::factory()->male()) - ->for(Region::factory()->name('NRW')) - ->postBillKind() - ->inNami(123) - ->for(Subscription::factory()->name('Sub')->forFee()) - ->has(CourseMember::factory()->for(Course::factory()->name(' Baustein 2e - Gewalt gegen Kinder und Jugendliche: Vertiefung, Prävention '))->state(['organizer' => 'DPSG', 'event_name' => 'Wochenende', 'completed_at' => '2022-03-03']), 'courses') - ->create([ - 'birthday' => '1991-04-20', - 'address' => 'Itterstr 3', - 'zip' => '42719', - 'location' => 'Solingen', - 'firstname' => 'Max', - 'lastname' => 'Muster', - 'other_country' => 'other', - 'main_phone' => '+49 212 1266775', - 'mobile_phone' => '+49 212 1266776', - 'work_phone' => '+49 212 1266777', - 'children_phone' => '+49 212 1266778', - 'email' => 'a@b.de', - 'email_parents' => 'b@c.de', - 'fax' => '+49 212 1255674', - 'efz' => '2022-09-20', - 'ps_at' => '2022-04-20', - 'more_ps_at' => '2022-06-02', - 'recertified_at' => '2022-06-13', - 'without_education_at' => '2022-06-03', - 'without_efz_at' => '2022-06-04', - 'has_vk' => true, - 'has_svk' => true, - 'multiply_pv' => true, - 'multiply_more_pv' => true, - 'send_newspaper' => true, - 'joined_at' => '2022-06-11', - 'mitgliedsnr' => 998, - 'lon' => 19.05, - 'lat' => 14.053, - ]); + ->has(Membership::factory()->promise(now())->in('€ LeiterIn', 5, 'Jungpfadfinder', 88)->from('2005-11-19')) + ->create(); - $response = $this->get("/member/{$member->id}"); - - $this->assertInertiaHas([ - 'birthday_human' => '20.04.1991', - 'age' => 14, - 'group_name' => 'Stamm Beispiel', - 'full_address' => 'Itterstr 3, 42719 Solingen', - 'region' => ['name' => 'NRW'], - 'other_country' => 'other', - 'main_phone' => '+49 212 1266775', - 'mobile_phone' => '+49 212 1266776', - 'work_phone' => '+49 212 1266777', - 'children_phone' => '+49 212 1266778', - 'email' => 'a@b.de', - 'email_parents' => 'b@c.de', - 'fax' => '+49 212 1255674', - 'fullname' => 'Herr Max Muster', - 'efz_human' => '20.09.2022', - 'ps_at_human' => '20.04.2022', - 'more_ps_at_human' => '02.06.2022', - 'without_education_at_human' => '03.06.2022', - 'without_efz_at_human' => '04.06.2022', - 'recertified_at_human' => '13.06.2022', - 'has_vk' => true, - 'has_svk' => true, - 'multiply_pv' => true, - 'multiply_more_pv' => true, - 'has_nami' => true, - 'nami_id' => 123, - 'send_newspaper' => true, - 'joined_at_human' => '11.06.2022', - 'bill_kind_name' => 'Post', - 'mitgliedsnr' => 998, - 'lon' => 19.05, - 'lat' => 14.053, - 'subscription' => [ - 'name' => 'Sub', - ], - ], $response, 'data'); - $this->assertInertiaHas([ - 'id' => $member->memberships->first()->id, - 'from' => ['human' => '19.11.2022', 'raw' => '2022-11-19'], - 'promised_at' => ['human' => now()->format('d.m.Y'), 'raw' => now()->format('Y-m-d')], - 'activity' => [ - 'name' => '€ LeiterIn', - 'id' => $member->memberships->first()->activity->id, - ], - 'subactivity' => [ - 'name' => 'Jungpfadfinder', - 'id' => $member->memberships->first()->subactivity->id, - ] - ], $response, 'data.memberships.0'); - - $this->assertInertiaHas([ - 'organizer' => 'DPSG', - 'event_name' => 'Wochenende', - 'completed_at_human' => '03.03.2022', - 'course' => [ - 'name' => ' Baustein 2e - Gewalt gegen Kinder und Jugendliche: Vertiefung, Prävention ', - 'short_name' => '2e', - ], - ], $response, 'data.courses.0'); - $this->assertInertiaHas([ - 'description' => 'uu', - 'price_human' => '10,50 €', - 'invoice' => [ - 'status' => 'Neu', - ] - ], $response, 'data.invoicePositions.0'); + $this->get("/member/{$member->id}") + ->assertInertiaPath('data.age_group_icon', 'jungpfadfinder') + ->assertInertiaPath('data.is_leader', true) + ->assertInertiaPath('data.memberships.0.id', $member->memberships->first()->id) + ->assertInertiaPath('data.memberships.0.from.human', '19.11.2005') + ->assertInertiaPath('data.memberships.0.from.raw', '2005-11-19') + ->assertInertiaPath('data.memberships.0.promised_at.human', now()->format('d.m.Y')) + ->assertInertiaPath('data.memberships.0.promised_at.raw', now()->format('Y-m-d')) + ->assertInertiaPath('data.memberships.0.activity.name', '€ LeiterIn') + ->assertInertiaPath('data.memberships.0.activity.id', $member->memberships->first()->activity->id) + ->assertInertiaPath('data.memberships.0.subactivity.name', 'Jungpfadfinder') + ->assertInertiaPath('data.memberships.0.subactivity.id', $member->memberships->first()->subactivity->id); }); -it('testItShowsMinimalSingleMember', function () { +it('shows that member is not a leader', function () { + $this->withoutExceptionHandling()->login()->loginNami(); + $member = Member::factory()->defaults()->create(); + + $this->get("/member/{$member->id}") + ->assertInertiaPath('data.is_leader', false); +}); + +it('shows links', function () { + $this->withoutExceptionHandling()->login()->loginNami(); + $member = Member::factory()->defaults()->create(); + + $this->get("/member/{$member->id}") + ->assertInertiaPath('data.links.edit', route('member.edit', $member)) + ->assertInertiaPath('data.links.show', route('member.show', $member)) + ->assertInertiaPath('data.links.invoiceposition_index', route('member.invoice-position.index', $member)) + ->assertInertiaPath('data.links.membership_index', route('member.membership.index', $member)) + ->assertInertiaPath('data.links.course_index', route('member.course.index', $member)); +}); + +it('shows invoice positions', function () { + Carbon::setTestNow(Carbon::parse('2006-01-01 15:00:00')); + + $this->withoutExceptionHandling()->login()->loginNami(); + $member = Member::factory() + ->defaults() + ->has(InvoicePosition::factory()->for(Invoice::factory())->price(1050)->description('uu')) + ->create(); + + $this->get("/member/{$member->id}") + ->assertInertiaPath('data.pending_payment', '10,50 €') + ->assertInertiaPath('data.invoicePositions.0.description', 'uu') + ->assertInertiaPath('data.invoicePositions.0.price_human', '10,50 €') + ->assertInertiaPath('data.invoicePositions.0.invoice.status', 'Neu'); +}); + +it('shows member single', function (array $attributes, array $expect) { + Carbon::setTestNow(Carbon::parse('2006-01-01 15:00:00')); $this->withoutExceptionHandling()->login()->loginNami(); $member = Member::factory() ->for(Group::factory()) ->for(Nationality::factory()->name('deutsch')) ->for(Subscription::factory()->forFee()) - ->create(['firstname' => 'Max', 'lastname' => 'Muster', 'has_vk' => false, 'has_svk' => false]); + ->create($attributes); - $response = $this->get("/member/{$member->id}"); - - $this->assertInertiaHas([ - 'region' => ['name' => '-- kein --'], - 'fullname' => 'Max Muster', - 'nationality' => [ - 'name' => 'deutsch', - ], - 'efz_human' => null, - 'ps_at_human' => null, - 'more_ps_at_human' => null, - 'without_education_at_human' => null, - 'without_efz_at_human' => null, - 'has_vk' => false, - 'has_svk' => false, - 'multiply_pv' => false, - 'multiply_more_pv' => false, - ], $response, 'data'); -}); + $this->get("/member/{$member->id}") + ->assertInertiaPath('data.id', $member->id) + ->assertInertiaPathArray($expect); +})->with([ + fn() => [['region_id' => Region::factory()->name('UUU')->create()->id], ['data.region.name' => 'UUU', 'data.region.id' => Region::first()->id, 'data.region_id' => Region::first()->id]], + fn() => [['confession_id' => Confession::factory()->create(['name' => 'UUU'])->id], ['data.confession_id' => Confession::firstWhere('name', 'UUU')->id]], + fn() => [['nationality_id' => Nationality::factory()->name('UUU')->create()->id], ['data.nationality.name' => 'UUU', 'data.nationality_id' => Nationality::first()->id, 'data.nationality.id' => Nationality::first()->id]], + fn() => [['group_id' => Group::factory()->name('UUU')->create()->id], ['data.group_name' => 'UUU', 'data.group_id' => Group::firstWhere('name', 'UUU')->id]], + fn() => [['bill_kind' => BillKind::EMAIL->value], ['data.bill_kind_name' => 'E-Mail', 'data.bill_kind' => 'E-Mail']], + fn() => [['subscription_id' => Subscription::factory()->name('Sub')->forFee()->create()], ['data.subscription.name' => 'Sub', 'data.subscription_id' => Subscription::first()->id]], + fn() => [['country_id' => Country::factory()->create(['name' => 'Sub'])->id], ['data.country_id' => Country::firstWhere('name', 'Sub')->id]], + fn() => [['firstname' => 'Max', 'lastname' => 'Muster', 'gender_id' => Gender::factory()->male()->create()->id], ['data.firstname' => 'Max', 'data.lastname' => 'Muster', 'data.fullname' => 'Herr Max Muster', 'data.gender_id' => Gender::first()->id]], + [['firstname' => 'Max', 'lastname' => 'Muster', 'gender_id' => null], ['data.fullname' => 'Max Muster']], + [['other_country' => 'other', 'further_address' => 'other', 'letter_address' => 'A'], ['data.other_country' => 'other', 'data.further_address' => 'other', 'data.letter_address' => 'A']], + [['gender_id' => null], ['data.gender_name' => 'keine Angabe']], + [['salutation' => 'Dr'], ['data.salutation' => 'Dr']], + [['comment' => 'Com'], ['data.comment' => 'Com']], + [['birthday' => null], ['data.birthday' => null, 'data.birthday_human' => null]], + [[], ['data.bank_account.iban' => null]], + [ + ['efz' => null, 'ps_at' => null, 'ps_at' => null, 'more_ps_at' => null, 'has_svk' => false, 'has_vk' => false, 'has_svk' => true], + ['data.efz_human' => null, 'data.ps_at_human' => null, 'data.ps_at_human' => null, 'data.more_ps_at_human' => null, 'data.has_svk' => false, 'data.has_vk' => false, 'data.has_svk' => true] + ], + [ + ['has_vk' => true, 'multiply_more_pv' => false, 'without_efz_at' => null, 'without_education_at' => null], + ['data.has_vk' => true, 'data.multiply_more_pv' => false, 'data.without_efz_at_human' => null, 'data.without_education_at_human' => null] + ], + [ + ['main_phone' => '+49 212 1266775', 'mobile_phone' => '+49 212 1266776', 'work_phone' => '+49 212 1266777', 'children_phone' => '+49 212 1266778'], + ['data.main_phone' => '+49 212 1266775', 'data.mobile_phone' => '+49 212 1266776', 'data.work_phone' => '+49 212 1266777', 'data.children_phone' => '+49 212 1266778'] + ], + [ + ['efz' => '2022-09-20', 'ps_at' => '2022-04-20', 'more_ps_at' => '2022-06-02', 'without_education_at' => '2022-06-03', 'without_efz_at' => '2022-06-04'], + ['data.efz' => '2022-09-20', 'data.efz_human' => '20.09.2022', 'data.ps_at' => '2022-04-20', 'data.more_ps_at' => '2022-06-02', 'data.without_education_at' => '2022-06-03', 'data.without_efz_at' => '2022-06-04', 'data.ps_at_human' => '20.04.2022', 'data.more_ps_at_human' => '02.06.2022', 'data.without_education_at_human' => '03.06.2022', 'data.without_efz_at_human' => '04.06.2022'] + ], + [['recertified_at' => '2022-06-13'], ['data.recertified_at_human' => '13.06.2022', 'data.recertified_at' => '2022-06-13']], + [['multiply_pv' => true, 'multiply_more_pv' => true], ['data.multiply_pv' => true, 'data.multiply_more_pv' => true]], + [ + ['email' => 'a@b.de', 'email_parents' => 'b@c.de', 'fax' => '+49 212 1255674'], + ['data.email' => 'a@b.de', 'data.email_parents' => 'b@c.de', 'data.fax' => '+49 212 1255674'] + ], + [['nami_id' => 123], ['data.nami_id' => 123, 'data.has_nami' => true]], + [['send_newspaper' => true], ['data.send_newspaper' => true]], + [['address' => 'Itterstr 3', 'location' => 'Solingen', 'zip' => '42719'], ['data.location' => 'Solingen', 'data.address' => 'Itterstr 3', 'data.zip' => '42719', 'data.full_address' => 'Itterstr 3, 42719 Solingen']], + [['lon' => 19.05, 'lat' => 14.053], ['data.lon' => 19.05, 'data.lat' => 14.053]], + [['birthday' => '1991-04-20'], ['data.birthday' => '1991-04-20', 'data.birthday_human' => '20.04.1991', 'data.age' => 14]], + [['joined_at' => '2022-06-11'], ['data.joined_at' => '2022-06-11', 'data.joined_at_human' => '11.06.2022']], + [['mitgliedsnr' => 998, 'keepdata' => true], ['data.mitgliedsnr' => 998, 'data.keepdata' => true]], +]); it('testItShowsIfMembershipIsActive', function (Carbon $from, ?Carbon $to, bool $isActive) { $this->withoutExceptionHandling()->login()->loginNami(); diff --git a/tests/TestCase.php b/tests/TestCase.php index dec5fdb2..6731b997 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -119,12 +119,24 @@ class TestCase extends BaseTestCase /** @var TestResponse */ $response = $this; $props = data_get($response->viewData('page'), 'props'); + Assert::assertTrue(Arr::has($props, $path), 'Failed that key ' . $path . ' is in Response.'); Assert::assertNotNull($props); $json = new AssertableJsonString($props); $json->assertPath($path, $value); return $this; }); + TestResponse::macro('assertInertiaPathArray', function ($arr) { + /** @var TestResponse */ + $response = $this; + + foreach ($arr as $key => $value) { + $response->assertInertiaPath($key, $value); + } + + return $response; + }); + TestResponse::macro('assertInertiaCount', function ($path, $count) { /** @var TestResponse */ $response = $this;