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

10565 bug #5614

Merged
merged 5 commits into from
Dec 3, 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
74 changes: 61 additions & 13 deletions web-api/src/business/useCases/caseAdvancedSearchInteractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ import {
mockPetitionsClerkUser,
} from '@shared/test/mockAuthUsers';

export const MOCK_CASE_SEARCH_RESULT = {
caseCaption: 'Test Case Caption',
docketNumber: '101-20',
docketNumberWithSuffix: '101-20L',
fakeField: 'Hide this',
irsPractitioners: [
{
address: 'Hide this',
name: 'TestIRSPractitioner',
state: 'California',
},
],
petitioners: [
{
address: 'Hide this',
name: 'Test Petitioner',
state: 'California',
},
],
privatePractitioners: [
{ address: 'Hide this', name: 'TestPrivatePractitioner' },
],
receivedAt: '2023-01-24T22:34:48.100Z',
};

describe('caseAdvancedSearchInteractor', () => {
it('returns an unauthorized error on petitioner user role', async () => {
await expect(
Expand Down Expand Up @@ -57,8 +82,8 @@ describe('caseAdvancedSearchInteractor', () => {
);

expect(results).toEqual([
{ docketNumber: '101-20', petitioners: [] },
{ docketNumber: '201-20', petitioners: [] },
{ docketNumber: '101-20', petitionerNames: [], petitionerStateNames: [] },
{ docketNumber: '201-20', petitionerNames: [], petitionerStateNames: [] },
]);
});

Expand Down Expand Up @@ -87,8 +112,8 @@ describe('caseAdvancedSearchInteractor', () => {
);

expect(results).toEqual([
{ docketNumber: '101-20', petitioners: [] },
{ docketNumber: '201-20', petitioners: [] },
{ docketNumber: '101-20', petitionerNames: [], petitionerStateNames: [] },
{ docketNumber: '201-20', petitionerNames: [], petitionerStateNames: [] },
]);
});

Expand Down Expand Up @@ -187,13 +212,8 @@ describe('caseAdvancedSearchInteractor', () => {
expect(results).toEqual([
{
docketNumber: '101-20',
irsPractitioners: [
{
userId: mockIrsPractitionerUser.userId,
},
],
petitioners: [],
sealedDate: 'yup',
petitionerNames: [],
petitionerStateNames: [],
},
]);
});
Expand All @@ -220,8 +240,36 @@ describe('caseAdvancedSearchInteractor', () => {
expect(results).toEqual([
{
docketNumber: '101-20',
petitioners: [],
sealedDate: 'yup',
petitionerNames: [],
petitionerStateNames: [],
},
]);
});

it('BUG: should return only necessary advanced search case data', async () => {
applicationContext
.getPersistenceGateway()
.caseAdvancedSearch.mockResolvedValue([MOCK_CASE_SEARCH_RESULT]);

const results = await caseAdvancedSearchInteractor(
applicationContext,
{
petitionerName: 'test person',
},
mockPetitionsClerkUser,
);

expect(Object.keys(results[0])).toHaveLength(6);
expect(results).toMatchObject([
{
caseCaption: MOCK_CASE_SEARCH_RESULT.caseCaption,
docketNumber: MOCK_CASE_SEARCH_RESULT.docketNumber,
docketNumberWithSuffix: MOCK_CASE_SEARCH_RESULT.docketNumberWithSuffix,
petitionerNames: MOCK_CASE_SEARCH_RESULT.petitioners.map(p => p.name),
petitionerStateNames: MOCK_CASE_SEARCH_RESULT.petitioners.map(
p => p.state,
),
receivedAt: MOCK_CASE_SEARCH_RESULT.receivedAt,
},
]);
});
Expand Down
25 changes: 23 additions & 2 deletions web-api/src/business/useCases/caseAdvancedSearchInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AbbrevatedStates,
CountryTypes,
MAX_SEARCH_RESULTS,
US_STATES,
} from '../../../../shared/src/business/entities/EntityConstants';
import {
ROLE_PERMISSIONS,
Expand All @@ -24,6 +25,15 @@ export type CaseAdvancedSearchParamsRequestType = {
startDate?: string;
};

export type CaseSearchResult = {
petitionerNames: string[];
docketNumberWithSuffix: string;
docketNumber: string;
receivedAt: string;
caseCaption: string;
petitionerStateNames?: string[];
};

export const caseAdvancedSearchInteractor = async (
applicationContext: ServerApplicationContext,
{
Expand All @@ -34,7 +44,7 @@ export const caseAdvancedSearchInteractor = async (
startDate,
}: CaseAdvancedSearchParamsRequestType,
authorizedUser: UnknownAuthUser,
) => {
): Promise<CaseSearchResult[]> => {
let searchStartDate;
let searchEndDate;

Expand Down Expand Up @@ -80,5 +90,16 @@ export const caseAdvancedSearchInteractor = async (
MAX_SEARCH_RESULTS,
);

return filteredCases;
return filteredCases.map(filteredCase => {
return {
caseCaption: filteredCase.caseCaption,
docketNumber: filteredCase.docketNumber,
docketNumberWithSuffix: filteredCase.docketNumberWithSuffix,
petitionerNames: filteredCase.petitioners?.map(p => p.name),
petitionerStateNames: filteredCase.petitioners?.map(
p => US_STATES[p.state] || p.state,
),
receivedAt: filteredCase.receivedAt,
};
});
Comment on lines +93 to +104
Copy link
Collaborator

Choose a reason for hiding this comment

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

Total personal preference and absolutely not necessary to change, but I like using shorthand where possible.

This:

return someArray.map(m => {
  return {
    foo: 'bar'
  };
});

can be shortened by wrapping the return object in parens:

return someArray.map(m => ({
  foo: 'bar'
}));

};
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { CaseAdvancedSearchParamsRequestType } from '@web-api/business/useCases/caseAdvancedSearchInteractor';
import { CasePublicSearchResultsType } from '@web-api/persistence/elasticsearch/casePublicSearch';
import {
CaseAdvancedSearchParamsRequestType,
CaseSearchResult,
} from '@web-api/business/useCases/caseAdvancedSearchInteractor';
import { ServerApplicationContext } from '@web-api/applicationContext';
import {
createEndOfDayISO,
Expand All @@ -15,7 +17,7 @@ export const casePublicSearchInteractor = async (
petitionerState,
startDate,
}: CaseAdvancedSearchParamsRequestType,
): Promise<{ results: CasePublicSearchResultsType }> => {
): Promise<{ results: CaseSearchResult[] }> => {
let searchStartDate;
let searchEndDate;

Expand Down
26 changes: 25 additions & 1 deletion web-api/src/persistence/elasticsearch/casePublicSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { casePublicSearch } from './casePublicSearch';
jest.mock('./searchClient');
import { CaseAdvancedSearchParamsRequestType } from '@web-api/business/useCases/caseAdvancedSearchInteractor';
import { MAX_SEARCH_RESULTS } from '@shared/business/entities/EntityConstants';
import { MOCK_CASE_SEARCH_RESULT } from '@web-api/business/useCases/caseAdvancedSearchInteractor.test';
import { search } from './searchClient';

jest.mock(
Expand All @@ -22,7 +23,10 @@ describe('casePublicSearch', () => {
petitionerName: 'test person',
};

search.mockReturnValue({ results: ['some', 'matches'], total: 0 });
search.mockReturnValue({
results: [MOCK_CASE_SEARCH_RESULT],
total: 0,
});

const mustNotClause = [
{
Expand Down Expand Up @@ -66,4 +70,24 @@ describe('casePublicSearch', () => {
expectedQuery,
);
});

it('BUG: should return only necessary public search case data', async () => {
const { results } = await casePublicSearch({
applicationContext,
searchTerms,
});
expect(Object.keys(results[0])).toHaveLength(6);
expect(results).toMatchObject([
{
caseCaption: MOCK_CASE_SEARCH_RESULT.caseCaption,
docketNumber: MOCK_CASE_SEARCH_RESULT.docketNumber,
docketNumberWithSuffix: MOCK_CASE_SEARCH_RESULT.docketNumberWithSuffix,
petitionerNames: MOCK_CASE_SEARCH_RESULT.petitioners.map(p => p.name),
petitionerStateNames: MOCK_CASE_SEARCH_RESULT.petitioners.map(
p => p.state,
),
receivedAt: MOCK_CASE_SEARCH_RESULT.receivedAt,
},
]);
});
});
44 changes: 25 additions & 19 deletions web-api/src/persistence/elasticsearch/casePublicSearch.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
import { CaseAdvancedSearchParamsRequestType } from '@web-api/business/useCases/caseAdvancedSearchInteractor';
import { MAX_SEARCH_RESULTS } from '../../../../shared/src/business/entities/EntityConstants';
import { RawIrsPractitioner } from '@shared/business/entities/IrsPractitioner';
import {
CaseAdvancedSearchParamsRequestType,
CaseSearchResult,
} from '@web-api/business/useCases/caseAdvancedSearchInteractor';
import {
MAX_SEARCH_RESULTS,
US_STATES,
} from '../../../../shared/src/business/entities/EntityConstants';
import { aggregateCommonQueryParams } from '../../../../shared/src/business/utilities/aggregateCommonQueryParams';
import { search } from './searchClient';

export type CasePublicSearchResultsType = {
caseCaption?: string;
contactId?: string;
docketNumber: string;
docketNumberSuffix?: string;
docketNumberWithSuffix: string;
irsPractitioners: RawIrsPractitioner[];
partyType: string;
petitioners: TPetitioner[];
receivedAt: string;
sealedDate?: string;
isSealed: boolean;
};

export const casePublicSearch = async ({
applicationContext,
searchTerms,
}: {
applicationContext: IApplicationContext;
searchTerms: CaseAdvancedSearchParamsRequestType;
}): Promise<{ results: CasePublicSearchResultsType }> => {
}): Promise<{ results: CaseSearchResult[] }> => {
const { commonQuery, exactMatchesQuery } =
aggregateCommonQueryParams(searchTerms);

Expand Down Expand Up @@ -66,7 +57,7 @@ export const casePublicSearch = async ({
},
};

return await search({
const cases = await search({
applicationContext,
searchParameters: {
body: {
Expand All @@ -78,4 +69,19 @@ export const casePublicSearch = async ({
index: 'efcms-case',
},
});

return {
results: cases.results.map(c => {
return {
caseCaption: c.caseCaption,
docketNumber: c.docketNumber,
docketNumberWithSuffix: c.docketNumberWithSuffix,
petitionerNames: c.petitioners?.map(p => p.name),
petitionerStateNames: c.petitioners?.map(
p => US_STATES[p.state] || p.state,
),
receivedAt: c.receivedAt,
};
}),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,10 @@ describe(`Petitioner searches for partial name match ${searchTerm}`, () => {
expect(searchResults).toEqual(
expect.arrayContaining([
expect.objectContaining({
petitioners: [
expect.objectContaining({
name: caseNamesToCreate[0],
}),
],
petitionerNames: [caseNamesToCreate[0]],
}),
expect.objectContaining({
petitioners: [
expect.objectContaining({
name: caseNamesToCreate[2],
}),
],
petitionerNames: [caseNamesToCreate[2]],
}),
]),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CasePublicSearchResultsType } from '@web-api/persistence/elasticsearch/casePublicSearch';
import { CaseSearchResult } from '@web-api/business/useCases/caseAdvancedSearchInteractor';
import { state } from '@web-client/presenter/app.cerebral';

export const setAdvancedSearchResultsAction = ({
get,
props,
store,
}: ActionProps<{
searchResults: CasePublicSearchResultsType;
searchResults: CaseSearchResult[];
}>) => {
const tabName = get(state.advancedSearchTab);
store.set(state.searchResults[tabName], props.searchResults);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CasePublicSearchResultsType } from '@web-api/persistence/elasticsearch/casePublicSearch';
import { CaseSearchResult } from '@web-api/business/useCases/caseAdvancedSearchInteractor';
import { PublicClientState } from '@web-client/presenter/state-public';
import { applicationContextForClient } from '@web-client/test/createClientTestApplicationContext';
import { presenter } from '../../presenter-public';
Expand All @@ -16,19 +16,19 @@ describe('submitPublicCaseAdvancedSearchAction', () => {
});

it('gets the public case information', async () => {
await runAction<
{ searchResults: CasePublicSearchResultsType },
PublicClientState
>(submitPublicCaseAdvancedSearchAction, {
modules: {
presenter,
},
state: {
advancedSearchForm: {
caseSearchByName: { petitionerName: 'case name' },
await runAction<{ searchResults: CaseSearchResult[] }, PublicClientState>(
submitPublicCaseAdvancedSearchAction,
{
modules: {
presenter,
},
state: {
advancedSearchForm: {
caseSearchByName: { petitionerName: 'case name' },
},
},
},
});
);

expect(
applicationContextForClient.getUseCases().casePublicSearchInteractor.mock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CasePublicSearchResultsType } from '@web-api/persistence/elasticsearch/casePublicSearch';
import { CaseSearchResult } from '@web-api/business/useCases/caseAdvancedSearchInteractor';
import { ClientPublicApplicationContext } from '@web-client/applicationContextPublic';
import { prepareFormDataForCaseSearchApi } from '@web-client/presenter/actions/AdvancedSearch/submitCaseAdvancedSearchAction';
import { state } from '@web-client/presenter/app-public.cerebral';
Expand All @@ -7,7 +7,7 @@ export const submitPublicCaseAdvancedSearchAction = async ({
applicationContext,
get,
}: ActionProps<{}, ClientPublicApplicationContext>): Promise<{
searchResults: CasePublicSearchResultsType;
searchResults: CaseSearchResult[];
}> => {
const form = get(state.advancedSearchForm.caseSearchByName);

Expand Down
Loading
Loading