diff --git a/src/Api.php b/src/Api.php index a5c1334..29080cb 100644 --- a/src/Api.php +++ b/src/Api.php @@ -220,6 +220,7 @@ class Api { */ public function createCourse(int $memberId, array $payload): int { + $this->assertLoggedIn(); $response = $this->http()->post($this->url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}", [ 'bausteinId' => $payload['course_id'], 'vstgName' => $payload['event_name'], diff --git a/tests/Unit/CourseTest.php b/tests/Unit/CourseTest.php index 36879b4..71f413d 100644 --- a/tests/Unit/CourseTest.php +++ b/tests/Unit/CourseTest.php @@ -44,6 +44,48 @@ class CourseTest extends TestCase Http::assertSentCount(2); } + public function test_it_needs_login_to_get_courses(): void + { + app(CourseFake::class)->forMember(11111, [ + ['bausteinId' => 506, 'id' => 788, 'veranstalter' => 'KJA', 'vstgName' => 'eventname', 'vstgTag' => '2021-11-12 00:00:00'] + ]); + $this->expectException(NotAuthenticatedException::class); + + Nami::coursesFor(11111); + } + + public function test_store_a_course(): void + { + Auth::success(12345, 'secret'); + app(CourseFake::class)->createsSuccessful(123, 999); + Nami::login(12345, 'secret'); + + Nami::createCourse(123, [ + 'event_name' => '::event::', + 'completed_at' => '2021-01-02 00:00:00', + 'organizer' => '::org::', + 'course_id' => 456 + ]); + + app(CourseFake::class)->assertCreated(123, [ + 'bausteinId' => 456, + 'veranstalter' => '::org::', + 'vstgName' => '::event::', + 'vstgTag' => '2021-01-02T00:00:00', + ]); + } + + public function test_needs_login_to_store_a_course(): void + { + $this->expectException(NotAuthenticatedException::class); + Nami::createCourse(123, [ + 'event_name' => '::event::', + 'completed_at' => '2021-01-02 00:00:00', + 'organizer' => '::org::', + 'course_id' => 456 + ]); + } + public function test_needs_login(): void { $this->expectException(NotAuthenticatedException::class);