Fix UpdateTest

This commit is contained in:
philipp lang 2024-08-28 22:31:35 +02:00
parent 4b73c79139
commit c058a1b78a
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\Setting\NamiSettings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Response;
@ -34,14 +35,14 @@ class MemberController extends Controller
return redirect()->route('member.index');
}
public function update(Member $member, MemberRequest $request): RedirectResponse
public function update(Member $member, MemberRequest $request): JsonResponse
{
try {
$request->persistUpdate($member);
} 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();
NamiPutMemberAction::allowToRun();
$response = $this
->from("/member/{$member->id}")
->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true]));
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true]));
$response->assertRedirect('/member');
NamiPutMemberAction::spy()->shouldHaveReceived('handle')->withArgs(
fn (Member $memberParam, ?Activity $activityParam, ?Subactivity $subactivityParam) => $memberParam->is($member)
&& null === $activityParam
@ -49,11 +46,8 @@ class UpdateTest extends TestCase
$member->update(['version' => 43]);
$this->fakeRequest();
$response = $this
->from("/member/{$member->id}")
->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true, 'firstname' => '::firstname::']));
$response->assertRedirect("/member/{$member->id}/edit?conflict=1");
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true, 'firstname' => '::firstname::']))
->assertStatus(409);
}
public function testItUpdatesPhoneNumber(): void
@ -99,9 +93,7 @@ class UpdateTest extends TestCase
$member = $this->member(['nami_id' => null]);
$this->fakeRequest();
$response = $this
->from("/member/{$member->id}")
->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
'other_country' => 'englisch',
]));
@ -158,9 +150,7 @@ class UpdateTest extends TestCase
$member = $this->member(['nami_id' => null]);
$this->fakeRequest();
$response = $this
->from("/member/{$member->id}")
->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
'ps_at' => '2021-02-01',
'more_ps_at' => '2021-02-02',
'has_svk' => true,