2021-11-20 01:09:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Course;
|
|
|
|
|
|
|
|
use App\Course\Models\Course;
|
|
|
|
use App\Course\Models\CourseMember;
|
|
|
|
use App\Member\Member;
|
2022-02-12 01:08:56 +01:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2021-11-20 01:09:28 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
use Zoomyboy\LaravelNami\Fakes\CourseFake;
|
|
|
|
|
|
|
|
class DeleteTest extends TestCase
|
|
|
|
{
|
2022-02-12 01:08:56 +01:00
|
|
|
use DatabaseTransactions;
|
2021-11-20 01:09:28 +01:00
|
|
|
|
|
|
|
public function testItDeletesACourse(): void
|
|
|
|
{
|
2022-02-19 18:06:07 +01:00
|
|
|
$this->login()->loginNami();
|
2022-02-23 00:01:03 +01:00
|
|
|
app(CourseFake::class)->deletesSuccessfully(123, 999);
|
2021-11-20 01:09:28 +01:00
|
|
|
$member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne();
|
|
|
|
|
2021-11-23 01:02:18 +01:00
|
|
|
$this->delete("/member/{$member->id}/course/{$member->courses->first()->id}");
|
2021-11-20 01:09:28 +01:00
|
|
|
|
|
|
|
$this->assertDatabaseCount('course_members', 0);
|
|
|
|
app(CourseFake::class)->assertDeleted(123, 999);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItReceivesUnknownErrors(): void
|
|
|
|
{
|
2022-02-19 18:06:07 +01:00
|
|
|
$this->login()->loginNami();
|
2022-02-23 00:01:03 +01:00
|
|
|
app(CourseFake::class)->failsDeleting(123, 999);
|
2021-11-20 01:09:28 +01:00
|
|
|
$member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne();
|
|
|
|
|
|
|
|
$response = $this->delete("/member/{$member->id}/course/{$member->courses->first()->id}");
|
|
|
|
|
|
|
|
$this->assertDatabaseCount('course_members', 1);
|
|
|
|
$response->assertSessionHasErrors(['id' => 'Unbekannter Fehler']);
|
|
|
|
}
|
|
|
|
}
|