Skip to content

Commit ce03954

Browse files
Test DeleteUserAction
1 parent 5fc987e commit ce03954

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Tests\Unit\Actions;
4+
5+
use App\Actions\DeleteUserAction;
6+
use App\Exceptions\UserNotFoundException;
7+
use App\Models\User;
8+
use Illuminate\Support\Facades\Storage;
9+
use Tests\TestCase;
10+
11+
class DeleteUserTest extends TestCase
12+
{
13+
public function testUserNotFound(): void
14+
{
15+
$this->expectException(UserNotFoundException::class);
16+
17+
(new DeleteUserAction())->execute(999);
18+
}
19+
20+
public function testSuccessfulAvatarCleared(): void
21+
{
22+
$image = \Image::canvas(500, 500, '#CCC');
23+
24+
Storage::put('public/avatars/yabadabadoo.png', (string) $image->encode());
25+
26+
$user = factory(User::class)->create([
27+
'avatar' => 'yabadabadoo.png'
28+
]);
29+
30+
$this->assertFileExists(storage_path() . '/app/public/avatars/yabadabadoo.png');
31+
32+
(new DeleteUserAction())->execute($user->id);
33+
34+
$this->assertFileNotExists(storage_path() . '/app/public/avatars/yabadabadoo.png');
35+
}
36+
37+
public function testSuccessfulColumnsCleared(): void
38+
{
39+
$user = factory(User::class)->create([
40+
'name' => 'John Doe',
41+
'email' => '[email protected]'
42+
]);
43+
44+
$this->assertNotNull($user->name);
45+
$this->assertNotNull($user->email);
46+
47+
(new DeleteUserAction())->execute($user->id);
48+
49+
$user->refresh();
50+
51+
$this->assertNull($user->name);
52+
$this->assertNull($user->email);
53+
}
54+
}

0 commit comments

Comments
 (0)