From 8614f81eca34143732a1618492c13e674ce7e224 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 20 Nov 2021 00:48:23 +0100 Subject: [PATCH] Add update course --- src/Api.php | 20 ++++++++++++++++++++ src/Fakes/CourseFake.php | 32 +++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/Api.php b/src/Api.php index 7afefde..fa131c5 100644 --- a/src/Api.php +++ b/src/Api.php @@ -244,6 +244,26 @@ class Api { return $response['data']; } + /** + * @param int $memberId + * @param int $courseId + * @param array $payload + * @return void + */ + public function updateCourse(int $memberId, int $courseId, array $payload): void + { + $response = $this->http()->put(self::$url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}", [ + '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()); + } + } + 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 index dcd5fba..7267839 100644 --- a/src/Fakes/CourseFake.php +++ b/src/Fakes/CourseFake.php @@ -10,7 +10,20 @@ class CourseFake extends Fake { public function createsSuccessful(int $memberId, int $courseId): void { Http::fake(function($request) use ($memberId, $courseId) { - if ($request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}") { + if ($request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}" && $request->method() === 'POST') { + return Http::response([ + 'data' => $courseId, + 'responseType' => 'OK', + 'success' => true, + ], 200); + } + }); + } + + public function updatesSuccessful(int $memberId, int $courseId): void + { + Http::fake(function($request) use ($memberId, $courseId) { + if ($request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}" && $request->method() === 'PUT') { return Http::response([ 'data' => $courseId, 'responseType' => 'OK', @@ -45,4 +58,21 @@ class CourseFake extends Fake { }); } + /** + * @param int $memberId + * @param int $courseId + * @param array $payload + */ + public function assertUpdated(int $memberId, int $courseId, array $payload): void + { + Http::assertSent(function($request) use ($memberId, $courseId, $payload) { + return $request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/${courseId}" + && $request->method() === 'PUT' + && data_get($request, 'bausteinId') === $payload['bausteinId'] + && data_get($request, 'veranstalter') === $payload['veranstalter'] + && data_get($request, 'vstgName') === $payload['vstgName'] + && data_get($request, 'vstgTag') === $payload['vstgTag']; + }); + } + }