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\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,11 +93,9 @@ 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(), [
'other_country' => 'englisch',
]));
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
'other_country' => 'englisch',
]));
$this->assertEquals('englisch', $member->fresh()->other_country);
}
@ -158,22 +150,20 @@ 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(), [
'ps_at' => '2021-02-01',
'more_ps_at' => '2021-02-02',
'has_svk' => true,
'has_vk' => true,
'efz' => '2021-02-03',
'without_education_at' => '2021-02-04',
'without_efz_at' => '2021-02-05',
'recertified_at' => '2021-02-08',
'has_nami' => false,
'multiply_pv' => true,
'multiply_more_pv' => true,
'salutation' => 'Doktor',
]));
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
'ps_at' => '2021-02-01',
'more_ps_at' => '2021-02-02',
'has_svk' => true,
'has_vk' => true,
'efz' => '2021-02-03',
'without_education_at' => '2021-02-04',
'without_efz_at' => '2021-02-05',
'recertified_at' => '2021-02-08',
'has_nami' => false,
'multiply_pv' => true,
'multiply_more_pv' => true,
'salutation' => 'Doktor',
]));
$this->assertEquals('2021-02-01', $member->fresh()->ps_at->format('Y-m-d'));
$this->assertEquals('2021-02-02', $member->fresh()->more_ps_at->format('Y-m-d'));