-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddsubaccountTest.php
117 lines (102 loc) · 3.43 KB
/
AddsubaccountTest.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
use App\Models\User;
use App\Models\Contract\Contract;
use Tests\TestCase;
class ContractControllerAddsubaccountTest extends TestCase
{
public function test_add_subaccount_success()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Create a contract
$contract = Contract::factory()->create();
// Call api endpoint
$response = $this->postJson("/add-subaccount/{$contract->id}", [
'users' => [
[
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'johndoe@example.com',
'percent_amount' => 10,
'fixed_amount' => 0,
'access_type' => 'read'
]
]
]);
// Assert the response
$response->assertStatus(200)
->assertJson([
'success' => true,
'message' => 'User Added to Contract Successfully'
]);
}
public function test_add_subaccount_failure_missing_user_data()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Create a contract
$contract = Contract::factory()->create();
// Call api endpoint
$response = $this->postJson("/add-subaccount/{$contract->id}", []);
// Assert the response
$response->assertStatus(400)
->assertJson([
'success' => false,
'message' => 'The users field is required.'
]);
}
public function test_add_subaccount_failure_invalid_percent_amount()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Create a contract
$contract = Contract::factory()->create();
// Call api endpoint
$response = $this->postJson("/add-subaccount/{$contract->id}", [
'users' => [
[
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'johndoe@example.com',
'percent_amount' => 110,
'fixed_amount' => 0,
'access_type' => 'read'
]
]
]);
// Assert the response
$response->assertStatus(422)
->assertJson([
'success' => false,
'message' => 'Total percentage assigned is greater than 100. Kindly revise and try again'
]);
}
public function test_add_subaccount_failure_contract_not_found()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Call api endpoint
$response = $this->postJson("/add-subaccount/1000", [
'users' => [
[
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'johndoe@example.com',
'percent_amount' => 110,
'fixed_amount' => 0,
'access_type' => 'read'
]
]
]);
// Assert the response
$response->assertStatus(400)
->assertJson([
'success' => false,
'message' => 'Contract not found'
]);
}
}