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