diff --git a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.test.tsx b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.test.tsx index 08c5f73986..ddd517f6ec 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.test.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.test.tsx @@ -17,8 +17,8 @@ import { useGenerateAgreement } from './useGenerateAgreement'; const generateFn = jest.fn(); const getAcquisitionFileFn = jest.fn(); const getAcquisitionFileProperties = jest.fn(); -const getPersonConceptFn = jest.fn(); -const getOrganizationConceptFn = jest.fn(); +const getPersonConceptFn = jest.fn().mockResolvedValue({}); +const getOrganizationConceptFn = jest.fn().mockResolvedValue({}); jest.mock('@/features/documents/hooks/useDocumentGenerationRepository'); (useDocumentGenerationRepository as jest.Mock).mockImplementation(() => ({ @@ -70,7 +70,7 @@ describe('useGenerateAgreement functions', () => { expect(generateFn).toHaveBeenCalled(); }); }); - it('makes requests to expected api endpoints if a team member is a property coordinator', async () => { + it('makes requests to expected api endpoints if a team member is a property coordinator with person', async () => { const responseWithTeam: Api_AcquisitionFile = { ...mockAcquisitionFileResponse(), acquisitionTeam: [ @@ -92,4 +92,27 @@ describe('useGenerateAgreement functions', () => { expect(getAcquisitionFileProperties).toHaveBeenCalled(); }); }); + + it('makes requests to expected api endpoints if a team member is a property coordinator with org', async () => { + const responseWithTeam: Api_AcquisitionFile = { + ...mockAcquisitionFileResponse(), + acquisitionTeam: [ + { + id: 1, + acquisitionFileId: 1, + organizationId: 1, + teamProfileTypeCode: 'PROPCOORD', + rowVersion: 2, + }, + ], + }; + const generate = setup({ acquisitionResponse: responseWithTeam }); + + await act(async () => { + await generate(mockAgreementsResponse()[1]); + expect(generateFn).toHaveBeenCalled(); + expect(getOrganizationConceptFn).toHaveBeenCalled(); + expect(getAcquisitionFileProperties).toHaveBeenCalled(); + }); + }); }); diff --git a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateLetter.test.tsx b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateLetter.test.tsx index c7a503239e..94c3f6d96a 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateLetter.test.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateLetter.test.tsx @@ -15,6 +15,7 @@ import { useGenerateLetter } from '../hooks/useGenerateLetter'; const generateFn = jest.fn(); const getAcquisitionFileFn = jest.fn(); const getPersonConceptFn = jest.fn(); +const getOrganizationConceptFn = jest.fn(); jest.mock('@/features/documents/hooks/useDocumentGenerationRepository'); (useDocumentGenerationRepository as jest.Mock).mockImplementation(() => ({ @@ -29,6 +30,7 @@ jest.mock('@/hooks/repositories/useAcquisitionProvider'); jest.mock('@/hooks/pims-api/useApiContacts'); (useApiContacts as jest.Mock).mockImplementation(() => ({ getPersonConcept: getPersonConceptFn, + getOrganizationConcept: getOrganizationConceptFn, })); let currentStore: MockStoreEnhanced; @@ -64,7 +66,7 @@ describe('useGenerateLetter functions', () => { expect(generateFn).toHaveBeenCalled(); }); }); - it('makes requests to expected api endpoints if a team member is a property coordinator', async () => { + it('makes requests to expected api endpoints if a team member is a property coordinator with person', async () => { const responseWithTeam: Api_AcquisitionFile = { ...mockAcquisitionFileResponse(), acquisitionTeam: [ @@ -85,4 +87,26 @@ describe('useGenerateLetter functions', () => { expect(getPersonConceptFn).toHaveBeenCalled(); }); }); + + it('makes requests to expected api endpoints if a team member is a property coordinator with org', async () => { + const responseWithTeam: Api_AcquisitionFile = { + ...mockAcquisitionFileResponse(), + acquisitionTeam: [ + { + id: 1, + acquisitionFileId: 1, + organizationId: 1, + teamProfileTypeCode: 'PROPCOORD', + rowVersion: 2, + }, + ], + }; + const generate = setup({ acquisitionResponse: responseWithTeam }); + + await act(async () => { + await generate(0); + expect(generateFn).toHaveBeenCalled(); + expect(getOrganizationConceptFn).toHaveBeenCalled(); + }); + }); }); diff --git a/source/frontend/src/models/generate/acquisition/GenerateAcquisitionFile.test.ts b/source/frontend/src/models/generate/acquisition/GenerateAcquisitionFile.test.ts index 6b2f73be24..3e8f094b12 100644 --- a/source/frontend/src/models/generate/acquisition/GenerateAcquisitionFile.test.ts +++ b/source/frontend/src/models/generate/acquisition/GenerateAcquisitionFile.test.ts @@ -1,3 +1,5 @@ +import { AddressTypes } from '@/constants'; +import { ContactMethodTypes } from '@/constants/contactMethodType'; import { mockAcquisitionFileResponse } from '@/mocks/acquisitionFiles.mock'; import { emptyApiInterestHolder, emptyInterestHolderProperty } from '@/mocks/interestHolder.mock'; @@ -175,4 +177,181 @@ describe('GenerateFile tests', () => { }); expect(file.properties[0].interest_holders_string).toBe(''); }); + + it('generates a file with org neg agent that has org name but primary contacts contact info and address', () => { + const acqFile = mockAcquisitionFileResponse(1, 'test', 1); + const file = new Api_GenerateAcquisitionFile({ + file: acqFile, + negotiatingAgent: { + acquisitionFileId: acqFile.id ?? 0, + organization: { + name: 'testOrg', + organizationAddresses: [ + { + address: { streetAddress1: 'orgaddress' }, + addressUsageType: { id: AddressTypes.Mailing }, + }, + ], + }, + primaryContact: { + contactMethods: [ + { contactMethodType: { id: ContactMethodTypes.WorkEmail }, value: 'primaryworkemail' }, + { contactMethodType: { id: ContactMethodTypes.WorkPhone }, value: 'primaryworkphone' }, + ], + personAddresses: [ + { + address: { streetAddress1: 'primaryaddress' }, + addressUsageType: { id: AddressTypes.Mailing }, + }, + ], + }, + }, + }); + expect(file.neg_agent?.full_name_string).toBe('testOrg (Inc. No. )'); + expect(file.neg_agent?.email).toBe('primaryworkemail'); + expect(file.neg_agent?.phone).toBe('primaryworkphone'); + expect(file.neg_agent?.address?.address_string).toBe('primaryaddress'); + }); + + it('generates a file with org neg agent that has org name but null contact if primary contact empty', () => { + const acqFile = mockAcquisitionFileResponse(1, 'test', 1); + const file = new Api_GenerateAcquisitionFile({ + file: acqFile, + negotiatingAgent: { + acquisitionFileId: acqFile.id ?? 0, + organization: { + name: 'testOrg', + organizationAddresses: [ + { + address: { streetAddress1: 'orgaddress' }, + addressUsageType: { id: AddressTypes.Mailing }, + }, + ], + }, + }, + }); + expect(file.neg_agent?.full_name_string).toBe('testOrg (Inc. No. )'); + expect(file.neg_agent?.email).toBe(''); + expect(file.neg_agent?.phone).toBe(''); + expect(file.neg_agent?.address).toBeNull(); + }); + + it('generates a file with org coord agent that has org name but primary contacts contact info', () => { + const acqFile = mockAcquisitionFileResponse(1, 'test', 1); + const file = new Api_GenerateAcquisitionFile({ + file: acqFile, + coordinatorContact: { + acquisitionFileId: acqFile.id ?? 0, + organization: { + name: 'testOrg', + organizationAddresses: [ + { + address: { streetAddress1: 'orgaddress' }, + addressUsageType: { id: AddressTypes.Mailing }, + }, + ], + }, + primaryContact: { + contactMethods: [ + { contactMethodType: { id: ContactMethodTypes.WorkEmail }, value: 'workemail' }, + { contactMethodType: { id: ContactMethodTypes.WorkPhone }, value: 'workphone' }, + ], + }, + }, + }); + expect(file.property_coordinator?.full_name_string).toBe('testOrg (Inc. No. )'); + expect(file.property_coordinator?.email).toBe('workemail'); + expect(file.property_coordinator?.phone).toBe('workphone'); + expect(file.property_coordinator?.address?.address_string).toBe('orgaddress'); + }); + + it('generates a file with org coord agent that has org name but empty primary contact', () => { + const acqFile = mockAcquisitionFileResponse(1, 'test', 1); + const file = new Api_GenerateAcquisitionFile({ + file: acqFile, + coordinatorContact: { + acquisitionFileId: acqFile.id ?? 0, + organization: { + name: 'testOrg', + organizationAddresses: [ + { + address: { streetAddress1: 'orgaddress' }, + addressUsageType: { id: AddressTypes.Mailing }, + }, + ], + }, + }, + }); + expect(file.property_coordinator?.full_name_string).toBe('testOrg (Inc. No. )'); + expect(file.property_coordinator?.email).toBe(''); + expect(file.property_coordinator?.phone).toBe(''); + expect(file.property_coordinator?.address?.address_string).toBe('orgaddress'); + }); + + it('generates a file with org provincial solicitor that has org address and name, primary contacts info, and separate attn field', () => { + const acqFile = mockAcquisitionFileResponse(1, 'test', 1); + const file = new Api_GenerateAcquisitionFile({ + file: acqFile, + provincialSolicitor: { + acquisitionFileId: acqFile.id ?? 0, + organization: { + name: 'testOrg', + organizationAddresses: [ + { + address: { streetAddress1: 'orgaddress' }, + addressUsageType: { id: AddressTypes.Mailing }, + }, + ], + }, + primaryContact: { + firstName: 'testfirst', + contactMethods: [ + { contactMethodType: { id: ContactMethodTypes.WorkEmail }, value: 'workemail' }, + { contactMethodType: { id: ContactMethodTypes.WorkPhone }, value: 'workphone' }, + ], + }, + }, + }); + expect(file.prov_solicitor?.full_name_string).toBe('testOrg (Inc. No. )'); + expect(file.prov_solicitor?.email).toBe('workemail'); + expect(file.prov_solicitor?.phone).toBe('workphone'); + expect(file.prov_solicitor_attn?.full_name_string).toBe('testfirst'); + expect(file.prov_solicitor?.address?.address_string).toBe('orgaddress'); + }); + + it('generates a file with org provincial solicitor that has org address and name, and empty attn and info if primary contact empty', () => { + const acqFile = mockAcquisitionFileResponse(1, 'test', 1); + const file = new Api_GenerateAcquisitionFile({ + file: acqFile, + provincialSolicitor: { + acquisitionFileId: acqFile.id ?? 0, + organization: { + name: 'testOrg', + organizationAddresses: [ + { + address: { streetAddress1: 'orgaddress' }, + addressUsageType: { id: AddressTypes.Mailing }, + }, + ], + }, + }, + }); + expect(file.prov_solicitor?.full_name_string).toBe('testOrg (Inc. No. )'); + expect(file.prov_solicitor?.email).toBe(''); + expect(file.prov_solicitor?.phone).toBe(''); + expect(file.prov_solicitor_attn?.full_name_string).toBe(''); + expect(file.prov_solicitor?.address?.address_string).toBe('orgaddress'); + }); + + it('saves a list of the organization owners on the file', () => { + const acqFile = mockAcquisitionFileResponse(1, 'test', 1); + const file = new Api_GenerateAcquisitionFile({ + file: acqFile, + interestHolders: [], + }); + expect(file.organization_owners).toHaveLength(1); + expect(file.organization_owners[0].owner_string).toBe( + 'FORTIS BC, Inc. No. 9999 (OR Reg. No. 12345)', + ); + }); });