Fixed: Deleting local memberships
This commit is contained in:
parent
2c0b9217ec
commit
37cbf860d0
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Member;
|
namespace App\Member;
|
||||||
|
|
||||||
use App\Activity;
|
use App\Activity;
|
||||||
|
use App\Nami\HasNamiField;
|
||||||
use App\Subactivity;
|
use App\Subactivity;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
@ -15,6 +16,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
class Membership extends Model
|
class Membership extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
use HasNamiField;
|
||||||
|
|
||||||
public $fillable = ['subactivity_id', 'activity_id', 'group_id', 'member_id', 'nami_id', 'from', 'to', 'promised_at'];
|
public $fillable = ['subactivity_id', 'activity_id', 'group_id', 'member_id', 'nami_id', 'from', 'to', 'promised_at'];
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,20 @@ class MembershipDestroyAction
|
||||||
public function handle(Member $member, Membership $membership, NamiSettings $settings): void
|
public function handle(Member $member, Membership $membership, NamiSettings $settings): void
|
||||||
{
|
{
|
||||||
$api = $settings->login();
|
$api = $settings->login();
|
||||||
|
|
||||||
|
if ($membership->hasNami) {
|
||||||
$settings->login()->deleteMembership(
|
$settings->login()->deleteMembership(
|
||||||
$member->nami_id,
|
$member->nami_id,
|
||||||
$api->membership($member->nami_id, $membership->nami_id)
|
$api->membership($member->nami_id, $membership->nami_id)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$membership->delete();
|
$membership->delete();
|
||||||
|
|
||||||
|
if ($membership->hasNami) {
|
||||||
$member->syncVersion();
|
$member->syncVersion();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function asController(Member $member, Membership $membership, ActionRequest $request, NamiSettings $settings): RedirectResponse
|
public function asController(Member $member, Membership $membership, ActionRequest $request, NamiSettings $settings): RedirectResponse
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,4 +54,22 @@ class DestroyTest extends TestCase
|
||||||
]);
|
]);
|
||||||
app(MembershipFake::class)->assertDeleted(6, 1300);
|
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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue