Fix UpdateTest

This commit is contained in:
philipp lang 2024-08-28 22:31:35 +02:00
parent aac47190e5
commit 12dd1f7f64
2 changed files with 24 additions and 33 deletions

View File

@ -4,6 +4,7 @@ namespace App\Member;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Setting\NamiSettings; use App\Setting\NamiSettings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Inertia\Response; use Inertia\Response;
@ -34,14 +35,14 @@ class MemberController extends Controller
return redirect()->route('member.index'); return redirect()->route('member.index');
} }
public function update(Member $member, MemberRequest $request): RedirectResponse public function update(Member $member, MemberRequest $request): JsonResponse
{ {
try { try {
$request->persistUpdate($member); $request->persistUpdate($member);
} catch (ConflictException $e) { } catch (ConflictException $e) {
return redirect()->route('member.edit', ['member' => $member, 'conflict' => '1']); return response()->json([], 409);
} }
return redirect()->route('member.index'); return response()->json([]);
} }
} }

View File

@ -30,11 +30,8 @@ class UpdateTest extends TestCase
$this->fakeRequest(); $this->fakeRequest();
NamiPutMemberAction::allowToRun(); NamiPutMemberAction::allowToRun();
$response = $this $this->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true]));
->from("/member/{$member->id}")
->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true]));
$response->assertRedirect('/member');
NamiPutMemberAction::spy()->shouldHaveReceived('handle')->withArgs( NamiPutMemberAction::spy()->shouldHaveReceived('handle')->withArgs(
fn (Member $memberParam, ?Activity $activityParam, ?Subactivity $subactivityParam) => $memberParam->is($member) fn (Member $memberParam, ?Activity $activityParam, ?Subactivity $subactivityParam) => $memberParam->is($member)
&& null === $activityParam && null === $activityParam
@ -49,11 +46,8 @@ class UpdateTest extends TestCase
$member->update(['version' => 43]); $member->update(['version' => 43]);
$this->fakeRequest(); $this->fakeRequest();
$response = $this $this->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true, 'firstname' => '::firstname::']))
->from("/member/{$member->id}") ->assertStatus(409);
->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true, 'firstname' => '::firstname::']));
$response->assertRedirect("/member/{$member->id}/edit?conflict=1");
} }
public function testItUpdatesPhoneNumber(): void public function testItUpdatesPhoneNumber(): void
@ -99,9 +93,7 @@ class UpdateTest extends TestCase
$member = $this->member(['nami_id' => null]); $member = $this->member(['nami_id' => null]);
$this->fakeRequest(); $this->fakeRequest();
$response = $this $this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
->from("/member/{$member->id}")
->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
'other_country' => 'englisch', 'other_country' => 'englisch',
])); ]));
@ -158,9 +150,7 @@ class UpdateTest extends TestCase
$member = $this->member(['nami_id' => null]); $member = $this->member(['nami_id' => null]);
$this->fakeRequest(); $this->fakeRequest();
$response = $this $this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
->from("/member/{$member->id}")
->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
'ps_at' => '2021-02-01', 'ps_at' => '2021-02-01',
'more_ps_at' => '2021-02-02', 'more_ps_at' => '2021-02-02',
'has_svk' => true, 'has_svk' => true,