import { Injectable } from '@angular/core'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { Collaborator } from '@core/typings/collaboration.typing'; import { BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect } from 'chai'; import { CollaborationService } from './collaboration.service'; @Injectable({ providedIn: 'root' }) @DescribeAngularService(CollaborationService, { imports: [ GCMockModule ] }) export class CollaborationServiceSpec implements Spec { applicantOwnerId = 1; applicantOwner: Collaborator = { id: this.applicantOwnerId, firstName: 'Josie', lastName: 'Conway', email: 'josie.conway@mailinator.com', canManageApplicants: true, canReceiveEmails: true, isApplicationOwner: true, phoneNumber: '', addressString: '' }; collabId = 2; collaborator: Collaborator = { id: this.collabId, firstName: 'Lukie', lastName: 'Smith', email: 'lukie@mailinator.com', canManageApplicants: true, canReceiveEmails: true, isApplicationOwner: false, phoneNumber: '', addressString: '' }; @BeforeEach() mock (service: CollaborationService) { service['userService'].setApplicant({ id: this.collabId, firstName: 'Lukie', lastName: 'Smith', email: 'lukie@mailinator.com', phoneNumber: '', profileImageUrl: '', requirePasswordReset: false, isNewUser: false, address: '', address2: '', city: '', country: '', state: '', postalCode: '', culture: '', organizations: [], acceptedTermsOfService: true, isSso: false, hasAwards: false }); service['userService'].setUser({ firstName: 'Tina', lastName: 'Conway', active: true, culture: '', email: 'tina.conway@mailinator.com', id: 27, isNewUser: false, isRootUser: false, jobTitle: '', profileImageUrl: '', requirePasswordReset: false, roles: [], workflows: null, workFlowLevels: [], acceptedTermsOfService: true, clientHasNominations: true, isInNominationWorkFlow: true, isIntegratedWithCsrZone: true, isSso: false }); } @TestCase('should be able to get collaborators for copy for applicant portal') async getCollaboratorsToCopyApplicant (service: CollaborationService) { Object.defineProperty(service['portal'], 'isApply', { get: () => { return true; } }); Object.defineProperty(service['portal'], 'isManager', { get: () => { return false; } }); service['collaborationResources']['getCollaborators'] = async () => { return [ this.applicantOwner, this.collaborator ]; }; const collabsToCopy = await service.getCollaboratorsToCopy(1); expect(collabsToCopy.length).to.be.equal(1); const collab = collabsToCopy[0]; expect(collab.id).to.be.equal(this.applicantOwnerId); } @TestCase('should be able to get collaborators for copy for manager portal') async getCollaboratorsToCopyManager (service: CollaborationService) { Object.defineProperty(service['portal'], 'isApply', { get: () => { return false; } }); Object.defineProperty(service['portal'], 'isManager', { get: () => { return true; } }); service['collaborationResources']['getCollaborators'] = async () => { return [ this.applicantOwner, this.collaborator ]; }; const collabsToCopy = await service.getCollaboratorsToCopy(1); expect(collabsToCopy.length).to.be.equal(1); const collab = collabsToCopy[0]; expect(collab.id).to.be.equal(this.collabId); } }