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"]