-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetagentTest.php
46 lines (40 loc) · 1.16 KB
/
GetagentTest.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
<?php
use App\Models\User;
use App\Models\Agent;
use Tests\TestCase;
class AgentControllerGetagentTest extends TestCase
{
/**
* Test the getAgent method returns a success response with the valid data
*
* @return void
*/
public function testGetAgentSuccess()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Call api endpoint
$agent = Agent::factory()->create();
$response = $this->getJson("/agents/{$agent->id}");
// Assert the response
$response->assertStatus(200);
$response->assertJsonStructure(['data' => ['users', 'accounts']]);
}
/**
* Test the getAgent method returns a bad request response when no agent is found
*
* @return void
*/
public function testGetAgentFailure()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Call api endpoint
$invalidId = 9999;
$response = $this->getJson("/agents/{$invalidId}");
// Assert the response
$response->assertStatus(400);
}
}