Fix PutMemberAction

This commit is contained in:
philipp lang 2023-02-06 00:24:57 +01:00
parent 329da67ad6
commit 150593b5cf
6 changed files with 18 additions and 42 deletions

View File

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

View File

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

View File

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

View File

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

@ -1 +1 @@
Subproject commit a2e5adfd4ce758a453f2ddbe2a25a88e9c932b0e
Subproject commit 5243b7341dc466fe1eccf9f0304caad14138418d

View File

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