-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreatetransactionsTest.php
97 lines (83 loc) · 2.79 KB
/
CreatetransactionsTest.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
<?php
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Models\User;
use App\Models\Contract\Contract;
use Tests\TestCase;
class ContractControllerCreatetransactionsTest extends TestCase{
use RefreshDatabase;
public function test_create_transactions_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("/create-transactions", [
'amount' => 100,
'contract_id' => $contract->id
]);
// Assert the response
$response->assertStatus(200);
$response->assertExactJson(['success' => true, 'message' => 'Contract Splitted Successfully']);
}
public function test_create_transactions_validation_failure()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Call api endpoint
$response = $this->postJson("/create-transactions", [
'amount' => 'abc',
'contract_id' => '123'
]);
// Assert the response
$response->assertStatus(400);
$response->assertExactJson(
[
'success' => false,
'message' => 'The amount must be a number.'
]
);
}
public function test_create_transactions_contract_not_found()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Call api endpoint
$response = $this->postJson("/create-transactions", [
'amount' => 100,
'contract_id' => 123
]);
// Assert the response
$response->assertStatus(404);
$response->assertExactJson(
[
'success' => false,
'message' => 'Contract not found'
]
);
}
public function test_create_transactions_amount_credit_to_wallet_cannot_be_splitted()
{
// 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("/create-transactions", [
'amount' => 100,
'contract_id' => $contract->id
]);
// Assert the response
$response->assertStatus(400);
$response->assertExactJson(
[
'success' => false,
'message' => 'Amount credited to wallet cannot be splitted to subaccounts. Kindly revise the subaccount settings and try again.'
]
);
}
}