2022-09-05 10:57:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Member;
|
|
|
|
|
2023-04-25 00:32:44 +02:00
|
|
|
use App\Course\Models\Course;
|
|
|
|
use App\Course\Models\CourseMember;
|
2023-08-14 23:57:15 +02:00
|
|
|
use App\Member\DeleteAction;
|
2022-09-05 10:57:20 +02:00
|
|
|
use App\Member\Member;
|
2022-09-05 11:37:54 +02:00
|
|
|
use Carbon\Carbon;
|
2022-09-05 10:57:20 +02:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Support\Facades\Queue;
|
|
|
|
use Tests\TestCase;
|
2022-09-05 11:37:54 +02:00
|
|
|
use Zoomyboy\LaravelNami\Fakes\MemberFake;
|
2022-09-05 10:57:20 +02:00
|
|
|
|
|
|
|
class DeleteTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
public function testItDeletesMemberFromNami(): void
|
|
|
|
{
|
2022-09-05 11:37:54 +02:00
|
|
|
Queue::fake();
|
2022-09-05 10:57:20 +02:00
|
|
|
$this->login()->loginNami();
|
|
|
|
$member = Member::factory()->defaults()->inNami(123)->create();
|
|
|
|
|
|
|
|
$response = $this->from('/member')->delete("/member/{$member->id}");
|
|
|
|
|
|
|
|
$response->assertRedirect('/member');
|
|
|
|
|
2023-08-15 00:01:12 +02:00
|
|
|
DeleteAction::assertPushed();
|
2022-09-05 10:57:20 +02:00
|
|
|
$this->assertDatabaseMissing('members', [
|
|
|
|
'id' => $member->id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItDoesntRunActionWhenMemberIsNotInNami(): void
|
|
|
|
{
|
2022-09-05 11:37:54 +02:00
|
|
|
Queue::fake();
|
2022-09-05 10:57:20 +02:00
|
|
|
$this->login()->loginNami();
|
|
|
|
$member = Member::factory()->defaults()->create();
|
|
|
|
|
|
|
|
$response = $this->from('/member')->delete("/member/{$member->id}");
|
|
|
|
|
|
|
|
$response->assertRedirect('/member');
|
|
|
|
|
2023-08-14 23:57:15 +02:00
|
|
|
Queue::assertNotPushed(DeleteAction::class);
|
2022-09-05 10:57:20 +02:00
|
|
|
$this->assertDatabaseMissing('members', [
|
|
|
|
'id' => $member->id,
|
|
|
|
]);
|
|
|
|
}
|
2022-09-05 11:37:54 +02:00
|
|
|
|
|
|
|
public function testTheActionDeletesNamiMember(): void
|
|
|
|
{
|
|
|
|
app(MemberFake::class)->deletes(123, Carbon::parse('yesterday'));
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
$member = Member::factory()->defaults()->inNami(123)->create();
|
|
|
|
|
2023-08-15 00:01:12 +02:00
|
|
|
DeleteAction::dispatch(123);
|
2022-09-05 11:37:54 +02:00
|
|
|
|
|
|
|
app(MemberFake::class)->assertDeleted(123, Carbon::parse('yesterday'));
|
|
|
|
}
|
2023-04-25 00:32:44 +02:00
|
|
|
|
|
|
|
public function testItDeletesMembersWithCourses(): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
$member = Member::factory()->defaults()->has(CourseMember::factory()->for(Course::factory()), 'courses')->create();
|
|
|
|
|
|
|
|
$member->delete();
|
|
|
|
|
|
|
|
$this->assertDatabaseCount('members', 0);
|
|
|
|
}
|
2022-09-05 10:57:20 +02:00
|
|
|
}
|