Fixed: Deleting local memberships

This commit is contained in:
Philipp Lang 2023-02-17 11:43:08 +01:00
parent 2c0b9217ec
commit 37cbf860d0
3 changed files with 32 additions and 5 deletions

View File

@ -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'];

View File

@ -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

View File

@ -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,
]);
}
}