From 435503073b55759d67500d37b587bd8a0646355d Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Mon, 14 Nov 2022 15:05:09 +0100 Subject: [PATCH] add member fake --- src/Fakes/MemberFake.php | 74 ++++++++++++++++++++++++++++++++++++++-- src/Member.php | 4 +-- 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/Fakes/MemberFake.php b/src/Fakes/MemberFake.php index 8a14cf4..7369f36 100644 --- a/src/Fakes/MemberFake.php +++ b/src/Fakes/MemberFake.php @@ -17,15 +17,41 @@ class MemberFake extends Fake }); } - public function shows(int $groupId, int $memberId, array $data): void + public function shows(int $groupId, int $memberId, array $data): self { Http::fake(function ($request) use ($groupId, $memberId, $data) { $url = 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId; if ($request->url() === $url && 'GET' === $request->method()) { return $this->dataResponse(array_merge([ + 'id' => $memberId, + 'eintrittsdatum' => '2005-05-01 00:00:00', + 'geburtsDatum' => '1991-06-20 00:00:00', + 'gruppierungId' => $groupId, + 'geschlechtId' => 19, + 'staatsangehoerigkeitId' => 1054, ], $data)); } }); + + return $this; + } + + /** + * @param array $data + */ + public function updates(int $groupId, int $memberId, array $data): self + { + Http::fake(function ($request) use ($groupId, $memberId, $data) { + $url = 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId; + if ($request->url() === $url && 'PUT' === $request->method()) { + return $this->dataResponse([ + 'id' => $memberId, + ...$data, + ]); + } + }); + + return $this; } public function deletes(int $memberId, Carbon $date): void @@ -53,7 +79,7 @@ class MemberFake extends Fake }); } - public function createsSuccessfully(int $groupId, int $memberId): void + public function createsSuccessfully(int $groupId, int $memberId): self { Http::fake(function ($request) use ($memberId, $groupId) { $url = "https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{$groupId}"; @@ -62,6 +88,8 @@ class MemberFake extends Fake return $this->idResponse($memberId); } }); + + return $this; } /** @@ -69,13 +97,53 @@ class MemberFake extends Fake */ public function assertCreated(int $groupId, array $body): void { - Http::assertSent(function ($request) use ($groupId) { + Http::assertSent(function ($request) use ($groupId, $body) { $url = "https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{$groupId}"; if ($request->url() !== $url || 'POST' !== $request->method()) { return false; } + $requestBody = json_decode($request->body(), true); + + foreach ($body as $key => $value) { + if (!isset($requestBody[$key])) { + return false; + } + + if ($requestBody[$key] !== $value) { + return false; + } + } + + return true; + }); + } + + /** + * @param array $body + */ + public function assertUpdated(int $groupId, int $memberId, array $body): void + { + Http::assertSent(function ($request) use ($groupId, $memberId, $body) { + $url = "https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{$groupId}/{$memberId}"; + + if ($request->url() !== $url || 'PUT' !== $request->method()) { + return false; + } + + $requestBody = json_decode($request->body(), true); + + foreach ($body as $key => $value) { + if (!isset($requestBody[$key])) { + return false; + } + + if ($requestBody[$key] !== $value) { + return false; + } + } + return true; }); } diff --git a/src/Member.php b/src/Member.php index d9b38ae..f74d8bb 100644 --- a/src/Member.php +++ b/src/Member.php @@ -106,8 +106,8 @@ class Member extends Model 'nameZusatz' => $this->further_address ?: '', 'konfessionId' => $this->confession_id, 'staatsangehoerigkeitText' => $this->other_country ?: '', - 'ersteTaetigkeitId' => $this->first_activity_id ?: null, - 'ersteUntergliederungId' => $this->first_subactivity_id ?: null, + 'ersteTaetigkeitId' => $this->first_activity ?: null, + 'ersteUntergliederungId' => $this->first_subactivity ?: null, ]; }