From 5ce86d632d3e228e08db314895aa9071e668f436 Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Mon, 5 Sep 2022 11:37:15 +0200 Subject: [PATCH] Add deleted member to memberFake --- src/Fakes/MemberFake.php | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/Fakes/MemberFake.php b/src/Fakes/MemberFake.php index 96bd133..358a7f5 100644 --- a/src/Fakes/MemberFake.php +++ b/src/Fakes/MemberFake.php @@ -2,6 +2,7 @@ namespace Zoomyboy\LaravelNami\Fakes; +use Carbon\Carbon; use Illuminate\Support\Facades\Http; class MemberFake extends Fake @@ -26,4 +27,54 @@ class MemberFake extends Fake } }); } + + public function deletes(int $memberId, Carbon $date): void + { + Http::fake(function ($request) use ($memberId, $date) { + $url = 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/mglschaft-beenden'; + + if ($request->url() !== $url || 'POST' !== $request->method()) { + return null; + } + + if ((int) data_get($request, 'id') !== $memberId) { + return; + } + + if ('true' !== data_get($request, 'isConfirmed')) { + return; + } + + if (Carbon::parse(data_get($request, 'beendenZumDatum'))->format('Y-m-d') !== $date->format('Y-m-d')) { + return; + } + + return $this->nullResponse(); + }); + } + + public function assertDeleted(int $memberId, Carbon $date): void + { + Http::assertSent(function ($request) use ($memberId, $date) { + $url = 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/mglschaft-beenden'; + + if ($request->url() !== $url || 'POST' !== $request->method()) { + return false; + } + + if ((int) data_get($request, 'id') !== $memberId) { + return false; + } + + if ('true' !== data_get($request, 'isConfirmed')) { + return false; + } + + if (Carbon::parse(data_get($request, 'beendenZumDatum'))->format('Y-m-d') !== $date->format('Y-m-d')) { + return false; + } + + return true; + }); + } }