diff --git a/app/Console/Commands/MemberResyncCommand.php b/app/Console/Commands/MemberResyncCommand.php index 622a0a36..db57ed9f 100644 --- a/app/Console/Commands/MemberResyncCommand.php +++ b/app/Console/Commands/MemberResyncCommand.php @@ -2,7 +2,7 @@ namespace App\Console\Commands; -use App\Actions\MemberPullAction; +use App\Actions\PullMemberAction; use App\Setting\NamiSettings; use Illuminate\Console\Command; use Zoomyboy\LaravelNami\Member as NamiMember; @@ -33,7 +33,7 @@ class MemberResyncCommand extends Command $api = $settings->login(); $api->search([])->each( - fn (NamiMember $member) => app(MemberPullAction::class)->api($api)->member($member->group_id, $member->id)->execute() + fn (NamiMember $member) => app(PullMemberAction::class)->api($api)->member($member->group_id, $member->id)->execute() ); return 0; diff --git a/app/Initialize/InitializeMembers.php b/app/Initialize/InitializeMembers.php index 7b11ff52..1647d675 100644 --- a/app/Initialize/InitializeMembers.php +++ b/app/Initialize/InitializeMembers.php @@ -2,7 +2,7 @@ namespace App\Initialize; -use App\Actions\MemberPullAction; +use App\Actions\PullMemberAction; use DB; use Zoomyboy\LaravelNami\Api; use Zoomyboy\LaravelNami\Member as NamiMember; @@ -21,7 +21,7 @@ class InitializeMembers $allMembers = collect([]); $this->api->search([])->each( - fn (NamiMember $member) => app(MemberPullAction::class)->api($this->api)->member($member->group_id, $member->id)->execute() + fn (NamiMember $member) => app(PullMemberAction::class)->api($this->api)->member($member->group_id, $member->id)->execute() ); } diff --git a/app/Member/Actions/NamiPutMemberAction.php b/app/Member/Actions/NamiPutMemberAction.php index 71270bc1..f27773e9 100644 --- a/app/Member/Actions/NamiPutMemberAction.php +++ b/app/Member/Actions/NamiPutMemberAction.php @@ -2,7 +2,7 @@ namespace App\Member\Actions; -use App\Actions\MemberPullAction; +use App\Actions\PullMemberAction; use App\Activity; use App\Confession; use App\Member\Member; @@ -18,7 +18,7 @@ class NamiPutMemberAction public function handle(Member $member, ?Activity $activity = null, ?Subactivity $subactivity = null): void { $api = app(NamiSettings::class)->login(); - $response = $api->putMember(NamiMember::from([ + $namiMember = NamiMember::from([ 'firstname' => $member->firstname, 'lastname' => $member->lastname, 'joinedAt' => $member->joined_at, @@ -43,15 +43,14 @@ class NamiPutMemberAction 'feeId' => $member->getNamiFeeId(), 'nationalityId' => $member->nationality->nami_id, 'groupId' => $member->group->nami_id, - 'first_activity_id' => $activity ? $activity->nami_id : null, - 'first_subactivity_id' => $subactivity ? $subactivity->nami_id : null, 'id' => $member->nami_id, 'version' => $member->version, 'keepdata' => false, - ])); - Member::withoutEvents(function () use ($response, $member, $api) { - $member->update(['nami_id' => $response['id']]); - app(MemberPullAction::class)->api($api)->member($member->group->nami_id, $member->nami_id)->execute(); + ]); + $response = $api->putMember($namiMember, $activity ? $activity->nami_id : null, $subactivity ? $subactivity->nami_id : null); + Member::withoutEvents(function () use ($response, $member) { + $member->update(['nami_id' => $response]); + app(PullMemberAction::class)->handle($member->group->nami_id, $member->nami_id); }); } } diff --git a/app/Member/Controllers/MemberResyncController.php b/app/Member/Controllers/MemberResyncController.php index ef103d5a..234d2fcc 100644 --- a/app/Member/Controllers/MemberResyncController.php +++ b/app/Member/Controllers/MemberResyncController.php @@ -2,7 +2,7 @@ namespace App\Member\Controllers; -use App\Actions\MemberPullAction; +use App\Actions\PullMemberAction; use App\Http\Controllers\Controller; use App\Member\Member; use App\Setting\NamiSettings; @@ -13,7 +13,7 @@ class MemberResyncController extends Controller public function __invoke(Member $member, NamiSettings $settings): RedirectResponse { if ($member->hasNami) { - app(MemberPullAction::class)->api($settings->login())->member($member->group->nami_id, $member->nami_id)->execute(); + app(PullMemberAction::class)->api($settings->login())->member($member->group->nami_id, $member->nami_id)->execute(); } return redirect()->route('member.edit', ['member' => $member])->success('Mitglied aktualisiert'); diff --git a/packages/laravel-nami b/packages/laravel-nami index a2e5adfd..5243b734 160000 --- a/packages/laravel-nami +++ b/packages/laravel-nami @@ -1 +1 @@ -Subproject commit a2e5adfd4ce758a453f2ddbe2a25a88e9c932b0e +Subproject commit 5243b7341dc466fe1eccf9f0304caad14138418d diff --git a/tests/Feature/Member/NamiPutMemberActionTest.php b/tests/Feature/Member/NamiPutMemberActionTest.php index df67b8fe..2da1f705 100644 --- a/tests/Feature/Member/NamiPutMemberActionTest.php +++ b/tests/Feature/Member/NamiPutMemberActionTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Member; -use App\Actions\MemberPullAction; +use App\Actions\PullMemberAction; use App\Activity; use App\Confession; use App\Country; @@ -16,6 +16,7 @@ use App\Payment\Subscription; use App\Region; use App\Subactivity; use Illuminate\Foundation\Testing\DatabaseTransactions; +use Phake; use Tests\TestCase; use Zoomyboy\LaravelNami\Fakes\MemberFake; @@ -35,7 +36,7 @@ class NamiPutMemberActionTest extends TestCase $group = Group::factory()->inNami(55)->create(); $confession = Confession::factory()->inNami(567)->create(['is_null' => true]); app(MemberFake::class)->createsSuccessfully(55, 993); - $this->stubIo(MemberPullAction::class, fn ($mock) => $mock); + $this->stubIo(PullMemberAction::class, fn ($mock) => $mock); $activity = Activity::factory()->hasAttached(Subactivity::factory()->name('Biber')->inNami(55))->name('Leiter')->inNami(6)->create(); $subactivity = $activity->subactivities->first(); @@ -59,30 +60,6 @@ class NamiPutMemberActionTest extends TestCase $this->assertDatabaseHas('members', [ 'nami_id' => 993, ]); - } - - public function testItMergesExistingData(): void - { - $this->withoutExceptionHandling()->login()->loginNami(); - $group = Group::factory()->inNami(55)->create(); - $confession = Confession::factory()->inNami(567)->create(['is_null' => true]); - $member = Member::factory() - ->defaults() - ->inNami(556) - ->create(); - $this->stubIo(MemberPullAction::class, fn ($mock) => $mock); - - app(MemberFake::class)->shows(55, 556, [ - 'missingkey' => 'missingvalue', - 'kontoverbindung' => ['a' => 'b'], - ])->updates(55, 556, ['id' => 556]); - - NamiPutMemberAction::run($member, null, null); - - app(MemberFake::class)->assertUpdated(55, 556, [ - 'kontoverbindung' => '{"a":"b"}', - 'missingkey' => 'missingvalue', - ]); - $this->assertDatabaseHas('members', ['nami_id' => 556]); + Phake::verify(app(PullMemberAction::class))->handle(55, 993); } }