Skip to content

Commit

Permalink
PCHR-3820: Refactor some tests. Fix typo.
Browse files Browse the repository at this point in the history
  • Loading branch information
tunbola committed Jun 13, 2018
1 parent 6229df3 commit 20d8441
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public function testDeleteShouldThrowAnExceptionWhenLoggedInUserIsNotAnAdminOrLe
public function testDeleteShouldDeleteAttachmentWhenLoggedInUserIsAnAdmin() {
$params = $this->getDefaultLeaveRequestParams();
$leaveRequest = LeaveRequestFabricator::fabricateWithoutValidation($params);

$leaveManagerService = $this->getLeaveManagerServiceWhenUserIsAdmin();
$leaveRequestRights = new LeaveRightsService($leaveManagerService);
$leaveRequestAttachmentService = new LeaveRequestAttachmentService($leaveRequestRights, $leaveManagerService);
$leaveRequestAttachmentService = $this->createLeaveRequestAttachmentsServiceWhenUserIsAdmin();

$attachment = $this->createAttachmentForLeaveRequest(['entity_id' => $leaveRequest->id]);
$attachment2 = $this->createAttachmentForLeaveRequest(['entity_id' => $leaveRequest->id]);
Expand Down Expand Up @@ -112,10 +109,7 @@ public function testDeleteShouldDeleteAttachmentWhenLoggedInUserIsTheLeaveApprov
public function testDeleteShouldThrowAnExceptionWhenAttachmentHasBeenDeletedBefore() {
$params = $this->getDefaultLeaveRequestParams();
$leaveRequest = LeaveRequestFabricator::fabricateWithoutValidation($params);

$leaveManagerService = $this->getLeaveManagerServiceWhenUserIsAdmin();
$leaveRequestRights = new LeaveRightsService($leaveManagerService);
$leaveRequestAttachmentService = new LeaveRequestAttachmentService($leaveRequestRights, $leaveManagerService);
$leaveRequestAttachmentService = $this->createLeaveRequestAttachmentsServiceWhenUserIsAdmin();

$attachment = $this->createAttachmentForLeaveRequest(['entity_id' => $leaveRequest->id]);

Expand All @@ -132,10 +126,7 @@ public function testDeleteShouldThrowAnExceptionWhenAttachmentHasBeenDeletedBefo
*/
public function testDeleteShouldThrowAnExceptionWhenAttachmentDoesNotExist() {
$leaveRequestID = 1;

$leaveManagerService = $this->getLeaveManagerServiceWhenUserIsAdmin();
$leaveRequestRights = new LeaveRightsService($leaveManagerService);
$leaveRequestAttachmentService = new LeaveRequestAttachmentService($leaveRequestRights, $leaveManagerService);
$leaveRequestAttachmentService = $this->createLeaveRequestAttachmentsServiceWhenUserIsAdmin();

$leaveRequestAttachmentService->delete(['leave_request_id' => $leaveRequestID, 'attachment_id' => 1]);
}
Expand Down Expand Up @@ -204,7 +195,6 @@ public function testGetReturnsLeaveAttachmentDataOnlyForAllContactsForAdmin() {
$attachment1 = $this->createAttachmentForLeaveRequest(['entity_id' => $leaveRequest1->id]);
$attachment2 = $this->createAttachmentForLeaveRequest(['entity_id' => $leaveRequest2->id]);


$leaveManagerService = $this->getLeaveManagerServiceWhenUserIsAdmin();
$leaveRightsService = $this->prophesize(LeaveRightsService::class);
$leaveRightsService->getLeaveContactsCurrentUserHasAccessTo()->willReturn([]);
Expand All @@ -218,7 +208,7 @@ public function testGetReturnsLeaveAttachmentDataOnlyForAllContactsForAdmin() {
$this->assertEquals($staff1Attachment['values'][0]['id'], $attachment1['id']);
$this->assertEquals($staff1Attachment['values'][0]['name'], $attachment1['name']);

$this->assertCount(1, $staff1Attachment['values']);
$this->assertCount(1, $staff2Attachment['values']);
$this->assertEquals($staff2Attachment['values'][0]['id'], $attachment2['id']);
$this->assertEquals($staff2Attachment['values'][0]['name'], $attachment2['name']);
}
Expand All @@ -241,4 +231,12 @@ private function getLeaveManagerServiceWhenUserIsAdmin() {
private function getLeaveManagerServiceWhenUserIsLeaveApprover($leaveContact) {
return $this->getLeaveManagerService(FALSE, $leaveContact);
}

private function createLeaveRequestAttachmentsServiceWhenUserIsAdmin() {
$leaveManagerService = $this->getLeaveManagerServiceWhenUserIsAdmin();
$leaveRequestRights = new LeaveRightsService($leaveManagerService);
$leaveRequestAttachmentService = new LeaveRequestAttachmentService($leaveRequestRights, $leaveManagerService);

return $leaveRequestAttachmentService;
}
}

0 comments on commit 20d8441

Please sign in to comment.