Skip to content

Commit

Permalink
test updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith committed Oct 31, 2023
1 parent becfb1c commit 2cec851
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 4 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 @@ -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
@@ -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';

Expand Down Expand Up @@ -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)',
);
});
});

0 comments on commit 2cec851

Please sign in to comment.