-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetbalanceTest.php
More file actions
57 lines (48 loc) · 1.6 KB
/
GetbalanceTest.php
File metadata and controls
57 lines (48 loc) · 1.6 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
<?php
use App\Models\User;
use Tests\TestCase;
class ProviderControllerGetbalanceTest extends TestCase
{
public function testGetBalanceSuccess()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Call api endpoint
$response = $this->getJson("/provider/disbursement/get/balance");
// Assert the response
$response->assertStatus(200);
$response->assertJsonStructure($this->getExpectedStructure());
}
public function testGetBalanceServiceUnavailable()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Mock a service exception
$mock = Mockery::mock('overload:Service');
$mock->shouldReceive('getBalance')->andThrow(new \Exception());
// Call api endpoint
$response = $this->getJson("/provider/disbursement/get/balance");
// Assert the response
$response->assertStatus(500);
$response->assertJsonStructure(['message', 'errors']);
}
public function testGetBalanceUnauthorized()
{
// Call api endpoint
$response = $this->getJson("/provider/disbursement/get/balance");
// Assert the response
$response->assertStatus(401);
$response->assertJsonStructure(['message', 'errors']);
}
protected function getExpectedStructure()
{
return [
'message',
'data' => [
'balance'
]
];
}
}