From 594c45aede9f84675b1a4dc10bdad1d6307f3a78 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 19 Apr 2024 11:12:41 +0200 Subject: [PATCH] Fix: Store membership for non nami member --- app/Membership/Actions/MembershipStoreAction.php | 9 +++++++-- tests/Feature/Membership/StoreTest.php | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/Membership/Actions/MembershipStoreAction.php b/app/Membership/Actions/MembershipStoreAction.php index c2bfd06f..d3097c48 100644 --- a/app/Membership/Actions/MembershipStoreAction.php +++ b/app/Membership/Actions/MembershipStoreAction.php @@ -33,7 +33,7 @@ class MembershipStoreAction $subactivity = $subactivity ?: new Subactivity(['nami_id' => null, 'id' => null]); - if ($activity->hasNami && ($subactivity->id === null || $subactivity->hasNami)) { + if ($this->syncable($member, $activity, $subactivity)) { try { $namiId = app(NamiSettings::class)->login()->putMembership($member->nami_id, NamiMembership::from([ 'startsAt' => $from, @@ -55,7 +55,7 @@ class MembershipStoreAction 'nami_id' => $namiId ?? null, ]); - if ($activity->hasNami && ($subactivity->id === null || $subactivity->hasNami)) { + if ($this->syncable($member, $activity, $subactivity)) { $member->syncVersion(); } @@ -64,6 +64,11 @@ class MembershipStoreAction return $membership; } + protected function syncable(Member $member, Activity $activity, ?Subactivity $subactivity): bool + { + return $activity->hasNami && ($subactivity->id === null || $subactivity->hasNami) && $member->hasNami; + } + /** * @return array> */ diff --git a/tests/Feature/Membership/StoreTest.php b/tests/Feature/Membership/StoreTest.php index e9031bb1..11a71432 100644 --- a/tests/Feature/Membership/StoreTest.php +++ b/tests/Feature/Membership/StoreTest.php @@ -247,6 +247,18 @@ class StoreTest extends TestCase ]); } + public function testItStoresNamiActivityAndSubactivityForNonNamiMember(): void + { + $this->withoutExceptionHandling(); + $member = Member::factory()->defaults()->create(); + $activity = Activity::factory()->hasAttached(Subactivity::factory()->inNami(7))->inNami(6)->create(); + + $this->post( + "/member/{$member->id}/membership", + MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->group($member->group)->create() + )->assertOk(); + } + /** * @testWith ["namierror
", "namierror<br>"] * ["", "Erstellen der Mitgliedschaft fehlgeschlagen"]