Skip to content

Commit

Permalink
psp-7896 add acquisition properties request to generate letter logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith committed Mar 6, 2024
1 parent 54c091c commit 66aa481
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { mockAcquisitionFileResponse } from '@/mocks/acquisitionFiles.mock';
import { ApiGen_Concepts_AcquisitionFile } from '@/models/api/generated/ApiGen_Concepts_AcquisitionFile';

import { useGenerateLetter } from '../hooks/useGenerateLetter';
import { ApiGen_Concepts_AcquisitionFileProperty } from '@/models/api/generated/ApiGen_Concepts_AcquisitionFileProperty';

const generateFn = jest.fn();
const getAcquisitionFileFn = jest.fn<ApiGen_Concepts_AcquisitionFile | undefined, any[]>();
const getAcquisitionFilePropertiesFn = jest.fn<ApiGen_Concepts_AcquisitionFileProperty | undefined, any[]>();
const getPersonConceptFn = jest.fn();
const getOrganizationConceptFn = jest.fn();

Expand All @@ -25,6 +27,7 @@ jest.mock('@/features/documents/hooks/useDocumentGenerationRepository');
jest.mock('@/hooks/repositories/useAcquisitionProvider');
(useAcquisitionProvider as jest.Mock).mockImplementation(() => ({
getAcquisitionFile: { execute: getAcquisitionFileFn },
getAcquisitionProperties: { execute: getAcquisitionFilePropertiesFn },
}));

jest.mock('@/hooks/pims-api/useApiContacts');
Expand All @@ -35,7 +38,7 @@ jest.mock('@/hooks/pims-api/useApiContacts');

let currentStore: MockStoreEnhanced<any, {}>;
const mockStore = configureMockStore([thunk]);
const getStore = (values?: any) => {
const getStore = (values?: any) => {
currentStore = mockStore(values ?? {});
return currentStore;
};
Expand All @@ -62,10 +65,12 @@ const setup = (params?: {
};

describe('useGenerateLetter functions', () => {
it('makes requests to expected api endpoints', async () => {
it('makes requests to expected base api endpoints', async () => {
const generate = setup();
await act(async () => {
await generate(0);
expect(getAcquisitionFileFn).toHaveBeenCalled();
expect(getAcquisitionFilePropertiesFn).toHaveBeenCalled();
expect(generateFn).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const useGenerateLetter = () => {
const { getPersonConcept, getOrganizationConcept } = useApiContacts();
const {
getAcquisitionFile: { execute: getAcquisitionFile },
getAcquisitionProperties: { execute: getAcquisitionProperties },
} = useAcquisitionProvider();

const { generateDocumentDownloadWrappedRequest: generate } = useDocumentGenerationRepository();
Expand All @@ -22,6 +23,8 @@ export const useGenerateLetter = () => {
) => {
const file = await getAcquisitionFile(acquisitionFileId);
if (file) {
const properties = await getAcquisitionProperties(acquisitionFileId);
file.fileProperties = properties ?? [];
const coordinator = file.acquisitionTeam?.find(
team => team.teamProfileTypeCode === 'PROPCOORD',
);
Expand Down

0 comments on commit 66aa481

Please sign in to comment.