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-7930 : Generate Document Hyperlink located within L/L File Summar… #4091

Merged
merged 7 commits into from
Jun 14, 2024
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,7 +17,7 @@ public class DocumentGenerationRequest
/// <summary>
/// get/set - The template type to use for generation.
/// </summary>
public FormDocumentType TemplateType { get; set; }
public FormTypes TemplateType { get; set; }

/// <summary>
/// get/set - the type the document template should be converted to when returned from cdogs.
Expand Down
2 changes: 1 addition & 1 deletion source/backend/api/Services/DocumentGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task<ExternalResponse<string>> UploadFileTemplate(IFormFile fileRaw
return result;
}

public async Task<ExternalResponse<FileDownloadResponse>> GenerateDocument(FormDocumentType templateType, JsonElement templateData, ConvertToTypes? convertTo)
public async Task<ExternalResponse<FileDownloadResponse>> GenerateDocument(FormTypes templateType, JsonElement templateData, ConvertToTypes? convertTo)
{
this.Logger.LogInformation("Generating document");

Expand Down
2 changes: 1 addition & 1 deletion source/backend/api/Services/IDocumentGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public interface IDocumentGenerationService

Task<ExternalResponse<string>> UploadFileTemplate(IFormFile fileRaw);

Task<ExternalResponse<FileDownloadResponse>> GenerateDocument(FormDocumentType templateType, JsonElement templateData, ConvertToTypes? convertTo);
Task<ExternalResponse<FileDownloadResponse>> GenerateDocument(FormTypes templateType, JsonElement templateData, ConvertToTypes? convertTo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,49 @@

namespace Pims.Api.Models.CodeTypes
{
/// <summary>
/// [PIMS_FORM_TYPE] table.
/// </summary>
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
public enum FormDocumentType
public enum FormTypes
{
// Payment requisition (H120)
[EnumMember(Value = "H120")]
H120,

// Offer agreement - Section 3 (H179 A)
[EnumMember(Value = "H179A")]
H179A,

// Offer agreement - Partial (H179 P)
[EnumMember(Value = "H179P")]
H179P,

// Offer agreement - Total (H179 T)
[EnumMember(Value = "H179T")]
H179T,

// Letter
[EnumMember(Value = "LETTER")]
LETTER,

// Conditions of Entry (H0443)
[EnumMember(Value = "H0443")]
H0443,

// License of Occupation (H0074)
[EnumMember(Value = "H0074")]
H0074,

// Notice of Expropriation (Form 1)
[EnumMember(Value = "FORM1")]
FORM1,

// Certificate of Approval of Expropriation (Form 5)
[EnumMember(Value = "FORM5")]
FORM5,

// Notice of Advance Payment (Form 8)
[EnumMember(Value = "FORM8")]
FORM8,

// Vesting Notice (Form 9)
[EnumMember(Value = "FORM9")]
FORM9,

// H1005A
[EnumMember(Value = "H0074")]
H0074,

[EnumMember(Value = "H0443")]
H0443,

[EnumMember(Value = "H1005A")]
H1005A,

[EnumMember(Value = "H1005")]
H1005,

[EnumMember(Value = "H120")]
H120,

[EnumMember(Value = "H179A")]
H179A,

[EnumMember(Value = "H179P")]
H179P,

[EnumMember(Value = "H179T")]
H179T,

[EnumMember(Value = "LETTER")]
LETTER,
}
}
51 changes: 51 additions & 0 deletions source/backend/apimodels/CodeTypes/LeaseLicenceTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace Pims.Api.Models.CodeTypes
{
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
public enum LeaseLicenceTypes
{
[EnumMember(Value = "LICONSTRC")]
LICONSTRC,

[EnumMember(Value = "LIMOTIPRJ")]
LIMOTIPRJ,

[EnumMember(Value = "LIOCCACCS")]
LIOCCACCS,

[EnumMember(Value = "LIOCCTTLD")]
LIOCCTTLD,

[EnumMember(Value = "LIOCCUSE")]
LIOCCUSE,

[EnumMember(Value = "LIOCCUTIL")]
LIOCCUTIL,

[EnumMember(Value = "LIPPUBHWY")]
LIPPUBHWY,

[EnumMember(Value = "LSGRND")]
LSGRND,

[EnumMember(Value = "LSREG")]
LSREG,

[EnumMember(Value = "LSUNREG")]
LSUNREG,

[EnumMember(Value = "MANUFHOME")]
MANUFHOME,

[EnumMember(Value = "OTHER")]
OTHER,

[EnumMember(Value = "RESLNDTEN")]
RESLNDTEN,

[EnumMember(Value = "ROADXING")]
ROADXING,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import LoadingBackdrop from '@/components/common/LoadingBackdrop';
import { ModalContext } from '@/contexts/modalContext';
import { LeaseStateContext } from '@/features/leases/context/LeaseContext';
import { LeaseFormModel } from '@/features/leases/models';
import { useGenerateH1005a } from '@/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH1005a';
import { useGenerateLicenceOfOccupation } from '@/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateLicenceOfOccupation';
import { LeasePageProps } from '@/features/mapSideBar/lease/LeaseContainer';
import { useLeasePaymentRepository } from '@/hooks/repositories/useLeasePaymentRepository';
import { useLeaseTermRepository } from '@/hooks/repositories/useLeaseTermRepository';
Expand All @@ -30,7 +30,7 @@ export const TermPaymentsContainer: React.FunctionComponent<
React.PropsWithChildren<LeasePageProps>
> = ({ formikRef, onSuccess }) => {
const { lease } = useContext(LeaseStateContext);
const generateH1005a = useGenerateH1005a();
const generateH1005a = useGenerateLicenceOfOccupation();
const [editModalValues, setEditModalValues] = useState<FormLeaseTerm | undefined>(undefined);
const [editPaymentModalValues, setEditPaymentModalValues] = useState<
FormLeasePayment | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import {
screen,
userEvent,
waitFor,
prettyDOM,
waitForElementToBeRemoved,
getByTestId,
} from '@/utils/test-utils';

import { defaultFormLeaseTerm, FormLeaseTerm } from './models';
Expand Down Expand Up @@ -123,12 +120,14 @@ describe('TermsPaymentsContainer component', () => {
beforeEach(() => {
mockAxios.resetHistory();
});

it('renders as expected', async () => {
const { component } = await setup({ claims: [Claims.LEASE_EDIT] });
await act(async () => {});

expect(component.asFragment()).toMatchSnapshot();
});

it('renders with data as expected', async () => {
const { component } = await setup({
claims: [Claims.LEASE_EDIT],
Expand All @@ -152,6 +151,7 @@ describe('TermsPaymentsContainer component', () => {

expect(getByDisplayValue('Jan 01, 2020')).toBeVisible();
});

it('makes a post request when adding a new term', async () => {
const {
component: { getAllByText, getByText },
Expand Down Expand Up @@ -282,10 +282,12 @@ describe('TermsPaymentsContainer component', () => {
expect(useLeaseTermRepository().deleteLeaseTerm.execute).toHaveBeenCalled();
});
});

describe('payments logic tests', () => {
mockGetLeaseTerms.execute.mockResolvedValue(
defaultLeaseWithTermsPayments.terms.map(t => FormLeaseTerm.toApi(t)),
);

it('makes a post request when adding a new payment', async () => {
mockGetLeaseTerms.execute.mockResolvedValue(
(mockGetLeaseTerms.response = defaultLeaseWithTermsPayments.terms.map(t =>
Expand Down Expand Up @@ -339,6 +341,7 @@ describe('TermsPaymentsContainer component', () => {
await act(async () => userEvent.click(saveButton));
expect(mockAxios.history.put.length).toBe(1);
});

it('asks for confirmation when deleting a payment', async () => {
mockGetLeaseTerms.execute.mockResolvedValue(
(mockGetLeaseTerms.response = defaultLeaseWithTermsPayments.terms.map(t =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { defaultFormLeaseTerm, FormLeasePayment } from '../../models';
import TermsForm, { ITermsFormProps } from './TermsForm';
import { createRef } from 'react';
import { ApiGen_CodeTypes_LeaseLicenceTypes } from '@/models/api/generated/ApiGen_CodeTypes_LeaseLicenceTypes';

const history = createMemoryHistory();
const mockAxios = new MockAdapter(axios);
Expand Down Expand Up @@ -111,6 +112,7 @@ describe('TermsForm component', () => {

expect(component.asFragment()).toMatchSnapshot();
});

test.each([
['ANNUAL', '$1,000.00', '$1,050.00'],
['SEMIANN', '$1,000.00', '$2,100.00'],
Expand All @@ -135,6 +137,7 @@ describe('TermsForm component', () => {
expect(findCell(row, 8)?.textContent).toBe(total);
},
);

it('Does not display certain fields if the end date is not supplied', async () => {
const { findFirstRow, findCell } = await setup({
store: undefined,
Expand Down Expand Up @@ -462,13 +465,13 @@ describe('TermsForm component', () => {
expect(findCell(row, 11)?.textContent).toContain('Generate H1005(a)');
});

it('calls onGenerate when generation button is clicked', async () => {
it('calls onGenerate H1005A when generation button is clicked', async () => {
const {
component: { queryAllByTitle },
} = await setup({
initialValues: {
...new LeaseFormModel(),
leaseTypeCode: 'LIOCCUTIL',
leaseTypeCode: ApiGen_CodeTypes_LeaseLicenceTypes.LIOCCUTIL,
terms: [
{
...defaultTestFormLeaseTerm,
Expand All @@ -485,4 +488,28 @@ describe('TermsForm component', () => {
await act(async () => userEvent.click(generateButton));
expect(onGenerate).toHaveBeenCalled();
});

it('calls onGenerate H1005 when generation button is clicked', async () => {
const {
component: { queryAllByTitle },
} = await setup({
initialValues: {
...new LeaseFormModel(),
leaseTypeCode: ApiGen_CodeTypes_LeaseLicenceTypes.LIPPUBHWY,
terms: [
{
...defaultTestFormLeaseTerm,
isTermExercised: false,
payments: [{ amountTotal: 1, receivedDate: '2020-01-01T18:00' }] as FormLeasePayment[],
},
],
},
});

const generateButton = queryAllByTitle('Generate H1005')[0];
expect(generateButton).toBeVisible();

await act(async () => userEvent.click(generateButton));
expect(onGenerate).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { Claims } from '@/constants';
import { LeaseTermStatusTypes } from '@/constants/leaseStatusTypes';
import useKeycloakWrapper from '@/hooks/useKeycloakWrapper';
import { ApiGen_CodeTypes_LeaseLicenceTypes } from '@/models/api/generated/ApiGen_CodeTypes_LeaseLicenceTypes';
import { ISystemConstant } from '@/store/slices/systemConstants';
import { NumberFieldValue } from '@/typings/NumberFieldValue';
import { prettyFormatDate } from '@/utils';
Expand Down Expand Up @@ -123,13 +124,28 @@ const termActions = (
{hasClaim(Claims.LEASE_VIEW) &&
index === 0 &&
!!leaseTypeCode &&
['LIOCCACCS', 'LIOCCTTLD', 'LIOCCUSE', 'LIOCCUTIL'].includes(leaseTypeCode) && (
[
ApiGen_CodeTypes_LeaseLicenceTypes.LIOCCACCS.toString(),
ApiGen_CodeTypes_LeaseLicenceTypes.LIOCCTTLD.toString(),
ApiGen_CodeTypes_LeaseLicenceTypes.LIOCCUSE.toString(),
ApiGen_CodeTypes_LeaseLicenceTypes.LIOCCUTIL.toString(),
].includes(leaseTypeCode) && (
<Button
title="Generate H1005(a)"
icon={<GenerateIcon size={24} id={`generate-h1005-a`} title="Generate H1005(a)" />}
onClick={() => onGenerate()}
></Button>
)}

{hasClaim(Claims.LEASE_VIEW) &&
index === 0 &&
leaseTypeCode === ApiGen_CodeTypes_LeaseLicenceTypes.LIPPUBHWY.toString() && (
<Button
title="Generate H1005"
icon={<GenerateIcon size={24} id={`generate-h1005`} title="Generate H1005" />}
onClick={() => onGenerate()}
></Button>
)}
{hasClaim(Claims.LEASE_EDIT) && (
<Button
title="edit term"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { InterestHolderType } from '@/constants/interestHolderTypes';
import { createFileDownload } from '@/features/documents/DownloadDocumentButton';
import { useDocumentGenerationRepository } from '@/features/documents/hooks/useDocumentGenerationRepository';
import { FormTemplateTypes } from '@/features/mapSideBar/shared/content/models';
import { useApiContacts } from '@/hooks/pims-api/useApiContacts';
import { useAcquisitionProvider } from '@/hooks/repositories/useAcquisitionProvider';
import { ApiGen_CodeTypes_AgreementTypes } from '@/models/api/generated/ApiGen_CodeTypes_AgreementTypes';
import { ApiGen_CodeTypes_ExternalResponseStatus } from '@/models/api/generated/ApiGen_CodeTypes_ExternalResponseStatus';
import { ApiGen_CodeTypes_FormTypes } from '@/models/api/generated/ApiGen_CodeTypes_FormTypes';
import { ApiGen_Concepts_AcquisitionFileTeam } from '@/models/api/generated/ApiGen_Concepts_AcquisitionFileTeam';
import { ApiGen_Concepts_Agreement } from '@/models/api/generated/ApiGen_Concepts_Agreement';
import { ApiGen_Concepts_Organization } from '@/models/api/generated/ApiGen_Concepts_Organization';
Expand Down Expand Up @@ -115,16 +115,16 @@ export const useGenerateAgreement = () => {
* @param agreementType
* @returns
*/
const getTemplateTypeFromAgreementType = (agreementType: string | null) => {
const getTemplateTypeFromAgreementType = (agreementType: string | null): string => {
switch (agreementType) {
case ApiGen_CodeTypes_AgreementTypes.H179A:
return FormTemplateTypes.H179A;
return ApiGen_CodeTypes_FormTypes.H179A.toString();
case ApiGen_CodeTypes_AgreementTypes.H179P:
return FormTemplateTypes.H179P;
return ApiGen_CodeTypes_FormTypes.H179P.toString();
case ApiGen_CodeTypes_AgreementTypes.H179T:
return FormTemplateTypes.H179T;
return ApiGen_CodeTypes_FormTypes.H179T.toString();
case ApiGen_CodeTypes_AgreementTypes.H0074:
return FormTemplateTypes.H0074;
return ApiGen_CodeTypes_FormTypes.H0074.toString();
default:
throw Error(`Unable to find form type for agreement type: ${agreementType}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { InterestHolderType } from '@/constants/interestHolderTypes';
import { createFileDownload } from '@/features/documents/DownloadDocumentButton';
import { useDocumentGenerationRepository } from '@/features/documents/hooks/useDocumentGenerationRepository';
import { ExpropriationForm1Model } from '@/features/mapSideBar/acquisition/tabs/expropriation/models';
import { FormTemplateTypes } from '@/features/mapSideBar/shared/content/models';
import { useApiContacts } from '@/hooks/pims-api/useApiContacts';
import { useAcquisitionProvider } from '@/hooks/repositories/useAcquisitionProvider';
import { useInterestHolderRepository } from '@/hooks/repositories/useInterestHolderRepository';
import { ApiGen_CodeTypes_ExternalResponseStatus } from '@/models/api/generated/ApiGen_CodeTypes_ExternalResponseStatus';
import { ApiGen_CodeTypes_FormTypes } from '@/models/api/generated/ApiGen_CodeTypes_FormTypes';
import { Api_GenerateAcquisitionFile } from '@/models/generate/acquisition/GenerateAcquisitionFile';
import { Api_GenerateExpropriationForm1 } from '@/models/generate/acquisition/GenerateExpropriationForm1';
import { isValidId } from '@/utils';
Expand Down Expand Up @@ -76,7 +76,7 @@ export const useGenerateExpropriationForm1 = () => {
});

const generatedFile = await generate({
templateType: FormTemplateTypes.EXPROP_FORM_1,
templateType: ApiGen_CodeTypes_FormTypes.FORM1.toString(),
templateData: expropriationData,
convertToType: null,
});
Expand Down
Loading
Loading