adrema/tests/Feature/Member/DeleteTest.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2022-09-05 10:57:20 +02:00
<?php
namespace Tests\Feature\Member;
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');
Queue::assertPushed(DeleteJob::class, fn ($job) => $job->memberId === $member->id);
$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();
dispatch(new DeleteJob($member));
app(MemberFake::class)->assertDeleted(123, Carbon::parse('yesterday'));
$this->assertNull($member->fresh()->nami_id);
}
2022-09-05 10:57:20 +02:00
}