-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathApiContactControllerTest.php
More file actions
99 lines (75 loc) · 2.49 KB
/
ApiContactControllerTest.php
File metadata and controls
99 lines (75 loc) · 2.49 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Tests\Api\Contact;
use App\Contact;
use Tests\ApiTestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ApiContactControllerTest extends ApiTestCase
{
use DatabaseTransactions;
public function test_it_gets_a_list_of_contacts()
{
$user = $this->signin();
$contact = factory(Contact::class, 10)->create([
'account_id' => $user->account_id,
]);
$response = $this->json('GET', '/api/contacts');
$response->assertStatus(200);
$this->assertEquals(
10,
count($response->decodeResponseJson()['data'])
);
}
public function test_it_gets_a_list_of_contacts_with_pagination_everytime()
{
$user = $this->signin();
$contact = factory(Contact::class, 10)->create([
'account_id' => $user->account_id,
]);
$response = $this->json('GET', '/api/contacts');
$response->assertJsonFragment([
'total' => 10,
'current_page' => 1,
]);
}
public function test_it_applies_the_limit_parameter_in_search()
{
$user = $this->signin();
$contact = factory(Contact::class, 10)->create([
'account_id' => $user->account_id,
]);
$response = $this->json('GET', '/api/contacts?limit=1');
$response->assertJsonFragment([
'total' => 10,
'current_page' => 1,
'per_page' => '1',
'last_page' => 10,
]);
$response = $this->json('GET', '/api/contacts?limit=2');
$response->assertJsonFragment([
'total' => 10,
'current_page' => 1,
'per_page' => '2',
'last_page' => 5,
]);
}
public function test_it_is_possible_to_search_for_a_specific_contact()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
'first_name' => 'roger',
]);
// create 10 other contacts named Bob (to avoid random conflicts if we took a random name)
$contact = factory(Contact::class, 10)->create([
'account_id' => $user->account_id,
'first_name' => 'bob',
]);
$response = $this->json('GET', '/api/contacts?query=ro');
$response->assertStatus(200);
$response->assertJsonFragment([
'first_name' => 'roger',
'total' => 1,
'query' => 'ro',
]);
}
}