2022-02-19 13:37:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
|
|
|
|
2023-02-07 02:30:00 +01:00
|
|
|
use Zoomyboy\LaravelNami\Data\Course;
|
2023-02-08 01:26:01 +01:00
|
|
|
use Zoomyboy\LaravelNami\Exceptions\NoJsonReceivedException;
|
2022-02-19 13:37:53 +01:00
|
|
|
use Zoomyboy\LaravelNami\Exceptions\NotAuthenticatedException;
|
2023-02-08 01:26:01 +01:00
|
|
|
use Zoomyboy\LaravelNami\Exceptions\NotSuccessfulException;
|
2022-02-19 13:37:53 +01:00
|
|
|
use Zoomyboy\LaravelNami\Fakes\CourseFake;
|
|
|
|
use Zoomyboy\LaravelNami\LoginException;
|
|
|
|
use Zoomyboy\LaravelNami\Nami;
|
|
|
|
use Zoomyboy\LaravelNami\Tests\TestCase;
|
|
|
|
|
|
|
|
class CourseTest extends TestCase
|
|
|
|
{
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testGetCoursesOfMember(): void
|
2022-02-19 13:37:53 +01:00
|
|
|
{
|
2022-02-22 23:37:32 +01:00
|
|
|
app(CourseFake::class)
|
|
|
|
->fetches(11111, [788])
|
2023-02-07 02:30:00 +01:00
|
|
|
->shows(11111, Course::factory()->toModel([
|
2022-02-22 23:37:32 +01:00
|
|
|
'bausteinId' => 506,
|
|
|
|
'id' => 788,
|
|
|
|
'veranstalter' => 'KJA',
|
|
|
|
'vstgName' => 'eventname',
|
2022-03-11 20:20:00 +01:00
|
|
|
'vstgTag' => '2021-11-12 00:00:00',
|
2023-02-07 02:30:00 +01:00
|
|
|
]));
|
2022-02-22 23:37:32 +01:00
|
|
|
|
2022-03-05 20:22:09 +01:00
|
|
|
$course = $this->login()->coursesFor(11111)->first();
|
2022-02-22 23:37:32 +01:00
|
|
|
|
|
|
|
$this->assertEquals(788, $course->id);
|
|
|
|
$this->assertEquals('KJA', $course->organizer);
|
2022-02-23 22:18:11 +01:00
|
|
|
$this->assertEquals(506, $course->courseId);
|
|
|
|
$this->assertEquals('eventname', $course->eventName);
|
|
|
|
$this->assertEquals('2021-11-12 00:00:00', $course->completedAt);
|
2022-02-22 23:37:32 +01:00
|
|
|
|
|
|
|
app(CourseFake::class)->assertFetched(11111);
|
|
|
|
app(CourseFake::class)->assertFetchedSingle(11111, 788);
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testItGetsMultipleCoursesOfMember(): void
|
2022-02-22 23:37:32 +01:00
|
|
|
{
|
|
|
|
app(CourseFake::class)
|
|
|
|
->fetches(11111, [788, 789])
|
2023-02-07 02:30:00 +01:00
|
|
|
->shows(11111, Course::factory()->id(788)->toModel())
|
|
|
|
->shows(11111, Course::factory()->id(789)->toModel());
|
2022-02-22 23:37:32 +01:00
|
|
|
|
2022-03-05 20:22:09 +01:00
|
|
|
$courses = $this->login()->coursesFor(11111);
|
2022-02-22 23:37:32 +01:00
|
|
|
|
|
|
|
$this->assertCount(2, $courses);
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testReturnNothingWhenCourseReturnsHtml(): void
|
2022-02-22 23:37:32 +01:00
|
|
|
{
|
|
|
|
app(CourseFake::class)
|
|
|
|
->fetches(11111, [788, 789])
|
2022-03-05 20:22:09 +01:00
|
|
|
->failsShowingWithHtml(11111, 788)
|
2023-02-07 02:30:00 +01:00
|
|
|
->shows(11111, Course::factory()->id(789)->toModel());
|
2022-02-22 23:37:32 +01:00
|
|
|
|
2022-03-05 20:22:09 +01:00
|
|
|
$courses = $this->login()->coursesFor(11111);
|
2022-02-22 23:37:32 +01:00
|
|
|
|
|
|
|
$this->assertCount(1, $courses);
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testReturnEmptyWhenCourseIndexReturnsHtml(): void
|
2022-02-22 23:37:32 +01:00
|
|
|
{
|
2023-02-08 01:26:01 +01:00
|
|
|
$this->expectException(NoJsonReceivedException::class);
|
2022-02-23 00:00:40 +01:00
|
|
|
app(CourseFake::class)->failsFetchingWithHtml(11111);
|
2022-02-19 13:37:53 +01:00
|
|
|
|
2023-02-08 01:26:01 +01:00
|
|
|
$this->login()->coursesFor(11111);
|
2022-02-19 13:37:53 +01:00
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testItNeedsLoginToGetCourses(): void
|
2022-02-19 13:56:41 +01:00
|
|
|
{
|
|
|
|
$this->expectException(NotAuthenticatedException::class);
|
|
|
|
|
|
|
|
Nami::coursesFor(11111);
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testStoreACourse(): void
|
2022-02-19 13:56:41 +01:00
|
|
|
{
|
2022-02-22 23:37:32 +01:00
|
|
|
app(CourseFake::class)->createsSuccessfully(123, 999);
|
2022-03-05 20:22:09 +01:00
|
|
|
$this->login()->createCourse(123, [
|
2022-02-19 13:56:41 +01:00
|
|
|
'event_name' => '::event::',
|
|
|
|
'completed_at' => '2021-01-02 00:00:00',
|
|
|
|
'organizer' => '::org::',
|
2022-03-11 20:20:00 +01:00
|
|
|
'course_id' => 456,
|
2022-02-19 13:56:41 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
app(CourseFake::class)->assertCreated(123, [
|
|
|
|
'vstgName' => '::event::',
|
|
|
|
'vstgTag' => '2021-01-02T00:00:00',
|
2022-02-22 23:37:32 +01:00
|
|
|
'veranstalter' => '::org::',
|
|
|
|
'bausteinId' => 456,
|
2022-02-19 13:56:41 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testNeedsLoginToStoreACourse(): void
|
2022-02-19 13:56:41 +01:00
|
|
|
{
|
|
|
|
$this->expectException(NotAuthenticatedException::class);
|
|
|
|
Nami::createCourse(123, [
|
|
|
|
'event_name' => '::event::',
|
|
|
|
'completed_at' => '2021-01-02 00:00:00',
|
|
|
|
'organizer' => '::org::',
|
2022-03-11 20:20:00 +01:00
|
|
|
'course_id' => 456,
|
2022-02-19 13:56:41 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testUpdateACourse(): void
|
2022-02-19 13:37:53 +01:00
|
|
|
{
|
2022-02-22 23:37:32 +01:00
|
|
|
app(CourseFake::class)->updatesSuccessfully(123, 999);
|
2022-02-19 13:37:53 +01:00
|
|
|
|
2022-03-05 20:22:09 +01:00
|
|
|
$this->login()->updateCourse(123, 999, [
|
2022-02-22 23:37:32 +01:00
|
|
|
'event_name' => '::event::',
|
|
|
|
'completed_at' => '2021-01-02 00:00:00',
|
|
|
|
'organizer' => '::org::',
|
|
|
|
'course_id' => 456,
|
|
|
|
'id' => 999,
|
|
|
|
]);
|
|
|
|
|
|
|
|
app(CourseFake::class)->assertUpdated(123, 999, [
|
|
|
|
'vstgName' => '::event::',
|
|
|
|
'vstgTag' => '2021-01-02T00:00:00',
|
|
|
|
'veranstalter' => '::org::',
|
|
|
|
'bausteinId' => 456,
|
|
|
|
'id' => 999,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testThrowExceptionWhenCourseUpdateFailed(): void
|
2022-02-22 23:37:32 +01:00
|
|
|
{
|
2023-02-08 01:26:01 +01:00
|
|
|
$this->expectException(NotSuccessfulException::class);
|
2022-02-23 00:00:40 +01:00
|
|
|
app(CourseFake::class)->failsUpdating(123, 999);
|
2022-02-22 23:37:32 +01:00
|
|
|
|
2022-03-05 20:22:09 +01:00
|
|
|
$this->login()->updateCourse(123, 999, [
|
2022-02-22 23:37:32 +01:00
|
|
|
'event_name' => '::event::',
|
|
|
|
'completed_at' => '2021-01-02 00:00:00',
|
|
|
|
'organizer' => '::org::',
|
|
|
|
'course_id' => 456,
|
|
|
|
'id' => 999,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testItNeedsValidCredentialsToStoreACourse(): void
|
2022-02-22 23:37:32 +01:00
|
|
|
{
|
|
|
|
$this->expectException(NotAuthenticatedException::class);
|
|
|
|
Nami::createCourse(123, [
|
|
|
|
'event_name' => '::event::',
|
|
|
|
'completed_at' => '2021-01-02 00:00:00',
|
|
|
|
'organizer' => '::org::',
|
2022-03-11 20:20:00 +01:00
|
|
|
'course_id' => 456,
|
2022-02-22 23:37:32 +01:00
|
|
|
]);
|
2022-02-19 13:37:53 +01:00
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testItThrowsLoginExceptionWhenFetchingWithWrongCredentials(): void
|
2022-02-19 13:37:53 +01:00
|
|
|
{
|
|
|
|
$this->expectException(LoginException::class);
|
|
|
|
|
2022-03-05 20:22:09 +01:00
|
|
|
$this->loginWithWrongCredentials()->coursesFor(11111);
|
2022-02-19 13:37:53 +01:00
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testThrowExceptionWhenStoringFailed(): void
|
2022-02-19 22:00:50 +01:00
|
|
|
{
|
2023-02-08 01:26:01 +01:00
|
|
|
$this->expectException(NotSuccessfulException::class);
|
2022-02-23 00:00:40 +01:00
|
|
|
app(CourseFake::class)->failsCreating(123);
|
2022-02-19 22:00:50 +01:00
|
|
|
|
2022-03-05 20:22:09 +01:00
|
|
|
$this->login()->createCourse(123, [
|
2022-02-19 22:00:50 +01:00
|
|
|
'event_name' => '::event::',
|
|
|
|
'completed_at' => '2021-01-02 00:00:00',
|
|
|
|
'organizer' => '::org::',
|
2022-03-11 20:20:00 +01:00
|
|
|
'course_id' => 456,
|
2022-02-19 22:00:50 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testDeleteACourse(): void
|
2022-02-23 00:00:40 +01:00
|
|
|
{
|
|
|
|
app(CourseFake::class)->deletesSuccessfully(123, 999);
|
|
|
|
|
2022-03-05 20:22:09 +01:00
|
|
|
$this->login()->deleteCourse(123, 999);
|
2022-02-23 00:00:40 +01:00
|
|
|
|
|
|
|
app(CourseFake::class)->assertDeleted(123, 999);
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testShrowExceptionWhenDeletingFailed(): void
|
2022-02-23 00:00:40 +01:00
|
|
|
{
|
2023-02-08 01:26:01 +01:00
|
|
|
$this->expectException(NotSuccessfulException::class);
|
2022-02-23 00:00:40 +01:00
|
|
|
app(CourseFake::class)->failsDeleting(123, 999);
|
|
|
|
|
2022-03-05 20:22:09 +01:00
|
|
|
$this->login()->deleteCourse(123, 999);
|
2022-02-23 00:00:40 +01:00
|
|
|
}
|
2022-02-19 13:37:53 +01:00
|
|
|
}
|