Add login validation for course creation

This commit is contained in:
philipp lang 2022-02-19 13:56:41 +01:00
parent 798f7222e9
commit b8d2a04d43
2 changed files with 43 additions and 0 deletions

View File

@ -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'],

View File

@ -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);