Skip to content

Commit

Permalink
Test DeleteUserAction
Browse files Browse the repository at this point in the history
  • Loading branch information
range-of-motion committed Oct 2, 2020
1 parent d9447f9 commit 50d888f
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/Unit/Actions/DeleteUserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Tests\Unit\Actions;

use App\Actions\DeleteUserAction;
use App\Exceptions\UserNotFoundException;
use App\Models\User;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;

class DeleteUserTest extends TestCase
{
public function testUserNotFound(): void
{
$this->expectException(UserNotFoundException::class);

(new DeleteUserAction())->execute(999);
}

public function testSuccessfulAvatarCleared(): void
{
$image = \Image::canvas(500, 500, '#CCC');

Storage::put('public/avatars/yabadabadoo.png', (string) $image->encode());

$user = factory(User::class)->create([
'avatar' => 'yabadabadoo.png'
]);

$this->assertFileExists(storage_path() . '/app/public/avatars/yabadabadoo.png');

(new DeleteUserAction())->execute($user->id);

$this->assertFileNotExists(storage_path() . '/app/public/avatars/yabadabadoo.png');
}

public function testSuccessfulColumnsCleared(): void
{
$user = factory(User::class)->create([
'name' => 'John Doe',
'email' => '[email protected]'
]);

$this->assertNotNull($user->name);
$this->assertNotNull($user->email);

(new DeleteUserAction())->execute($user->id);

$user->refresh();

$this->assertNull($user->name);
$this->assertNull($user->email);
}
}

0 comments on commit 50d888f

Please sign in to comment.