diff --git a/src/Api.php b/src/Api.php index fa131c5..920da4f 100644 --- a/src/Api.php +++ b/src/Api.php @@ -260,7 +260,16 @@ class Api { ]); if (data_get($response->json(), 'success') !== true) { - $this->exception('Course creation failed', $payload, $response->json()); + $this->exception('Course update failed', $payload, $response->json()); + } + } + + public function deleteCourse(int $memberId, int $courseId): void + { + $response = $this->http()->delete(self::$url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}"); + + if (data_get($response->json(), 'success') !== true) { + $this->exception('Course deletion failed', [], $response->json()); } } diff --git a/src/Fakes/CourseFake.php b/src/Fakes/CourseFake.php index e5cf2a2..cd9886a 100644 --- a/src/Fakes/CourseFake.php +++ b/src/Fakes/CourseFake.php @@ -33,6 +33,32 @@ class CourseFake extends Fake { }); } + public function deleteSuccessful(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() === 'DELETE') { + return Http::response([ + 'data' => null, + 'responseType' => 'OK', + 'success' => true, + ], 200); + } + }); + } + + public function deleteFailed(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() === 'DELETE') { + return Http::response([ + 'data' => null, + 'responseType' => 'NOK', + 'success' => false, + ], 200); + } + }); + } + public function doesntCreateWithError(int $memberId): void { Http::fake(function($request) use ($memberId) { @@ -84,4 +110,12 @@ class CourseFake extends Fake { }); } + public function assertDeleted(int $memberId, int $courseId): void + { + Http::assertSent(function($request) use ($memberId, $courseId) { + return $request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/${courseId}" + && $request->method() === 'DELETE'; + }); + } + }