/
AdminTest.php
69 lines (52 loc) · 1.54 KB
/
AdminTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Tests\Feature;
use App\Mail\NewUser;
use App\Models\Client;
use App\Models\User;
use Faker\Factory;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use Tests\TestCase;
class AdminTest extends TestCase
{
use RefreshDatabase;
protected $admin;
protected $faker;
public function setUp()
{
parent::setUp();
// Create super admin user so don't test it
create(User::class, ['is_admin' => true]);
$this->admin = create(User::class, [
'is_admin' => true,
]);
$this->faker = Factory::create();
}
/** @test */
public function admins_can_create_client()
{
$client = [
'name' => $this->faker->name,
'email' => $this->faker->email,
'number' => $this->faker->phoneNumber,
'address' => $this->faker->address,
];
Mail::fake();
$this->signIn($this->admin)
->post('/clients', $client)
->assertRedirect('/clients');
Mail::assertSent(NewUser::class, function ($mail) use ($client) {
return $mail->hasTo($client['email']);
});
$this->assertDatabaseHas('clients', $client);
}
/** @test */
public function admins_can_delete_client()
{
$client = create(Client::class);
$this->signIn($this->admin)
->delete('/clients/' . $client->id)
->assertRedirect('/clients');
$this->assertDatabaseMissing('clients', $client->toArray());
}
}