-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddagentTest.php
More file actions
64 lines (57 loc) · 1.69 KB
/
AddagentTest.php
File metadata and controls
64 lines (57 loc) · 1.69 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
<?php
use App\Models\User;
use Tests\TestCase;
class AgentControllerAddagentTest extends TestCase
{
public function test_create_agent_success()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
$data = [
'name' => 'John Doe',
'accounts' => [1, 2],
'status' => 'active',
'users' => [1],
];
$response = $this->postJson('/core/agents/', $data);
$response->assertStatus(200);
$response->assertJsonStructure(['success','data','message']);
$this->assertDatabaseHas('agents', [
'name' => 'John Doe',
'status' => 'active',
]);
}
public function test_create_agent_failure_bad_validation()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
$data = [
'name' => '',
'accounts' => [1, 2],
'status' => 'active',
'users' => [1],
];
$response = $this->postJson('/core/agents/', $data);
$response->assertStatus(400);
$response->assertJson([
'success' => false,
'message' => 'The name field is required.',
]);
}
public function test_create_agent_failure_unauthorized()
{
$data = [
'name' => 'John Doe',
'accounts' => [1, 2],
'status' => 'active',
'users' => [1],
];
$response = $this->postJson('/core/agents/', $data);
$response->assertStatus(401);
$response->assertJson([
'message' => 'Unauthenticated.',
]);
}
}