Fix: Store membership for non nami member
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2024-04-19 11:12:41 +02:00
parent aa81843df1
commit 594c45aede
2 changed files with 19 additions and 2 deletions

View File

@ -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<string, array<int, string|In>>
*/

View File

@ -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<br>", "namierror&lt;br&gt;"]
* ["", "Erstellen der Mitgliedschaft fehlgeschlagen"]