diff --git a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH0443.test.tsx b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH0443.test.tsx index 77e1bc420c..a576c0cd1e 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH0443.test.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH0443.test.tsx @@ -71,13 +71,15 @@ const setup = (params?: { storeValues?: any; acquisitionResponse?: Api_Acquisiti describe('useGenerateH0443 functions', () => { it('makes requests to expected api endpoints', async () => { const generate = setup(); - await act(async () => { - await generate(0); - expect(generateFn).toHaveBeenCalled(); - }); + await act(async () => await generate(0)); + + expect(generateFn).toHaveBeenCalled(); }); it('makes requests to expected api endpoints for each required team member', async () => { + const organizationPersonMock = getMockPerson({ id: 3, firstName: 'JONH', surname: 'Doe' }); + getPersonConceptFn.mockResolvedValue(Promise.resolve({ data: organizationPersonMock })); + const responseWithTeam: Api_AcquisitionFile = { ...mockAcquisitionFileResponse(), acquisitionTeam: [ @@ -99,11 +101,10 @@ describe('useGenerateH0443 functions', () => { }; const generate = setup({ acquisitionResponse: responseWithTeam }); - await act(async () => { - await generate(0); - expect(generateFn).toHaveBeenCalled(); - expect(getPersonConceptFn).toHaveBeenCalledTimes(2); - }); + await act(async () => await generate(0)); + + expect(generateFn).toHaveBeenCalled(); + expect(getPersonConceptFn).toHaveBeenCalledTimes(2); }); it('makes requests to Organization when Property Coordinator is an organization with a Primary Contact', async () => { @@ -111,7 +112,7 @@ describe('useGenerateH0443 functions', () => { getPersonConceptFn.mockResolvedValue(Promise.resolve({ data: organizationPersonMock })); const organizationMock = getMockOrganization(); - getOrganizationConceptFn.mockResolvedValue(Promise.resolve({ data: organizationMock })); + getOrganizationConceptFn.mockResolvedValue({ data: organizationMock }); const responseWithTeam: Api_AcquisitionFile = { ...mockAcquisitionFileResponse(), @@ -128,12 +129,11 @@ describe('useGenerateH0443 functions', () => { }; const generate = setup({ acquisitionResponse: responseWithTeam }); - await act(async () => { - await generate(0); - expect(generateFn).toHaveBeenCalled(); - expect(getPersonConceptFn).toHaveBeenLastCalledWith(3); - expect(getOrganizationConceptFn).toHaveBeenCalledTimes(1); - }); + await act(async () => await generate(0)); + + expect(generateFn).toHaveBeenCalled(); + expect(getPersonConceptFn).toHaveBeenLastCalledWith(3); + expect(getOrganizationConceptFn).toHaveBeenCalledTimes(1); }); it('makes requests to Organization when Property Coordinator is an organization and no Primary Contact', async () => { @@ -157,12 +157,11 @@ describe('useGenerateH0443 functions', () => { }; const generate = setup({ acquisitionResponse: responseWithTeam }); - await act(async () => { - await generate(0); - expect(generateFn).toHaveBeenCalled(); - expect(getOrganizationConceptFn).toHaveBeenCalledTimes(1); - expect(getPersonConceptFn).not.toHaveBeenCalled(); - }); + await act(async () => await generate(0)); + + expect(generateFn).toHaveBeenCalled(); + expect(getOrganizationConceptFn).toHaveBeenCalledTimes(1); + expect(getPersonConceptFn).not.toHaveBeenCalled(); }); it('makes requests to Organization when Property Agent is an organization with Primary Contact', async () => { @@ -186,12 +185,11 @@ describe('useGenerateH0443 functions', () => { }; const generate = setup({ acquisitionResponse: responseWithTeam }); - await act(async () => { - await generate(0); - expect(generateFn).toHaveBeenCalled(); - expect(getOrganizationConceptFn).toHaveBeenCalledTimes(1); - expect(getPersonConceptFn).toHaveBeenCalledWith(3); - }); + await act(async () => generate(0)); + + expect(generateFn).toHaveBeenCalled(); + expect(getOrganizationConceptFn).toHaveBeenCalledTimes(1); + expect(getPersonConceptFn).toHaveBeenCalledWith(3); }); it('makes requests to Organization when Property Agent is an organization with no Primary Contact', async () => { @@ -214,12 +212,11 @@ describe('useGenerateH0443 functions', () => { }; const generate = setup({ acquisitionResponse: responseWithTeam }); - await act(async () => { - await generate(0); - expect(generateFn).toHaveBeenCalled(); - expect(getOrganizationConceptFn).toHaveBeenCalledTimes(1); - expect(getPersonConceptFn).not.toHaveBeenCalled(); - }); + await act(async () => await generate(0)); + + expect(generateFn).toHaveBeenCalled(); + expect(getOrganizationConceptFn).toHaveBeenCalledTimes(1); + expect(getPersonConceptFn).not.toHaveBeenCalled(); }); it('makes requests to expected api endpoints if there are properties', async () => { diff --git a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH0443.ts b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH0443.ts index 0e3881217c..36b6e9f6ec 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH0443.ts +++ b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH0443.ts @@ -44,7 +44,7 @@ export const useGenerateH0443 = () => { file.acquisitionFileOwners?.filter((x): x is Api_AcquisitionFileOwner => !!x) || []; const contactOwner = owners.find(x => x.isPrimaryContact === true); - let h0443Data: H0443Data = { + const h0443Data: H0443Data = { file_name: file.fileName || '', file_number: file.fileNumber || '', project_number: file.project?.code || '', @@ -64,9 +64,7 @@ export const useGenerateH0443 = () => { if (propertyCoordinator.personId) { const personConceptResponse = await getPersonConcept(propertyCoordinator?.personId); - h0443Data.property_coordinator = personConceptResponse?.data - ? new Api_GeneratePerson(personConceptResponse.data) - : null; + h0443Data.property_coordinator = new Api_GeneratePerson(personConceptResponse.data); } else if (propertyCoordinator.organizationId) { const organizationConceptResponse = await getOrganizationConcept( propertyCoordinator?.organizationId, @@ -80,9 +78,7 @@ export const useGenerateH0443 = () => { ) { const personResponse = await getPersonConcept(propertyCoordinator.primaryContactId); - h0443Data.property_coordinator = personResponse.data - ? new Api_GeneratePerson(personResponse.data) - : null; + h0443Data.property_coordinator = new Api_GeneratePerson(personResponse.data); } } } @@ -92,9 +88,7 @@ export const useGenerateH0443 = () => { if (propertyAgent.personId) { const personResponse = await getPersonConcept(propertyAgent?.personId); - h0443Data.property_agent = personResponse?.data - ? new Api_GeneratePerson(personResponse.data) - : null; + h0443Data.property_agent = new Api_GeneratePerson(personResponse.data); } else if (propertyAgent.organizationId) { const organizationConceptResponse = await getOrganizationConcept( propertyAgent?.organizationId, @@ -107,9 +101,7 @@ export const useGenerateH0443 = () => { ) { const personResponse = await getPersonConcept(propertyAgent.primaryContactId); - h0443Data.property_agent = personResponse.data - ? new Api_GeneratePerson(personResponse.data) - : null; + h0443Data.property_agent = new Api_GeneratePerson(personResponse.data); } } }