-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateuserTest.php
More file actions
82 lines (73 loc) · 2.33 KB
/
CreateuserTest.php
File metadata and controls
82 lines (73 loc) · 2.33 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Models\User;
use Tests\TestCase;
class UserControllerCreateuserTest extends TestCase
{
use RefreshDatabase;
public function test_create_user_success()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Post request to the api endpoint
$response = $this->postJson("/", [
'first_name' => 'John',
'last_name' => 'Doe',
'user_type' => 'admin',
'email' => 'john@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'status' => 'live'
]);
// Assert the response
$response->assertStatus(200)
->assertJson([
"success" => true,
"message" => "Account Created."
]);
}
public function test_create_user_fails_invalid_data()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Post request to the api endpoint
$response = $this->postJson("/", [
'first_name' => 'John',
'last_name' => 'Doe',
'user_type' => 'admin',
'email' => 'john',
'password' => 'password',
'password_confirmation' => 'password',
'status' => 'live'
]);
// Assert the response
$response->assertStatus(400)
->assertJson([
"success" => false,
"message" => "The email must be a valid email address."
]);
}
public function test_create_user_fails_missing_data()
{
// Create a user and authenticate
$user = User::factory()->create();
$this->actingAs($user);
// Post request to the api endpoint
$response = $this->postJson("/", [
'first_name' => 'John',
'last_name' => 'Doe',
'user_type' => 'admin',
'password' => 'password',
'password_confirmation' => 'password',
'status' => 'live'
]);
// Assert the response
$response->assertStatus(400)
->assertJson([
"success" => false,
"message" => "The email field is required."
]);
}
}