1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Unit\Validators; |
4
|
|
|
|
5
|
|
|
use Tests\TestCase; |
6
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase; |
7
|
|
|
use App\Services\Validation\Rules\ContainsObjectWithAttributeRule; |
8
|
|
|
use Illuminate\Support\Facades\Validator; |
9
|
|
|
use Illuminate\Support\Facades\Hash; |
10
|
|
|
use App\Models\Applicant; |
11
|
|
|
use App\Models\User; |
12
|
|
|
use App\Services\Validation\Requests\UpdateApplicationProfileValidator; |
13
|
|
|
|
14
|
|
|
class UpdateApplicationProfileValidatorTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function testUpdatingBasicProfileIsValid() |
17
|
|
|
{ |
18
|
|
|
$applicant = factory(Applicant::class)->create(); |
19
|
|
|
$data = [ |
20
|
|
|
'profile_name' => $applicant->user->name, |
21
|
|
|
'profile_email' => $applicant->user->email, |
22
|
|
|
'twitter_username' => 'Test_person', |
23
|
|
|
'linkedin_url' => 'www.linkedin.com/in/test-person', |
24
|
|
|
'tagline' => 'GO FOR IT', |
25
|
|
|
]; |
26
|
|
|
$validator = new UpdateApplicationProfileValidator($applicant); |
27
|
|
|
$this->assertTrue($validator->isValid($data)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testNotValidWhenNameIsEmpty() |
31
|
|
|
{ |
32
|
|
|
$applicant = factory(Applicant::class)->create(); |
33
|
|
|
$data = [ |
34
|
|
|
'profile_name' => '', |
35
|
|
|
'profile_email' => $applicant->user->email, |
36
|
|
|
'twitter_username' => 'Test_person', |
37
|
|
|
'linkedin_url' => 'www.linkedin.com/in/test-person', |
38
|
|
|
'tagline' => 'GO FOR IT', |
39
|
|
|
]; |
40
|
|
|
$validator = new UpdateApplicationProfileValidator($applicant); |
41
|
|
|
$this->assertFalse($validator->isValid($data)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testNotValidWhenNEmailIsEmpty() |
45
|
|
|
{ |
46
|
|
|
$applicant = factory(Applicant::class)->create(); |
47
|
|
|
$data = [ |
48
|
|
|
'profile_name' => $applicant->user->name, |
49
|
|
|
'profile_email' => '', |
50
|
|
|
'twitter_username' => 'Test_person', |
51
|
|
|
'linkedin_url' => 'www.linkedin.com/in/test-person', |
52
|
|
|
'tagline' => 'GO FOR IT', |
53
|
|
|
]; |
54
|
|
|
$validator = new UpdateApplicationProfileValidator($applicant); |
55
|
|
|
$this->assertFalse($validator->isValid($data)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testNotValidWhenNEmailSameAsAnotherUser() |
59
|
|
|
{ |
60
|
|
|
$applicant1 = factory(Applicant::class)->create(); |
61
|
|
|
$applicant2 = factory(Applicant::class)->create(); |
62
|
|
|
$data = [ |
63
|
|
|
'profile_name' => $applicant1->user->name, |
64
|
|
|
'profile_email' => $applicant2->user->email, |
65
|
|
|
'twitter_username' => 'Test_person', |
66
|
|
|
'linkedin_url' => 'www.linkedin.com/in/test-person', |
67
|
|
|
'tagline' => 'GO FOR IT', |
68
|
|
|
]; |
69
|
|
|
$validator = new UpdateApplicationProfileValidator($applicant1); |
70
|
|
|
$this->assertFalse($validator->isValid($data)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testUpdatePasswordValidWithOldAndConfirm() |
74
|
|
|
{ |
75
|
|
|
$user = factory(User::class)->create([ |
76
|
|
|
'password' => Hash::make('Testing123!') |
77
|
|
|
]); |
78
|
|
|
$applicant = factory(Applicant::class)->create(['user_id' => $user->id]); |
79
|
|
|
$data = [ |
80
|
|
|
'profile_name' => $applicant->user->name, |
81
|
|
|
'profile_email' => $applicant->user->email, |
82
|
|
|
'old_password' => "Testing123!", |
83
|
|
|
'new_password' => 'NewPassword123!', |
84
|
|
|
'new_password_confirmation' => 'NewPassword123!', |
85
|
|
|
'twitter_username' => 'Test_person', |
86
|
|
|
'linkedin_url' => 'www.linkedin.com/in/test-person', |
87
|
|
|
'tagline' => 'GO FOR IT', |
88
|
|
|
]; |
89
|
|
|
$this->be($applicant->user); |
90
|
|
|
$validator = new UpdateApplicationProfileValidator($applicant); |
91
|
|
|
$this->assertTrue($validator->isValid($data)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testUpdatePasswordFailsWithoutConfirm() |
95
|
|
|
{ |
96
|
|
|
$user = factory(User::class)->create([ |
97
|
|
|
'password' => Hash::make('Testing123!') |
98
|
|
|
]); |
99
|
|
|
$applicant = factory(Applicant::class)->create(['user_id' => $user->id]); |
100
|
|
|
$data = [ |
101
|
|
|
'profile_name' => $applicant->user->name, |
102
|
|
|
'profile_email' => $applicant->user->email, |
103
|
|
|
'old_password' => 'Testing123!', |
104
|
|
|
'new_password' => 'NewPassword123!', |
105
|
|
|
'twitter_username' => 'Test_person', |
106
|
|
|
'linkedin_url' => 'www.linkedin.com/in/test-person', |
107
|
|
|
'tagline' => 'GO FOR IT', |
108
|
|
|
]; |
109
|
|
|
$this->be($applicant->user); |
110
|
|
|
$validator = new UpdateApplicationProfileValidator($applicant); |
111
|
|
|
$this->assertFalse($validator->isValid($data)); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testUpdatePasswordFailsWithBadConfirm() |
115
|
|
|
{ |
116
|
|
|
$user = factory(User::class)->create([ |
117
|
|
|
'password' => Hash::make('Testing123!') |
118
|
|
|
]); |
119
|
|
|
$applicant = factory(Applicant::class)->create(['user_id' => $user->id]); |
120
|
|
|
$data = [ |
121
|
|
|
'profile_name' => $applicant->user->name, |
122
|
|
|
'profile_email' => $applicant->user->email, |
123
|
|
|
'old_password' => 'Testing123!', |
124
|
|
|
'new_password' => 'NewPassword123!', |
125
|
|
|
'new_password_confirmation' => 'DifferentPassword123!', |
126
|
|
|
'twitter_username' => 'Test_person', |
127
|
|
|
'linkedin_url' => 'www.linkedin.com/in/test-person', |
128
|
|
|
'tagline' => 'GO FOR IT', |
129
|
|
|
]; |
130
|
|
|
$this->be($applicant->user); |
131
|
|
|
$validator = new UpdateApplicationProfileValidator($applicant); |
132
|
|
|
$this->assertFalse($validator->isValid($data)); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testUpdatePasswordFailsWithIllegalPassword() |
136
|
|
|
{ |
137
|
|
|
$user = factory(User::class)->create([ |
138
|
|
|
'password' => Hash::make('Testing123!') |
139
|
|
|
]); |
140
|
|
|
$applicant = factory(Applicant::class)->create(['user_id' => $user->id]); |
141
|
|
|
$data = [ |
142
|
|
|
'profile_name' => $applicant->user->name, |
143
|
|
|
'profile_email' => $applicant->user->email, |
144
|
|
|
'old_password' => 'Testing123!', |
145
|
|
|
'new_password' => 'NewPassword', |
146
|
|
|
'new_password_confirmation' => 'NewPassword', |
147
|
|
|
'twitter_username' => 'Test_person', |
148
|
|
|
'linkedin_url' => 'www.linkedin.com/in/test-person', |
149
|
|
|
'tagline' => 'GO FOR IT', |
150
|
|
|
]; |
151
|
|
|
$this->be($applicant->user); |
152
|
|
|
$validator = new UpdateApplicationProfileValidator($applicant); |
153
|
|
|
$this->assertFalse($validator->isValid($data)); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function testUpdatePasswordFailsWithBadOldPassword() |
157
|
|
|
{ |
158
|
|
|
$applicant = factory(Applicant::class)->create(); |
159
|
|
|
$data = [ |
160
|
|
|
'profile_name' => $applicant->user->name, |
161
|
|
|
'profile_email' => $applicant->user->email, |
162
|
|
|
'old_password' => 'NotTheRightPassword123!', |
163
|
|
|
'new_password' => 'NewPassword123!', |
164
|
|
|
'new_password_confirmation' => 'NewPassword123!', |
165
|
|
|
'twitter_username' => 'Test_person', |
166
|
|
|
'linkedin_url' => 'www.linkedin.com/in/test-person', |
167
|
|
|
'tagline' => 'GO FOR IT', |
168
|
|
|
]; |
169
|
|
|
$this->be($applicant->user); |
170
|
|
|
$validator = new UpdateApplicationProfileValidator($applicant); |
171
|
|
|
$this->assertFalse($validator->isValid($data)); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|