-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add approver platform API (#3131)
- Loading branch information
1 parent
0ca1861
commit 91f3050
Showing
9 changed files
with
111 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ export interface EmployeeParams { | |
ou_id: string; | ||
order: string; | ||
limit: number; | ||
us_email?: string; | ||
} |
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 |
---|---|---|
|
@@ -200,6 +200,25 @@ describe('ApproverReportsService', () => { | |
}); | ||
}); | ||
|
||
it('addApprover(): should add approver to a report', (done) => { | ||
approverPlatformApiService.post.and.returnValue(of(null)); | ||
|
||
const reportID = 'rprj1zHHpW2W'; | ||
const approverEmail = '[email protected]'; | ||
const comment = 'comment'; | ||
|
||
approverReportsService.addApprover(reportID, approverEmail, comment).subscribe(() => { | ||
expect(approverPlatformApiService.post).toHaveBeenCalledOnceWith(`/reports/add_approver`, { | ||
data: { | ||
id: reportID, | ||
approver_email: approverEmail, | ||
comment, | ||
}, | ||
}); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('getReportById(): should get a report by id', () => { | ||
spyOn(approverReportsService, 'getReportsByParams').and.returnValue(of(allReportsPaginated1)); | ||
const queryParams = { | ||
|
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 |
---|---|---|
|
@@ -260,22 +260,6 @@ describe('ReportService', () => { | |
}); | ||
}); | ||
|
||
it('addApprover(): should add approver to a report', (done) => { | ||
apiService.post.and.returnValue(of(null)); | ||
|
||
const reportID = 'rprj1zHHpW2W'; | ||
const approverEmail = '[email protected]'; | ||
const comment = 'comment'; | ||
|
||
reportService.addApprover(reportID, approverEmail, comment).subscribe(() => { | ||
expect(apiService.post).toHaveBeenCalledOnceWith(`/reports/${reportID}/approvals`, { | ||
approver_email: approverEmail, | ||
comment, | ||
}); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('delete(): should delete a report', (done) => { | ||
apiService.delete.and.returnValue(of(null)); | ||
spyOn(reportService, 'clearTransactionCache').and.returnValue(of(null)); | ||
|
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ import { FormsModule } from '@angular/forms'; | |
import { pullBackAdvancedRequests } from 'src/app/core/mock-data/advance-requests.data'; | ||
import { getElementBySelector, getTextContent } from 'src/app/core/dom-helpers'; | ||
import { of } from 'rxjs'; | ||
import { ApproverReportsService } from 'src/app/core/services/platform/v1/approver/reports.service'; | ||
|
||
describe('AddApproversPopoverComponent', () => { | ||
let component: AddApproversPopoverComponent; | ||
|
@@ -20,15 +21,15 @@ describe('AddApproversPopoverComponent', () => { | |
let modalProperties: jasmine.SpyObj<ModalPropertiesService>; | ||
let popoverController: jasmine.SpyObj<PopoverController>; | ||
let advanceRequestService: jasmine.SpyObj<AdvanceRequestService>; | ||
let reportService: jasmine.SpyObj<ReportService>; | ||
let approverReportsService: jasmine.SpyObj<ApproverReportsService>; | ||
let loaderService: jasmine.SpyObj<LoaderService>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
const modalControllerSpy = jasmine.createSpyObj('ModalController', ['create']); | ||
const modalPropertiesSpy = jasmine.createSpyObj('ModalPropertiesService', ['getModalDefaultProperties']); | ||
const popoverControllerSpy = jasmine.createSpyObj('PopoverController', ['dismiss']); | ||
const advanceRequestServiceSpy = jasmine.createSpyObj('AdvanceRequestService', ['addApprover']); | ||
const reportServiceSpy = jasmine.createSpyObj('ReportService', ['addApprover']); | ||
const approverReportsServiceSpy = jasmine.createSpyObj('ApproverReportsService', ['addApprover']); | ||
const loaderServiceSpy = jasmine.createSpyObj('LoaderService', ['showLoader', 'hideLoader']); | ||
|
||
TestBed.configureTestingModule({ | ||
|
@@ -52,8 +53,8 @@ describe('AddApproversPopoverComponent', () => { | |
useValue: advanceRequestServiceSpy, | ||
}, | ||
{ | ||
provide: ReportService, | ||
useValue: reportServiceSpy, | ||
provide: ApproverReportsService, | ||
useValue: approverReportsServiceSpy, | ||
}, | ||
{ | ||
provide: LoaderService, | ||
|
@@ -65,7 +66,7 @@ describe('AddApproversPopoverComponent', () => { | |
modalProperties = TestBed.inject(ModalPropertiesService) as jasmine.SpyObj<ModalPropertiesService>; | ||
popoverController = TestBed.inject(PopoverController) as jasmine.SpyObj<PopoverController>; | ||
advanceRequestService = TestBed.inject(AdvanceRequestService) as jasmine.SpyObj<AdvanceRequestService>; | ||
reportService = TestBed.inject(ReportService) as jasmine.SpyObj<ReportService>; | ||
approverReportsService = TestBed.inject(ApproverReportsService) as jasmine.SpyObj<ApproverReportsService>; | ||
loaderService = TestBed.inject(LoaderService) as jasmine.SpyObj<LoaderService>; | ||
|
||
fixture = TestBed.createComponent(AddApproversPopoverComponent); | ||
|
@@ -84,17 +85,21 @@ describe('AddApproversPopoverComponent', () => { | |
component.type = 'report'; | ||
component.ownerEmail = '[email protected]'; | ||
const selectedApproversList = ['[email protected]', 'aiyush.dhar@fylein', '[email protected]', '[email protected]']; | ||
component.selectedApproversList = selectedApproversList; | ||
modalController.create.and.returnValue(Promise.resolve(modalSpy)); | ||
modalSpy.onWillDismiss.and.returnValue(Promise.resolve({ data: { selectedApproversList } } as any)); | ||
component.selectedApproversList = selectedApproversList.map((email) => { | ||
return { email }; | ||
}); | ||
modalController.create.and.resolveTo(modalSpy); | ||
modalSpy.onWillDismiss.and.resolveTo({ data: { selectedApproversList } } as any); | ||
|
||
component.openModal(); | ||
tick(); | ||
expect(modalController.create).toHaveBeenCalledOnceWith({ | ||
component: ApproverDialogComponent, | ||
componentProps: { | ||
approverEmailsList: component.approverEmailsList, | ||
initialApproverList: selectedApproversList, | ||
initialApproverList: selectedApproversList.map((email) => { | ||
return { email }; | ||
}), | ||
id: component.id, | ||
type: component.type, | ||
ownerEmail: component.ownerEmail, | ||
|
@@ -107,7 +112,7 @@ describe('AddApproversPopoverComponent', () => { | |
})); | ||
|
||
it('closeAddApproversPopover(): should close popover', fakeAsync(() => { | ||
popoverController.dismiss.and.returnValue(Promise.resolve(true)); | ||
popoverController.dismiss.and.resolveTo(true); | ||
|
||
tick(); | ||
component.closeAddApproversPopover(); | ||
|
@@ -121,9 +126,9 @@ describe('AddApproversPopoverComponent', () => { | |
component.confirmationMessage = 'The request is approved'; | ||
component.selectedApproversList = [{ email: '[email protected]' }]; | ||
advanceRequestService.addApprover.and.returnValue(of(pullBackAdvancedRequests)); | ||
loaderService.showLoader.and.returnValue(Promise.resolve()); | ||
loaderService.hideLoader.and.returnValue(Promise.resolve()); | ||
popoverController.dismiss.and.returnValue(Promise.resolve(true)); | ||
loaderService.showLoader.and.resolveTo(); | ||
loaderService.hideLoader.and.resolveTo(); | ||
popoverController.dismiss.and.resolveTo(true); | ||
|
||
component.saveUpdatedApproversList(); | ||
|
||
|
@@ -138,22 +143,22 @@ describe('AddApproversPopoverComponent', () => { | |
expect(popoverController.dismiss).toHaveBeenCalledOnceWith({ reload: true }); | ||
})); | ||
|
||
it('should call reportService.addApprover() for other request types', fakeAsync(() => { | ||
it('should call approverReportsService.addApprover() for other request types', fakeAsync(() => { | ||
fixture.detectChanges(); | ||
component.type = 'report'; | ||
component.id = 'repP09oaYXAf'; | ||
component.confirmationMessage = 'The request is approved'; | ||
component.selectedApproversList = [{ email: '[email protected]' }]; | ||
reportService.addApprover.and.returnValue(of(null)); | ||
loaderService.showLoader.and.returnValue(Promise.resolve()); | ||
loaderService.hideLoader.and.returnValue(Promise.resolve()); | ||
popoverController.dismiss.and.returnValue(Promise.resolve(true)); | ||
approverReportsService.addApprover.and.returnValue(of(null)); | ||
loaderService.showLoader.and.resolveTo(); | ||
loaderService.hideLoader.and.resolveTo(); | ||
popoverController.dismiss.and.resolveTo(true); | ||
|
||
component.saveUpdatedApproversList(); | ||
|
||
expect(loaderService.showLoader).toHaveBeenCalledTimes(1); | ||
tick(); | ||
expect(reportService.addApprover).toHaveBeenCalledOnceWith( | ||
expect(approverReportsService.addApprover).toHaveBeenCalledOnceWith( | ||
'repP09oaYXAf', | ||
'[email protected]', | ||
'The request is approved' | ||
|
@@ -168,7 +173,10 @@ describe('AddApproversPopoverComponent', () => { | |
}); | ||
|
||
it('should display the "+n more" chip when there are more than 3 selected approvers', () => { | ||
component.selectedApproversList = ['[email protected]', '[email protected]', '[email protected]', '[email protected]']; | ||
const selectedApproversList = ['[email protected]', '[email protected]', '[email protected]', '[email protected]']; | ||
component.selectedApproversList = selectedApproversList.map((email) => { | ||
return { email }; | ||
}); | ||
fixture.detectChanges(); | ||
const moreChip = getElementBySelector(fixture, '.add-approvers-popover--input-container__chip'); | ||
expect(moreChip).toBeTruthy(); | ||
|
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
Oops, something went wrong.