-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Debt-ture]
updatePoolCandidateStatus
policy enhancment (#12494)
* add parent policy method for status * add testing * test policy on mutation itself * renaming (cherry picked from commit b24b60c)
- Loading branch information
1 parent
0eca1fa
commit 605633e
Showing
3 changed files
with
380 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
use App\Enums\PlacementType; | ||
use App\Enums\PoolCandidateStatus; | ||
use App\Facades\Notify; | ||
use App\Models\Community; | ||
use App\Models\CommunityExperience; | ||
use App\Models\Department; | ||
use App\Models\EducationExperience; | ||
|
@@ -51,12 +52,20 @@ class PoolCandidateUpdateTest extends TestCase | |
|
||
protected $adminUser; | ||
|
||
protected $community; | ||
|
||
protected $team; | ||
|
||
protected $teamPool; | ||
|
||
protected $poolCandidate; | ||
|
||
protected $processOperatorUser; | ||
|
||
protected $communityRecruiterUser; | ||
|
||
protected $communityAdminUser; | ||
|
||
protected $unauthorizedMessage; | ||
|
||
protected $manualStatusUpdateMutation; | ||
|
@@ -98,6 +107,8 @@ protected function setUp(): void | |
]); | ||
|
||
$this->team = Team::factory()->create(['name' => 'test-team']); | ||
$this->community = Community::factory()->create(['name' => ['en' => 'test-team EN', 'fr' => 'test-team FR']]); | ||
|
||
$this->poolOperatorUser = User::factory() | ||
->asPoolOperator($this->team->name) | ||
->create([ | ||
|
@@ -129,8 +140,27 @@ protected function setUp(): void | |
$this->teamPool = Pool::factory()->create([ | ||
'user_id' => $this->poolOperatorUser->id, | ||
'team_id' => $this->team->id, | ||
'community_id' => $this->community->id, | ||
]); | ||
|
||
$this->processOperatorUser = User::factory() | ||
->asProcessOperator($this->teamPool->id) | ||
->create([ | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$this->communityRecruiterUser = User::factory() | ||
->asCommunityRecruiter($this->community->id) | ||
->create([ | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$this->communityAdminUser = User::factory() | ||
->asCommunityAdmin($this->community->id) | ||
->create([ | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$this->poolCandidate = PoolCandidate::factory()->create([ | ||
'user_id' => $this->candidateUser->id, | ||
'pool_id' => $this->teamPool->id, | ||
|
@@ -1143,4 +1173,144 @@ public static function manualStatusProvider() | |
], | ||
]; | ||
} | ||
|
||
// test policy correctly allows sample manual status updates to work, when expected and fail otherwise | ||
public function testManualStatusUpdatePolicy(): void | ||
{ | ||
$past = config('constants.past_datetime'); | ||
$this->poolCandidate->pool_candidate_status = PoolCandidateStatus::NEW_APPLICATION->name; | ||
$this->poolCandidate->submitted_at = $past; | ||
$this->poolCandidate->save(); | ||
|
||
// process operator | ||
// can set to SCREENED IN, QUALIFIED, REMOVED only | ||
// cannot set PLACED TERM, or DRAFT | ||
$this->actingAs($this->processOperatorUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::DRAFT->name], | ||
])->assertGraphQLErrorMessage($this->unauthorizedMessage); | ||
$this->actingAs($this->processOperatorUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::SCREENED_IN->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::SCREENED_IN->name, | ||
], | ||
]); | ||
$this->actingAs($this->processOperatorUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::QUALIFIED_AVAILABLE->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::QUALIFIED_AVAILABLE->name, | ||
], | ||
]); | ||
$this->actingAs($this->processOperatorUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::REMOVED->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::REMOVED->name, | ||
], | ||
]); | ||
$this->actingAs($this->processOperatorUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::PLACED_TERM->name], | ||
])->assertGraphQLErrorMessage($this->unauthorizedMessage); | ||
|
||
// community recruiter | ||
// can set to SCREENED IN, QUALIFIED, REMOVED, PLACED TERM only | ||
// cannot set DRAFT | ||
$this->actingAs($this->communityRecruiterUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::DRAFT->name], | ||
])->assertGraphQLErrorMessage($this->unauthorizedMessage); | ||
$this->actingAs($this->communityRecruiterUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::SCREENED_IN->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::SCREENED_IN->name, | ||
], | ||
]); | ||
$this->actingAs($this->communityRecruiterUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::QUALIFIED_AVAILABLE->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::QUALIFIED_AVAILABLE->name, | ||
], | ||
]); | ||
$this->actingAs($this->communityRecruiterUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::REMOVED->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::REMOVED->name, | ||
], | ||
]); | ||
$this->actingAs($this->communityRecruiterUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::PLACED_TERM->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::PLACED_TERM->name, | ||
], | ||
]); | ||
|
||
// community admin | ||
// can set to SCREENED IN, QUALIFIED, REMOVED, PLACED TERM only | ||
// cannot set DRAFT | ||
$this->actingAs($this->communityAdminUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::DRAFT->name], | ||
])->assertGraphQLErrorMessage($this->unauthorizedMessage); | ||
$this->actingAs($this->communityAdminUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::SCREENED_IN->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::SCREENED_IN->name, | ||
], | ||
]); | ||
$this->actingAs($this->communityAdminUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::QUALIFIED_AVAILABLE->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::QUALIFIED_AVAILABLE->name, | ||
], | ||
]); | ||
$this->actingAs($this->communityAdminUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::REMOVED->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::REMOVED->name, | ||
], | ||
]); | ||
$this->actingAs($this->communityAdminUser, 'api') | ||
->graphQL($this->manualStatusUpdateMutation, [ | ||
'id' => $this->poolCandidate->id, | ||
'candidate' => ['status' => PoolCandidateStatus::PLACED_TERM->name], | ||
])->assertJsonFragment([ | ||
'status' => [ | ||
'value' => PoolCandidateStatus::PLACED_TERM->name, | ||
], | ||
]); | ||
} | ||
} |
Oops, something went wrong.