-
Notifications
You must be signed in to change notification settings - Fork 56
/
UserTest.php
81 lines (67 loc) · 2.14 KB
/
UserTest.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
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace Tests\Feature;
use App\User;
use Tests\TestCase;
use Laravel\Passport\Passport;
use Illuminate\Foundation\Testing\RefreshDatabase;
class UserTest extends TestCase
{
use RefreshDatabase;
public function setUp()
{
parent::setUp();
$this->user = factory(User::class)->create();
Passport::actingAs($this->user, ['*']);
}
/** @test */
public function user_can_create_user()
{
$this->json('POST', 'api/v1/user', [
'name' => 'John',
'email' => 'john.doe@gmail.com',
'password' => 'secret-password',
], [$this->header])->assertStatus(201);
$this->assertInstanceOf(User::class, $this->user);
}
/** @test */
public function user_can_read_single_user()
{
$this->json('GET', 'api/v1/user/'.$this->user->id, [], [$this->header])->assertJson([
'data' => [
'id' => $this->user->id,
'name' => $this->user->name,
'email' => $this->user->email,
'created_at' => $this->user->created_at,
'updated_at' => $this->user->updated_at,
],
]);
}
/** @test */
public function user_can_read_all_user()
{
$this->user = factory(User::class, 2)->create();
$this->json('GET', 'api/v1/user', [], [$this->header])->assertStatus(200);
}
/** @test */
public function user_can_update_user()
{
$response = $this->json('PUT', 'api/v1/user/'.$this->user->id, [
'name' => 'another name',
'email' => 'another@email.com',
], [$this->header])->assertJson([
'data' => [
'id' => $this->user->id,
'name' => 'another name',
'email' => 'another@email.com',
'created_at' => $this->user->created_at,
'updated_at' => $this->user->updated_at,
],
]);
$response->assertStatus(200);
}
/** @test */
public function user_can_delete_user()
{
$this->json('DELETE', 'api/v1/user/'.$this->user->id, [], [$this->header])->assertStatus(200);
}
}