From 489072411ee9aa18f607198f7245efd6a7974fe5 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 19 Nov 2021 22:58:42 +0100 Subject: [PATCH] Add store course --- src/Api.php | 22 ++++++++++++++++++++++ src/Fakes/CourseFake.php | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/Fakes/CourseFake.php diff --git a/src/Api.php b/src/Api.php index 5c8ee9c..7afefde 100644 --- a/src/Api.php +++ b/src/Api.php @@ -4,6 +4,7 @@ namespace Zoomyboy\LaravelNami; use App\Conf; use App\Nami\Exceptions\TooManyLoginAttemptsException; +use Carbon\Carbon; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; @@ -222,6 +223,27 @@ class Api { }); } + /** + * @param int $memberId + * @param array $payload + * @return int + */ + public function createCourse(int $memberId, array $payload): int + { + $response = $this->http()->post(self::$url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}", [ + 'bausteinId' => $payload['course_id'], + 'vstgName' => $payload['event_name'], + 'vstgTag' => Carbon::parse($payload['completed_at'])->format('Y-m-d').'T00:00:00', + 'veranstalter' => $payload['organizer'], + ]); + + if (data_get($response->json(), 'success') !== true) { + $this->exception('Course creation failed', $payload, $response->json()); + } + + return $response['data']; + } + public function member($groupId, $memberId) { $url = self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId; $response = $this->http()->get($url); diff --git a/src/Fakes/CourseFake.php b/src/Fakes/CourseFake.php new file mode 100644 index 0000000..944c8f6 --- /dev/null +++ b/src/Fakes/CourseFake.php @@ -0,0 +1,39 @@ +url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}") { + return Http::response([ + 'data' => $courseId, + 'responseType' => 'OK', + 'success' => true, + ], 200); + } + }); + } + + /** + * @param int $memberId + * @param array $payload + */ + public function assertCreated(int $memberId, array $payload): void + { + Http::assertSent(function($request) use ($memberId, $payload) { + return $request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}" + && $request->method() === 'POST' + && data_get($request, 'bausteinId') === $payload['bausteinId'] + && data_get($request, 'veranstalter') === $payload['veranstalter'] + // && data_get($request, 'vstgName') === $payload['vstgName'] + && data_get($request, 'vstgTag') === $payload['vstgTag']; + }); + } + +}