|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use Tests\TestCase; |
|
6
|
|
|
use Illuminate\Foundation\Testing\WithFaker; |
|
7
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase; |
|
8
|
|
|
|
|
9
|
|
|
use App\Policies\ApplicantPolicy; |
|
10
|
|
|
use App\Policies\ManagerPolicy; |
|
11
|
|
|
|
|
12
|
|
|
class ApplicantPolicyTest extends BasePolicyTest |
|
13
|
|
|
{ |
|
14
|
|
|
protected function getApplicantPolicy() { |
|
15
|
|
|
return new ApplicantPolicy(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
protected function getManagerPolicy() { |
|
19
|
|
|
return new ManagerPolicy(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testView() |
|
23
|
|
|
{ |
|
24
|
|
|
//Test 1: User is the applicant |
|
25
|
|
|
//Expect to be allowed to view |
|
26
|
|
|
$applicant = $this->makeApplicant(); |
|
27
|
|
|
$userCanViewOwnApplicant = $this->getApplicantPolicy()->view($applicant->user, $applicant); |
|
28
|
|
|
$this->assertTrue($userCanViewOwnApplicant); |
|
29
|
|
|
|
|
30
|
|
|
//Test 2: Applicants cannot view other applicant |
|
31
|
|
|
$applicant2 = $this->makeApplicant(); |
|
32
|
|
|
$user1CanViewApplicant2 = $this->getApplicantPolicy()->view($applicant->user, $applicant2); |
|
33
|
|
|
$this->assertFalse($user1CanViewApplicant2); |
|
34
|
|
|
|
|
35
|
|
|
//Test 3: new manager cannot view new applicant |
|
36
|
|
|
$jillManager = $this->makeManager(); |
|
|
|
|
|
|
37
|
|
|
$jennyApplicant = $this->makeApplicant(); |
|
38
|
|
|
$canManagerViewapplicant = $this->getApplicantPolicy()->view($applicant->user, $jennyApplicant); |
|
39
|
|
|
$this->assertFalse($canManagerViewapplicant); |
|
40
|
|
|
|
|
41
|
|
|
//Test 3.5: applicants can view manager |
|
42
|
|
|
$steveManager = $this->makeManager(); |
|
43
|
|
|
$bobApplicant = $this->makeApplicant(); |
|
44
|
|
|
$canApplicantViewManager = $this->getManagerPolicy()->view($bobApplicant->user, $steveManager); |
|
45
|
|
|
$this->assertTrue($canApplicantViewManager); |
|
46
|
|
|
|
|
47
|
|
|
//Test 4: applicant starts a job application but doesn't submit. |
|
48
|
|
|
// Manager should not be able to view applicant |
|
49
|
|
|
|
|
50
|
|
|
//Test 5: applicant submits a job application. Job's manager should be |
|
51
|
|
|
// able to view applicant. |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|