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->jobPoster->criteria()->saveMany(factory(Criteria::class, 2)->make([ |
41
|
|
|
'job_poster_id' => $this->jobPoster->id |
42
|
|
|
])); |
43
|
|
|
$this->jobPoster->job_poster_key_tasks()->saveMany(factory(JobPosterKeyTask::class, 2)->make([ |
44
|
|
|
'job_poster_id' => $this->jobPoster->id |
45
|
|
|
])); |
46
|
|
|
$this->jobPoster->job_poster_questions()->saveMany(factory(JobPosterQuestion::class, 2)->make([ |
47
|
|
|
'job_poster_id' => $this->jobPoster->id |
48
|
|
|
])); |
49
|
|
|
|
50
|
|
|
$this->otherManager = factory(Manager::class)->create(); |
|
|
|
|
51
|
|
|
$this->otherJobPoster = factory(JobPoster::class)->create([ |
|
|
|
|
52
|
|
|
'manager_id' => $this->otherManager->id |
53
|
|
|
]); |
54
|
|
|
|
55
|
|
|
$this->publishedJob = factory(JobPoster::class)->states('published')->create(); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Ensure an unauthorized user receives the correct job poster view. |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function testGuestSingleView() : void |
64
|
|
|
{ |
65
|
|
|
$response = $this->get('jobs/' . $this->publishedJob->id); |
66
|
|
|
$response->assertStatus(200); |
67
|
|
|
$response->assertSee(Lang::get('applicant/job_post')['apply']['login_link_title']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Ensure an authorized applicant receives the correct job poster view. |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
public function testApplicantSingleView() : void |
76
|
|
|
{ |
77
|
|
|
$applicant = factory(Applicant::class)->create(); |
78
|
|
|
|
79
|
|
|
$response = $this->actingAs($applicant->user) |
80
|
|
|
->get('jobs/' . $this->publishedJob->id); |
81
|
|
|
$response->assertStatus(200); |
82
|
|
|
$response->assertSee(Lang::get('applicant/job_post')['apply']['apply_link_title']); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Ensure a manager can view their index page. |
87
|
|
|
* |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
public function testManagerIndexView() : void |
91
|
|
|
{ |
92
|
|
|
$response = $this->actingAs($this->manager->user) |
93
|
|
|
->get('manager/jobs'); |
94
|
|
|
$response->assertStatus(200); |
95
|
|
|
|
96
|
|
|
$response->assertSee('<h3>' . $this->jobPoster->title . '</h3>'); |
97
|
|
|
$response->assertDontSee('<h3>' . $this->otherJobPoster->title . '</h3>'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Ensure a manager can view the create Job Poster form. |
102
|
|
|
* |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
public function testManagerCreateView() : void |
106
|
|
|
{ |
107
|
|
|
$response = $this->actingAs($this->manager->user) |
108
|
|
|
->get('manager/jobs/create'); |
109
|
|
|
$response->assertStatus(200); |
110
|
|
|
|
111
|
|
|
$response->assertSee('<h2 class="heading--01">' . Lang::get('manager/job_create')['title'] . '</h2>'); |
112
|
|
|
$response->assertViewIs('manager.job_create'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Ensure a manager can create a Job Poster. |
117
|
|
|
* |
118
|
|
|
* @return void |
119
|
|
|
*/ |
120
|
|
|
public function testManagerCreate() : void |
121
|
|
|
{ |
122
|
|
|
$newJob = [ |
123
|
|
|
'term_qty' => $this->faker->numberBetween(1, 4), |
124
|
|
|
'salary_min' => $this->faker->numberBetween(60000, 80000), |
125
|
|
|
'salary_max' => $this->faker->numberBetween(80000, 100000), |
126
|
|
|
'noc' => $this->faker->numberBetween(1, 9999), |
127
|
|
|
'classification' => $this->faker->regexify('[A-Z]{2}-0[1-5]'), |
128
|
|
|
'manager_id' => $this->manager->id, |
129
|
|
|
'published' => false, |
130
|
|
|
'remote_work_allowed' => $this->faker->boolean(50), |
131
|
|
|
'open_date' => $this->faker->date('Y-m-d', strtotime('+1 day')), |
132
|
|
|
'open_time' => $this->faker->time(), |
133
|
|
|
'close_date' => $this->faker->date('Y-m-d', strtotime('+2 weeks')), |
134
|
|
|
'close_time' => $this->faker->time(), |
135
|
|
|
'start_date_time' => $this->faker->date('Y-m-d', strtotime('+2 weeks')) . ' ' . $this->faker->time(), |
136
|
|
|
'security_clearance' => SecurityClearance::inRandomOrder()->first()->id, |
137
|
|
|
'language_requirement' => LanguageRequirement::inRandomOrder()->first()->id, |
138
|
|
|
'department' => Department::inRandomOrder()->first()->id, |
139
|
|
|
'province' => Province::inRandomOrder()->first()->id, |
140
|
|
|
'city' => $this->faker->city, |
141
|
|
|
'title' => [ |
142
|
|
|
'en' => $this->faker->word, |
143
|
|
|
'fr' => $this->faker_fr->word |
144
|
|
|
], |
145
|
|
|
'impact' => [ |
146
|
|
|
'en' => $this->faker->paragraphs( |
147
|
|
|
2, |
148
|
|
|
true |
149
|
|
|
), |
150
|
|
|
'fr' => $this->faker_fr->paragraphs( |
151
|
|
|
2, |
152
|
|
|
true |
153
|
|
|
) |
154
|
|
|
], |
155
|
|
|
'branch' => [ |
156
|
|
|
'en' => $this->faker->word, |
157
|
|
|
'fr' => $this->faker_fr->word |
158
|
|
|
], |
159
|
|
|
'division' => [ |
160
|
|
|
'en' => $this->faker->word, |
161
|
|
|
'fr' => $this->faker_fr->word |
162
|
|
|
], |
163
|
|
|
'education' => [ |
164
|
|
|
'en' => $this->faker->sentence(), |
165
|
|
|
'fr' => $this->faker_fr->sentence() |
166
|
|
|
], |
167
|
|
|
'submit' => '', |
168
|
|
|
]; |
169
|
|
|
|
170
|
|
|
$dbValues = array_slice($newJob, 0, 8); |
171
|
|
|
|
172
|
|
|
$response = $this->followingRedirects() |
173
|
|
|
->actingAs($this->manager->user) |
174
|
|
|
->post('manager/jobs/', $newJob); |
175
|
|
|
$response->assertStatus(200); |
176
|
|
|
$response->assertViewIs('applicant.job_post'); |
177
|
|
|
$this->assertDatabaseHas('job_posters', $dbValues); |
178
|
|
|
$response->assertSee(Lang::get('applicant/job_post')['apply']['edit_link_title']); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Ensure a manager can edit an unpublished Job Poster they created. |
183
|
|
|
* |
184
|
|
|
* @return void |
185
|
|
|
*/ |
186
|
|
|
public function testManagerEditView() : void |
187
|
|
|
{ |
188
|
|
|
$response = $this->actingAs($this->manager->user) |
189
|
|
|
->get('manager/jobs/' . $this->jobPoster->id . '/edit'); |
190
|
|
|
|
191
|
|
|
$response->assertStatus(200); |
192
|
|
|
$response->assertViewIs('manager.job_create'); |
193
|
|
|
// Check for a handful of properties |
194
|
|
|
$response->assertSee($this->jobPoster->city); |
195
|
|
|
$response->assertSee($this->jobPoster->education); |
196
|
|
|
$response->assertSee($this->jobPoster->title); |
197
|
|
|
$response->assertSee($this->jobPoster->impact); |
198
|
|
|
$response->assertSee($this->jobPoster->branch); |
199
|
|
|
$response->assertSee($this->jobPoster->division); |
200
|
|
|
$response->assertSee($this->jobPoster->education); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|