2022-02-11 01:24:09 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Member;
|
|
|
|
|
2022-11-16 23:52:38 +01:00
|
|
|
use App\Activity;
|
2022-02-11 01:24:09 +01:00
|
|
|
use App\Confession;
|
|
|
|
use App\Country;
|
|
|
|
use App\Fee;
|
|
|
|
use App\Group;
|
2022-11-16 22:59:49 +01:00
|
|
|
use App\Member\Actions\NamiPutMemberAction;
|
2022-02-11 01:24:09 +01:00
|
|
|
use App\Member\Member;
|
|
|
|
use App\Nationality;
|
|
|
|
use App\Payment\Subscription;
|
2022-11-16 23:52:38 +01:00
|
|
|
use App\Subactivity;
|
2022-02-11 01:24:09 +01:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use Tests\TestCase;
|
|
|
|
use Zoomyboy\LaravelNami\Backend\FakeBackend;
|
|
|
|
|
|
|
|
class UpdateTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
public function testItRedirectsToMemberOverview(): void
|
|
|
|
{
|
2022-02-19 18:08:29 +01:00
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
2022-02-11 01:24:09 +01:00
|
|
|
$member = $this->member();
|
|
|
|
$this->fakeRequest();
|
2022-11-16 22:59:49 +01:00
|
|
|
NamiPutMemberAction::allowToRun();
|
2022-02-11 01:24:09 +01:00
|
|
|
|
|
|
|
$response = $this
|
|
|
|
->from("/member/{$member->id}")
|
|
|
|
->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true]));
|
|
|
|
|
|
|
|
$response->assertRedirect('/member');
|
2022-11-16 22:59:49 +01:00
|
|
|
NamiPutMemberAction::spy()->shouldHaveReceived('handle')->withArgs(fn (Member $memberParam, ?Activity $activityParam, ?Subactivity $subactivityParam) => $memberParam->is($member)
|
|
|
|
&& null === $activityParam
|
|
|
|
&& null === $subactivityParam
|
|
|
|
)->once();
|
2022-02-11 01:24:09 +01:00
|
|
|
}
|
|
|
|
|
2022-04-28 23:52:30 +02:00
|
|
|
public function testItChecksVersion(): void
|
|
|
|
{
|
2023-02-08 01:39:46 +01:00
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
2022-04-28 23:52:30 +02:00
|
|
|
$member = $this->member();
|
|
|
|
$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");
|
|
|
|
}
|
|
|
|
|
2022-11-19 00:09:53 +01:00
|
|
|
public function testItUpdatesContact(): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
$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->assertEquals('englisch', $member->fresh()->other_country);
|
|
|
|
}
|
|
|
|
|
2022-03-15 16:32:05 +01:00
|
|
|
public function testItUpdatesCriminalRecord(): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
2022-11-16 22:59:49 +01:00
|
|
|
$member = $this->member(['nami_id' => null]);
|
2022-03-15 16:32:05 +01:00
|
|
|
$this->fakeRequest();
|
|
|
|
|
|
|
|
$response = $this
|
|
|
|
->from("/member/{$member->id}")
|
2022-04-28 23:20:41 +02:00
|
|
|
->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',
|
2022-11-16 22:59:49 +01:00
|
|
|
'has_nami' => false,
|
2022-04-28 23:20:41 +02:00
|
|
|
'multiply_pv' => true,
|
|
|
|
'multiply_more_pv' => true,
|
|
|
|
]));
|
|
|
|
|
2022-11-22 00:37:34 +01:00
|
|
|
$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'));
|
2022-04-28 23:20:41 +02:00
|
|
|
$this->assertTrue($member->fresh()->has_svk);
|
|
|
|
$this->assertTrue($member->fresh()->has_vk);
|
|
|
|
$this->assertTrue($member->fresh()->multiply_pv);
|
|
|
|
$this->assertTrue($member->fresh()->multiply_more_pv);
|
2022-11-22 00:37:34 +01:00
|
|
|
$this->assertEquals('2021-02-03', $member->fresh()->efz->format('Y-m-d'));
|
|
|
|
$this->assertEquals('2021-02-04', $member->fresh()->without_education_at->format('Y-m-d'));
|
|
|
|
$this->assertEquals('2021-02-05', $member->fresh()->without_efz_at->format('Y-m-d'));
|
2022-03-15 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
2022-11-16 22:59:49 +01:00
|
|
|
/**
|
|
|
|
* @param array<string, string|Activity|null> $overwrites
|
|
|
|
*/
|
|
|
|
private function member(array $overwrites = []): Member
|
2022-02-11 01:24:09 +01:00
|
|
|
{
|
|
|
|
return Member::factory()
|
|
|
|
->for(Group::factory()->state(['nami_id' => 10]))
|
|
|
|
->for(Confession::factory())
|
|
|
|
->for(Nationality::factory())
|
|
|
|
->for(Subscription::factory()->for(Fee::factory()))
|
|
|
|
->for(Country::factory())
|
2022-11-16 22:59:49 +01:00
|
|
|
->create(['nami_id' => 135, ...$overwrites]);
|
2022-02-11 01:24:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function fakeRequest(): void
|
|
|
|
{
|
|
|
|
Http::fake(function ($request) {
|
2023-02-17 18:57:11 +01:00
|
|
|
if ($request->url() === $this->singleMemberUrl(10, 135) && 'GET' === $request->method()) {
|
2022-02-11 01:56:02 +01:00
|
|
|
return Http::response('{ "success": true, "data": {"missingkey": "missingvalue", "kontoverbindung": {"a": "b"} } }', 200);
|
2022-02-11 01:24:09 +01:00
|
|
|
}
|
|
|
|
|
2023-02-17 18:57:11 +01:00
|
|
|
if ($request->url() === $this->singleMemberUrl(10, 135) && 'PUT' === $request->method() && 43 === $request['version']) {
|
2022-04-28 23:52:30 +02:00
|
|
|
return Http::response('{ "success": false, "message": "Update nicht möglich. Der Datensatz wurde zwischenzeitlich verändert." }', 200);
|
|
|
|
}
|
|
|
|
|
2023-02-17 18:57:11 +01:00
|
|
|
if ($request->url() === $this->singleMemberUrl(10, 135) && 'PUT' === $request->method()) {
|
2022-02-11 01:24:09 +01:00
|
|
|
return Http::response('{ "success": true, "data": { "version": 44 } }', 200);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-02-17 18:57:11 +01:00
|
|
|
|
|
|
|
private function singleMemberUrl(int $gruppierungId, int $memberId): string
|
|
|
|
{
|
|
|
|
return "https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{$gruppierungId}/{$memberId}";
|
|
|
|
}
|
2022-02-11 01:24:09 +01:00
|
|
|
}
|