Skip to content

Commit

Permalink
Psp 6991 - organization team support for h0074 and agreements (#3553)
Browse files Browse the repository at this point in the history
* psp-6991 update agreement generation to support team organizations.

* test updates.
  • Loading branch information
devinleighsmith authored Oct 31, 2023
1 parent b857440 commit 139bc7c
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 47 deletions.
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 @@ export const useGenerateAgreement = () => {
);

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,
)
: Promise.resolve();
const negotiatingAgentPromise = negotiatingAgent?.personId
? getPersonConcept(negotiatingAgent?.personId)
: Promise.resolve(null);
? getPersonConcept(negotiatingAgent?.personId).then(p => (negotiatingAgent.person = p?.data))
: provincialSolicitor?.organizationId
? getOrganizationConcept(provincialSolicitor?.organizationId).then(o =>
!!negotiatingAgent ? (negotiatingAgent.organization = o?.data) : null,
)
: Promise.resolve();
const provincialSolicitorPromise = provincialSolicitor?.personId
? getPersonConcept(provincialSolicitor?.personId)
: Promise.resolve(null);
? getPersonConcept(provincialSolicitor?.personId).then(
p => (provincialSolicitor.person = p?.data),
)
: provincialSolicitor?.organizationId
? getOrganizationConcept(provincialSolicitor?.organizationId).then(o =>
!!provincialSolicitor ? (provincialSolicitor.organization = o?.data) : null,
)
: 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 @@ export const useGenerateAgreement = () => {
? 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 @@ export const useGenerateAgreement = () => {

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,
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

0 comments on commit 139bc7c

Please sign in to comment.