From 37cbf860d01ac9399945d9c884517b980a3585b1 Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Fri, 17 Feb 2023 11:43:08 +0100 Subject: [PATCH] Fixed: Deleting local memberships --- app/Member/Membership.php | 2 ++ .../Actions/MembershipDestroyAction.php | 17 ++++++++++++----- tests/Feature/Membership/DestroyTest.php | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/Member/Membership.php b/app/Member/Membership.php index dc283ca9..bb8631e3 100644 --- a/app/Member/Membership.php +++ b/app/Member/Membership.php @@ -3,6 +3,7 @@ namespace App\Member; use App\Activity; +use App\Nami\HasNamiField; use App\Subactivity; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -15,6 +16,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; class Membership extends Model { use HasFactory; + use HasNamiField; public $fillable = ['subactivity_id', 'activity_id', 'group_id', 'member_id', 'nami_id', 'from', 'to', 'promised_at']; diff --git a/app/Membership/Actions/MembershipDestroyAction.php b/app/Membership/Actions/MembershipDestroyAction.php index 4fb30944..f6af4eae 100644 --- a/app/Membership/Actions/MembershipDestroyAction.php +++ b/app/Membership/Actions/MembershipDestroyAction.php @@ -16,12 +16,19 @@ class MembershipDestroyAction public function handle(Member $member, Membership $membership, NamiSettings $settings): void { $api = $settings->login(); - $settings->login()->deleteMembership( - $member->nami_id, - $api->membership($member->nami_id, $membership->nami_id) - ); + + if ($membership->hasNami) { + $settings->login()->deleteMembership( + $member->nami_id, + $api->membership($member->nami_id, $membership->nami_id) + ); + } + $membership->delete(); - $member->syncVersion(); + + if ($membership->hasNami) { + $member->syncVersion(); + } } public function asController(Member $member, Membership $membership, ActionRequest $request, NamiSettings $settings): RedirectResponse diff --git a/tests/Feature/Membership/DestroyTest.php b/tests/Feature/Membership/DestroyTest.php index ba02a9dd..2ec66291 100644 --- a/tests/Feature/Membership/DestroyTest.php +++ b/tests/Feature/Membership/DestroyTest.php @@ -54,4 +54,22 @@ class DestroyTest extends TestCase ]); app(MembershipFake::class)->assertDeleted(6, 1300); } + + public function testItDoesntReachNamiWhenMembershipIsLocal(): void + { + $this->withoutExceptionHandling(); + $member = Member::factory() + ->defaults() + ->for(Group::factory()->inNami(1400)) + ->has(Membership::factory()->in('€ Mitglied', 1, 'Rover', 6)) + ->inNami(6) + ->create(); + + $response = $this->from('/member')->delete("/member/{$member->id}/membership/{$member->memberships->first()->id}"); + + $response->assertRedirect('/member'); + $this->assertDatabaseMissing('memberships', [ + 'member_id' => $member->id, + ]); + } }