80 lines
2.7 KiB
PHP
80 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Member;
|
|
|
|
use App\Course\Models\Course;
|
|
use App\Course\Models\CourseMember;
|
|
use App\Lib\Events\ClientMessage;
|
|
use App\Lib\Events\JobFinished;
|
|
use App\Lib\Events\JobStarted;
|
|
use App\Member\Actions\MemberDeleteAction;
|
|
use App\Member\Actions\NamiDeleteMemberAction;
|
|
use App\Member\Member;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Tests\TestCase;
|
|
|
|
class DeleteTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function testItFiresJob(): void
|
|
{
|
|
Queue::fake();
|
|
$this->login()->loginNami();
|
|
$member = Member::factory()->defaults()->inNami(123)->create();
|
|
|
|
$response = $this->from('/member')->delete("/member/{$member->id}");
|
|
|
|
$response->assertRedirect('/member');
|
|
|
|
MemberDeleteAction::assertPushed(fn ($action, $parameters) => $parameters[0] === $member->id);
|
|
}
|
|
|
|
public function testItDeletesMemberFromNami(): void
|
|
{
|
|
$this->login()->loginNami();
|
|
NamiDeleteMemberAction::partialMock()->shouldReceive('handle')->with(123)->once();
|
|
$member = Member::factory()->defaults()->inNami(123)->create();
|
|
|
|
MemberDeleteAction::run($member->id);
|
|
|
|
$this->assertDatabaseMissing('members', [
|
|
'id' => $member->id,
|
|
]);
|
|
}
|
|
|
|
public function testItDoesntRunActionWhenMemberIsNotInNami(): void
|
|
{
|
|
$this->login()->loginNami();
|
|
NamiDeleteMemberAction::partialMock()->shouldReceive('handle')->never();
|
|
$member = Member::factory()->defaults()->create();
|
|
|
|
MemberDeleteAction::run($member->id);
|
|
}
|
|
|
|
|
|
public function testItDeletesMembersWithCourses(): void
|
|
{
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
$member = Member::factory()->defaults()->has(CourseMember::factory()->for(Course::factory()), 'courses')->create();
|
|
|
|
MemberDeleteAction::run($member->id);
|
|
|
|
$this->assertDatabaseCount('members', 0);
|
|
}
|
|
|
|
public function testItFiresEventWhenFinished(): void
|
|
{
|
|
Event::fake([JobStarted::class, JobFinished::class]);
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
$member = Member::factory()->defaults()->create(['firstname' => 'Max', 'lastname' => 'Muster']);
|
|
|
|
MemberDeleteAction::dispatch($member->id);
|
|
|
|
Event::assertDispatched(JobStarted::class, fn ($event) => $event->broadcastOn()->name === 'member' && $event->message === 'Lösche Mitglied Max Muster' && $event->reload === false);
|
|
Event::assertDispatched(JobFinished::class, fn ($event) => $event->message === 'Mitglied Max Muster gelöscht' && $event->reload === true);
|
|
}
|
|
}
|