2022-02-11 01:24:09 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Member;
|
|
|
|
|
2024-03-08 23:44:40 +01:00
|
|
|
use App\Actions\PullMemberAction;
|
|
|
|
use App\Actions\PullMembershipsAction;
|
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;
|
2024-03-08 23:44:40 +01:00
|
|
|
use Zoomyboy\LaravelNami\Fakes\MemberFake;
|
2022-02-11 01:24:09 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2024-08-28 22:31:35 +02:00
|
|
|
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true]));
|
2022-02-11 01:24:09 +01:00
|
|
|
|
2023-11-24 13:28:54 +01:00
|
|
|
NamiPutMemberAction::spy()->shouldHaveReceived('handle')->withArgs(
|
|
|
|
fn (Member $memberParam, ?Activity $activityParam, ?Subactivity $subactivityParam) => $memberParam->is($member)
|
|
|
|
&& null === $activityParam
|
|
|
|
&& null === $subactivityParam
|
2022-11-16 22:59:49 +01:00
|
|
|
)->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();
|
|
|
|
|
2024-08-28 22:31:35 +02:00
|
|
|
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true, 'firstname' => '::firstname::']))
|
|
|
|
->assertStatus(409);
|
2022-04-28 23:52:30 +02:00
|
|
|
}
|
|
|
|
|
2023-03-03 00:30:33 +01:00
|
|
|
public function testItUpdatesPhoneNumber(): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
$member = $this->member();
|
|
|
|
$this->fakeRequest();
|
|
|
|
NamiPutMemberAction::allowToRun();
|
|
|
|
|
|
|
|
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
|
|
|
|
'main_phone' => '02103 4455129',
|
|
|
|
'fax' => '02103 4455130',
|
|
|
|
'children_phone' => '02103 4455130',
|
|
|
|
'has_nami' => true,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('members', [
|
|
|
|
'main_phone' => '+49 2103 4455129',
|
|
|
|
'fax' => '+49 2103 4455130',
|
|
|
|
'children_phone' => '+49 2103 4455130',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-07-24 16:55:07 +02:00
|
|
|
public function testItSetsLocationToNull(): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
$member = $this->member(['location' => 'Hilden', 'nami_id' => null]);
|
|
|
|
$this->fakeRequest();
|
|
|
|
NamiPutMemberAction::allowToRun();
|
|
|
|
|
|
|
|
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
|
|
|
|
'location' => null,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('members', [
|
|
|
|
'location' => null,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-11-19 00:09:53 +01:00
|
|
|
public function testItUpdatesContact(): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
$member = $this->member(['nami_id' => null]);
|
|
|
|
$this->fakeRequest();
|
|
|
|
|
2024-08-28 22:31:35 +02:00
|
|
|
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
|
|
|
|
'other_country' => 'englisch',
|
|
|
|
]));
|
2022-11-19 00:09:53 +01:00
|
|
|
|
|
|
|
$this->assertEquals('englisch', $member->fresh()->other_country);
|
|
|
|
}
|
|
|
|
|
2024-03-08 23:44:40 +01:00
|
|
|
public function testItCreatesMemberWithFirstActivityId(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$member = Member::factory()->defaults()->create();
|
|
|
|
app(MemberFake::class)->stores($member->group->nami_id, 103);
|
|
|
|
$activity = Activity::factory()->inNami(89)->create();
|
|
|
|
$subactivity = Subactivity::factory()->inNami(90)->create();
|
|
|
|
Confession::factory()->create(['is_null' => true]);
|
|
|
|
PullMemberAction::shouldRun();
|
|
|
|
PullMembershipsAction::shouldRun();
|
|
|
|
|
|
|
|
$this->patch("/member/{$member->id}", [
|
|
|
|
...$member->getAttributes(),
|
|
|
|
'has_nami' => true,
|
|
|
|
'first_activity_id' => $activity->id,
|
|
|
|
'first_subactivity_id' => $subactivity->id,
|
|
|
|
])->assertSessionHasNoErrors();
|
|
|
|
|
|
|
|
app(MemberFake::class)->assertStored($member->group->nami_id, [
|
|
|
|
'ersteTaetigkeitId' => 89,
|
|
|
|
'ersteUntergliederungId' => 90,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItRequiresFirstActivityId(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami();
|
|
|
|
$member = Member::factory()->defaults()->create();
|
|
|
|
app(MemberFake::class)->stores($member->group->nami_id, 103);
|
|
|
|
Confession::factory()->create(['is_null' => true]);
|
|
|
|
PullMemberAction::shouldRun();
|
|
|
|
PullMembershipsAction::shouldRun();
|
|
|
|
|
|
|
|
$this->patch("/member/{$member->id}", [
|
|
|
|
...$member->getAttributes(),
|
|
|
|
'has_nami' => true,
|
|
|
|
'first_activity_id' => null,
|
|
|
|
'first_subactivity_id' => null,
|
|
|
|
])->assertSessionHasErrors([
|
|
|
|
'first_activity_id' => 'Erste Tätigkeit ist erforderlich.',
|
|
|
|
'first_subactivity_id' => 'Erste Untergliederung ist erforderlich.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2024-08-28 22:31:35 +02:00
|
|
|
$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',
|
|
|
|
]));
|
2022-04-28 23:20:41 +02:00
|
|
|
|
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'));
|
2023-11-24 13:28:54 +01:00
|
|
|
$this->assertEquals('2021-02-08', $member->fresh()->recertified_at->format('Y-m-d'));
|
2023-02-27 22:40:47 +01:00
|
|
|
$this->assertEquals('Doktor', $member->fresh()->salutation);
|
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())
|
2024-02-22 11:13:20 +01:00
|
|
|
->for(Subscription::factory()->forFee())
|
2022-02-11 01:24:09 +01:00
|
|
|
->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
|
|
|
}
|