1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Unit; |
4
|
|
|
|
5
|
|
|
use Tests\TestCase; |
6
|
|
|
use Illuminate\Foundation\Testing\WithFaker; |
7
|
|
|
use Illuminate\Support\Facades\Lang; |
8
|
|
|
|
9
|
|
|
use App\Models\Applicant; |
10
|
|
|
use App\Models\Criteria; |
11
|
|
|
use App\Models\Lookup\Department; |
12
|
|
|
use App\Models\JobPoster; |
13
|
|
|
use App\Models\JobPosterKeyTask; |
14
|
|
|
use App\Models\JobPosterQuestion; |
15
|
|
|
use App\Models\Lookup\LanguageRequirement; |
16
|
|
|
use App\Models\Manager; |
17
|
|
|
use App\Models\Lookup\Province; |
18
|
|
|
use App\Models\Lookup\SecurityClearance; |
19
|
|
|
use Doctrine\Common\Cache\VoidCache; |
20
|
|
|
|
21
|
|
|
class JobControllerTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Run parent setup and provide reusable factories. |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
protected function setUp() : void |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
|
32
|
|
|
$this->faker = \Faker\Factory::create(); |
|
|
|
|
33
|
|
|
$this->faker_fr = \Faker\Factory::create('fr_FR'); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$this->manager = factory(Manager::class)->create(); |
|
|
|
|
36
|
|
|
$this->jobPoster = factory(JobPoster::class)->create([ |
|
|
|
|
37
|
|
|
'manager_id' => $this->manager->id |
38
|
|
|
]); |
39
|
|
|
|
40
|
|
|
$this->otherManager = factory(Manager::class)->create(); |
|
|
|
|
41
|
|
|
$this->otherJobPoster = factory(JobPoster::class)->create([ |
|
|
|
|
42
|
|
|
'manager_id' => $this->otherManager->id |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
$this->publishedJob = factory(JobPoster::class)->states('published')->create(); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Ensure an unauthorized user receives the correct job poster view. |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function testGuestSingleView() : void |
54
|
|
|
{ |
55
|
|
|
$response = $this->get('jobs/' . $this->publishedJob->id); |
56
|
|
|
$response->assertStatus(200); |
57
|
|
|
$response->assertSee(Lang::get('applicant/job_post')['apply']['login_link_title']); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Ensure an authorized applicant receives the correct job poster view. |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function testApplicantSingleView() : void |
66
|
|
|
{ |
67
|
|
|
$applicant = factory(Applicant::class)->create(); |
68
|
|
|
|
69
|
|
|
$response = $this->actingAs($applicant->user) |
70
|
|
|
->get('jobs/' . $this->publishedJob->id); |
71
|
|
|
$response->assertStatus(200); |
72
|
|
|
$response->assertSee(Lang::get('applicant/job_post')['apply']['apply_link_title']); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Ensure a manager can view their index page. |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public function testManagerIndexView() : void |
81
|
|
|
{ |
82
|
|
|
$response = $this->actingAs($this->manager->user) |
83
|
|
|
->get('manager/jobs'); |
84
|
|
|
$response->assertStatus(200); |
85
|
|
|
|
86
|
|
|
$response->assertSee('<h3>' . $this->jobPoster->title . '</h3>'); |
87
|
|
|
$response->assertDontSee('<h3>' . $this->otherJobPoster->title . '</h3>'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Ensure a manager can view the create Job Poster form. |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
public function testManagerCreateView() : void |
96
|
|
|
{ |
97
|
|
|
$response = $this->actingAs($this->manager->user) |
98
|
|
|
->get('manager/jobs/create'); |
99
|
|
|
$response->assertStatus(200); |
100
|
|
|
|
101
|
|
|
$response->assertSee('<h2 class="heading--01">' . Lang::get('manager/job_create')['title'] . '</h2>'); |
102
|
|
|
$response->assertViewIs('manager.job_create'); |
103
|
|
|
|
104
|
|
|
$response->assertSee(Lang::get('manager/job_create', [], 'en')['questions']['00']); |
105
|
|
|
$response->assertSee(Lang::get('manager/job_create', [], 'fr')['questions']['00']); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Ensure a manager can create a Job Poster. |
110
|
|
|
* |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
|
|
public function testManagerCreate() : void |
114
|
|
|
{ |
115
|
|
|
$newJob = [ |
116
|
|
|
'term_qty' => $this->faker->numberBetween(1, 4), |
117
|
|
|
'salary_min' => $this->faker->numberBetween(60000, 80000), |
118
|
|
|
'salary_max' => $this->faker->numberBetween(80000, 100000), |
119
|
|
|
'noc' => $this->faker->numberBetween(1, 9999), |
120
|
|
|
'classification' => $this->faker->regexify('[A-Z]{2}-0[1-5]'), |
121
|
|
|
'manager_id' => $this->manager->id, |
122
|
|
|
'published' => false, |
123
|
|
|
'remote_work_allowed' => $this->faker->boolean(50), |
124
|
|
|
'open_date' => $this->faker->date('Y-m-d', strtotime('+1 day')), |
125
|
|
|
'open_time' => $this->faker->time(), |
126
|
|
|
'close_date' => $this->faker->date('Y-m-d', strtotime('+2 weeks')), |
127
|
|
|
'close_time' => $this->faker->time(), |
128
|
|
|
'start_date_time' => $this->faker->date('Y-m-d', strtotime('+2 weeks')) . ' ' . $this->faker->time(), |
129
|
|
|
'security_clearance' => SecurityClearance::inRandomOrder()->first()->id, |
130
|
|
|
'language_requirement' => LanguageRequirement::inRandomOrder()->first()->id, |
131
|
|
|
'department' => Department::inRandomOrder()->first()->id, |
132
|
|
|
'province' => Province::inRandomOrder()->first()->id, |
133
|
|
|
'city' => $this->faker->city, |
134
|
|
|
'title' => [ |
135
|
|
|
'en' => $this->faker->word, |
136
|
|
|
'fr' => $this->faker_fr->word |
137
|
|
|
], |
138
|
|
|
'impact' => [ |
139
|
|
|
'en' => $this->faker->paragraphs( |
140
|
|
|
2, |
141
|
|
|
true |
142
|
|
|
), |
143
|
|
|
'fr' => $this->faker_fr->paragraphs( |
144
|
|
|
2, |
145
|
|
|
true |
146
|
|
|
) |
147
|
|
|
], |
148
|
|
|
'branch' => [ |
149
|
|
|
'en' => $this->faker->word, |
150
|
|
|
'fr' => $this->faker_fr->word |
151
|
|
|
], |
152
|
|
|
'division' => [ |
153
|
|
|
'en' => $this->faker->word, |
154
|
|
|
'fr' => $this->faker_fr->word |
155
|
|
|
], |
156
|
|
|
'education' => [ |
157
|
|
|
'en' => $this->faker->sentence(), |
158
|
|
|
'fr' => $this->faker_fr->sentence() |
159
|
|
|
], |
160
|
|
|
'submit' => '', |
161
|
|
|
]; |
162
|
|
|
|
163
|
|
|
$dbValues = array_slice($newJob, 0, 8); |
164
|
|
|
|
165
|
|
|
$response = $this->followingRedirects() |
166
|
|
|
->actingAs($this->manager->user) |
167
|
|
|
->post('manager/jobs/', $newJob); |
168
|
|
|
$response->assertStatus(200); |
169
|
|
|
$response->assertViewIs('applicant.job_post'); |
170
|
|
|
$this->assertDatabaseHas('job_posters', $dbValues); |
171
|
|
|
$response->assertSee(Lang::get('applicant/job_post')['apply']['edit_link_title']); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Ensure a manager can edit an unpublished Job Poster they created. |
176
|
|
|
* |
177
|
|
|
* @return void |
178
|
|
|
*/ |
179
|
|
|
public function testManagerEditView() : void |
180
|
|
|
{ |
181
|
|
|
$response = $this->actingAs($this->manager->user) |
182
|
|
|
->get('manager/jobs/' . $this->jobPoster->id . '/edit'); |
183
|
|
|
|
184
|
|
|
$response->assertStatus(200); |
185
|
|
|
$response->assertViewIs('manager.job_create'); |
186
|
|
|
// Check for a handful of properties |
187
|
|
|
$response->assertSee($this->jobPoster->city); |
188
|
|
|
$response->assertSee($this->jobPoster->education); |
189
|
|
|
$response->assertSee($this->jobPoster->title); |
190
|
|
|
$response->assertSee($this->jobPoster->impact); |
191
|
|
|
$response->assertSee($this->jobPoster->branch); |
192
|
|
|
$response->assertSee($this->jobPoster->division); |
193
|
|
|
$response->assertSee($this->jobPoster->education); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|