Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psp 6991 - organization team support for h0074 and agreements #3553

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { useGenerateAgreement } from './useGenerateAgreement';
const generateFn = jest.fn();
const getAcquisitionFileFn = jest.fn<Api_AcquisitionFile | undefined, any[]>();
const getAcquisitionFileProperties = jest.fn<Api_Property[] | undefined, any[]>();
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(() => ({
Expand Down Expand Up @@ -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: [
Expand All @@ -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();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,28 @@
);

const coordinatorPromise = coordinator?.personId
? getPersonConcept(coordinator?.personId)
: Promise.resolve(null);
? getPersonConcept(coordinator?.personId).then(p => (coordinator.person = p?.data))
: provincialSolicitor?.organizationId
? getOrganizationConcept(provincialSolicitor?.organizationId).then(o =>
!!coordinator ? (coordinator.organization = o?.data) : null,

Check warning on line 44 in source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts#L43-L44

Added lines #L43 - L44 were not covered by tests
)
: Promise.resolve();
const negotiatingAgentPromise = negotiatingAgent?.personId
? getPersonConcept(negotiatingAgent?.personId)
: Promise.resolve(null);
? getPersonConcept(negotiatingAgent?.personId).then(p => (negotiatingAgent.person = p?.data))

Check warning on line 48 in source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts#L48

Added line #L48 was not covered by tests
: provincialSolicitor?.organizationId
? getOrganizationConcept(provincialSolicitor?.organizationId).then(o =>
!!negotiatingAgent ? (negotiatingAgent.organization = o?.data) : null,

Check warning on line 51 in source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts#L50-L51

Added lines #L50 - L51 were not covered by tests
)
: Promise.resolve();
const provincialSolicitorPromise = provincialSolicitor?.personId
? getPersonConcept(provincialSolicitor?.personId)
: Promise.resolve(null);
? getPersonConcept(provincialSolicitor?.personId).then(
p => (provincialSolicitor.person = p?.data),

Check warning on line 56 in source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts#L55-L56

Added lines #L55 - L56 were not covered by tests
)
: provincialSolicitor?.organizationId
? getOrganizationConcept(provincialSolicitor?.organizationId).then(o =>
!!provincialSolicitor ? (provincialSolicitor.organization = o?.data) : null,

Check warning on line 60 in source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts#L59-L60

Added lines #L59 - L60 were not covered by tests
)
: Promise.resolve();

// Owner solicitor can be either a Person or an Organization (with optional primary contact)
const ownerSolicitorPersonPromise = ownerSolicitor?.personId
Expand All @@ -59,21 +73,10 @@
? getPersonConcept(ownerSolicitor?.primaryContactId)
: Promise.resolve(null);

const [
coordinatorConcept,
negotiatingAgentConcept,
provincialSolicitorConcept,
ownerSolicitorPersonConcept,
ownerSolicitorOrganizationConcept,
ownerSolicitorPrimaryContactConcept,
] = await Promise.all([
coordinatorPromise,
negotiatingAgentPromise,
provincialSolicitorPromise,
ownerSolicitorPersonPromise,
ownerSolicitorOrganizationPromise,
ownerSolicitorPrimaryContactPromise,
]);
await Promise.all([coordinatorPromise, negotiatingAgentPromise, provincialSolicitorPromise]);
const ownerSolicitorPersonConcept = await ownerSolicitorPersonPromise;
const ownerSolicitorOrganizationConcept = await ownerSolicitorOrganizationPromise;
const ownerSolicitorPrimaryContactConcept = await ownerSolicitorPrimaryContactPromise;

if (ownerSolicitor) {
ownerSolicitor.person = ownerSolicitorPersonConcept?.data ?? null;
Expand All @@ -83,9 +86,9 @@

const fileData = new Api_GenerateAcquisitionFile({
file,
coordinatorContact: coordinatorConcept?.data ?? null,
negotiatingAgent: negotiatingAgentConcept?.data ?? null,
provincialSolicitor: provincialSolicitorConcept?.data ?? null,
coordinatorContact: coordinator ?? null,
negotiatingAgent: negotiatingAgent ?? null,
provincialSolicitor: provincialSolicitor ?? null,
Comment on lines +89 to +91
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks cleaner!

ownerSolicitor: ownerSolicitor ?? null,
interestHolders: [],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useGenerateLetter } from '../hooks/useGenerateLetter';
const generateFn = jest.fn();
const getAcquisitionFileFn = jest.fn<Api_AcquisitionFile | undefined, any[]>();
const getPersonConceptFn = jest.fn();
const getOrganizationConceptFn = jest.fn();

jest.mock('@/features/documents/hooks/useDocumentGenerationRepository');
(useDocumentGenerationRepository as jest.Mock).mockImplementation(() => ({
Expand All @@ -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<any, {}>;
Expand Down Expand Up @@ -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: [
Expand All @@ -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();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Api_GenerateLetter } from '@/models/generate/GenerateLetter';
import { Api_GenerateOwner } from '@/models/generate/GenerateOwner';

export const useGenerateLetter = () => {
const { getPersonConcept } = useApiContacts();
const { getPersonConcept, getOrganizationConcept } = useApiContacts();
const {
getAcquisitionFile: { execute: getAcquisitionFile },
} = useAcquisitionProvider();
Expand All @@ -24,10 +24,14 @@ export const useGenerateLetter = () => {
const coordinator = file.acquisitionTeam?.find(
team => team.teamProfileTypeCode === 'PROPCOORD',
);
const coordinatorPerson = !!coordinator?.personId
? (await getPersonConcept(coordinator?.personId))?.data
: null;
const letterData = new Api_GenerateLetter(file, coordinatorPerson);
if (!!coordinator?.personId) {
coordinator.person = (await getPersonConcept(coordinator?.personId))?.data;
} else if (!!coordinator?.organizationId) {
coordinator.organization = (
await getOrganizationConcept(coordinator?.organizationId)
)?.data;
}
const letterData = new Api_GenerateLetter(file, coordinator);
letterData.owners = recipients ?? letterData.owners;
const generatedFile = await generate({
templateType: FormDocumentType.LETTER,
Expand Down
8 changes: 5 additions & 3 deletions source/frontend/src/models/generate/GenerateLetter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import moment from 'moment';

import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile';
import { Api_Person } from '@/models/api/Person';
import { Api_AcquisitionFile, Api_AcquisitionFileTeam } from '@/models/api/AcquisitionFile';

import { Api_GenerateAcquisitionFile } from './acquisition/GenerateAcquisitionFile';
export class Api_GenerateLetter extends Api_GenerateAcquisitionFile {
date_generated: string;
constructor(file: Api_AcquisitionFile, coordinatorContact: Api_Person | null | undefined) {
constructor(
file: Api_AcquisitionFile,
coordinatorContact: Api_AcquisitionFileTeam | null | undefined,
) {
super({
file,
coordinatorContact: coordinatorContact ?? null,
Expand Down
Loading
Loading