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
|
|
|
|
13
|
|
|
class ApplicantPolicyTest extends BasePolicyTest |
14
|
|
|
{ |
15
|
|
|
protected function getApplicantPolicy() { |
16
|
|
|
return new ApplicantPolicy(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function getManagerPolicy() { |
20
|
|
|
return new ManagerPolicy(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testView() |
24
|
|
|
{ |
25
|
|
|
//Test 1: User is the applicant |
26
|
|
|
//Expect to be allowed to view |
27
|
|
|
$applicant = $this->makeApplicant(); |
28
|
|
|
$userCanViewOwnApplicant = $this->getApplicantPolicy()->view($applicant->user, $applicant); |
29
|
|
|
$this->assertTrue($userCanViewOwnApplicant); |
30
|
|
|
|
31
|
|
|
//Test 2: Applicants cannot view other applicant |
32
|
|
|
$applicant2 = $this->makeApplicant(); |
33
|
|
|
$user1CanViewApplicant2 = $this->getApplicantPolicy()->view($applicant->user, $applicant2); |
34
|
|
|
$this->assertFalse($user1CanViewApplicant2); |
35
|
|
|
|
36
|
|
|
//Test 3: new manager cannot view new applicant |
37
|
|
|
$jennyApplicant = $this->makeApplicant(); |
38
|
|
|
$jillManager = $this->makeManager(); |
39
|
|
|
# Make a job poster first to satisfy managerCanViewApplicant? |
40
|
|
|
//$canManagerViewapplicant = $this->getApplicantPolicy()->view($jillManager->user, $jennyApplicant); |
41
|
|
|
//$this->assertFalse($canManagerViewapplicant); |
42
|
|
|
|
43
|
|
|
//Test 3.5: applicants can view manager |
44
|
|
|
$steveManager = $this->makeManager(); |
45
|
|
|
$bobApplicant = $this->makeApplicant(); |
46
|
|
|
$canApplicantViewManager = $this->getManagerPolicy()->view($bobApplicant->user, $steveManager); |
47
|
|
|
$this->assertTrue($canApplicantViewManager); |
48
|
|
|
|
49
|
|
|
//Test 4: applicant starts a job application but doesn't submit. |
50
|
|
|
// Manager should not be able to view applicant |
51
|
|
|
// $jackManager = $this->makeManager(); |
52
|
|
|
// $juneApplicant= $this->makeApplicant(); |
53
|
|
|
// $canManagerViewApplicant = $this->getApplicantPolicy()->view($jackManager->user, $juneApplicant); |
54
|
|
|
// $this->assertTrue($canManagerViewapplicant); |
55
|
|
|
|
56
|
|
|
//Test 5: applicant submits a job application. Job's manager should be |
57
|
|
|
// able to view applicant. |
58
|
|
|
|
59
|
|
|
public function testView() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
//Test 1: applicant can view applicant (self) |
62
|
|
|
$bobApplicant = $this->createApplicant(); |
63
|
|
|
$userCanViewSelf = $this->getApplicantPolicy()->view($bobApplicant->user, $bobApplicant); |
64
|
|
|
$this->assertTrue($userCanViewSelf); |
65
|
|
|
|
66
|
|
|
//Test 2: qpplicant cannot view other applicant |
67
|
|
|
$katyApplicant = $this->createApplicant(); |
68
|
|
|
$user1CanViewApplicant2 = $this->getApplicantPolicy()->view($katyApplicant->user, $bobApplicant); |
69
|
|
|
$this->assertFalse($user1CanViewApplicant2); |
70
|
|
|
|
71
|
|
|
//Test 3: manager cannot view applicant |
72
|
|
|
$jillManager = $this->createManager(); |
73
|
|
|
$jennyApplicant = $this->createApplicant(); |
74
|
|
|
$canManagerViewapplicant = $this->getApplicantPolicy()->view($jillManager->user, $jennyApplicant); |
75
|
|
|
$this->assertFalse($canManagerViewapplicant); |
76
|
|
|
|
77
|
|
|
//Test 4: applicant starts a job application but doesn't submit. |
78
|
|
|
// Manager should not be able to view applicant |
79
|
|
|
|
80
|
|
|
//Test 5: applicant submits a job application. Job's manager should be |
81
|
|
|
// able to view applicant. |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testCreate() { |
85
|
|
|
//Test 1: applicant cannot create user |
86
|
|
|
$joeApplicant = $this->createApplicant(); |
87
|
|
|
$canApplicantCreateUser = $this->getApplicantPolicy()->create($joeApplicant->user); |
88
|
|
|
$this->assertFalse($canApplicantCreateUser); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
// git pull origin this |
93
|
|
|
|
94
|
|
|
// Move these tests to another file? One test per file? Ask G or T. |
95
|
|
|
|
96
|
|
|
|