adrema/tests/Feature/Member/DeleteTest.php

72 lines
2.1 KiB
PHP
Raw Normal View History

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;
2022-09-05 10:57:20 +02:00
use App\Member\DeleteJob;
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');
2022-11-16 23:39:44 +01:00
Queue::assertPushed(DeleteJob::class, fn ($job) => 123 === $job->namiId);
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');
Queue::assertNotPushed(DeleteJob::class);
$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();
2022-11-16 23:39:44 +01:00
dispatch(new DeleteJob(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
}