import { Injectable } from '@angular/core'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { ApplicantForDash, ApplicantSummaryApi } from '@core/typings/applicant.typing'; import { PaginatedResponse, SummaryNumbers } from '@yourcause/common'; import { BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect } from 'chai'; import { ApplicantManagerService } from './applicant-manager.service'; @Injectable({ providedIn: 'root' }) @DescribeAngularService(ApplicantManagerService, { imports: [ GCMockModule ] }) export class ApplicantManagerServiceSpec implements Spec { applicantId = 1; applicantSummaryApi: ApplicantSummaryApi = { id: this.applicantId, firstName: 'Tina', lastName: 'Conway', email: 'tina.conway@mailinator.com', address: '', address2: '', city: '', state: '', postalCode: '', country: '', phoneNumber: '' }; additionalInfo: SummaryNumbers = { awardsPaidAmount: 5, numberOfApplications: 1, numberOfNominations: 0, pendingPaymentsAmount: 500, totalAwardAmount: 500 }; applicantsInsightsResult: PaginatedResponse = { records: [{ applicantInfo: { id: this.applicantId, fullName: 'Tina Conway', email: 'tina.conway@mailinator.com', phoneNumber: '', address1: '', address2: '', city: '', state: '', postalCode: '', country: '' }, organizationInfos: [{ id: 2, name: 'Test Org', charityId: null, phoneNumber: '', address1: '', address2: '', city: '', state: '', postalCode: '', country: '', identification: '', isPrivateOrg: false, imageUrl: '', guid: '' }], numberOfApplications: 2, amountRequested: 5000, numberOfAwards: 2, amountAwardedTotal: 5000, numberOfPayments: 1, paymentsTotal: 5000, lastApplicationDate: '' }], recordCount: 2 }; @BeforeEach() mock (service: ApplicantManagerService) { service['applicantManagerResources']['getApplicantSummary'] = async () => { return this.applicantSummaryApi; }; service['applicantManagerResources']['getApplicantCalculations'] = async () => { return this.additionalInfo; }; service['applicantManagerResources']['getApplicantsForInsights'] = async () => { return this.applicantsInsightsResult; }; } @TestCase('should be able to set applicant profile details') async setApplicantProfileDetails (service: ApplicantManagerService) { await service.setApplicantProfileDetails(this.applicantId); expect(service.applicantMap[this.applicantId].applicant).to.deep.equal( this.applicantSummaryApi ); } @TestCase('should be able to get applicants list for insights non CSV') async getApplicantListForInsightsNonCsv (service: ApplicantManagerService) { const response = await service.getApplicantListForInsights( { rowsPerPage: 1, pageNumber: 1, sortColumns: [], filterColumns: [], retrieveTotalRecordCount: false, returnAll: true }, [1], false ); expect(response.success).to.be.true; expect(response.data.records.length).to.be.equal( this.applicantsInsightsResult.records.length ); } @TestCase('should be able to get applicants list for insights for CSV') async getApplicantListForInsightsCsv (service: ApplicantManagerService) { const response = await service.getApplicantListForInsights( { rowsPerPage: 1, pageNumber: 1, sortColumns: [], filterColumns: [], retrieveTotalRecordCount: false, returnAll: true }, [1], true ); expect(response).to.be.string; } @TestCase('should be able to get applicant fields') async getApplicantFields (service: ApplicantManagerService) { const result = await service.getApplicantFields( 123, 'First', 'Last', 'appEmail@email.com', '' ); expect(result.id).to.be.equal(this.applicantSummaryApi.id); expect(result.email).to.be.equal(this.applicantSummaryApi.email); } }