Skip to content

Commit

Permalink
Merge pull request #10148 from flexion/10049-judge-activity-report-Ju…
Browse files Browse the repository at this point in the history
…dgeActivityReportFilters-refactor

10049 judge activity report judge activity report filters refactor
  • Loading branch information
TomElliottFlexion committed Sep 19, 2023
2 parents e08ccf5 + e5d8b1a commit 0cd8d8f
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
isAuthorized,
} from '../../../authorization/authorizationClientService';
import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet';
import { getCountOfConsolidedCases } from '@web-api/persistence/elasticsearch/getCountOfConsolidedCases';

export type JudgeActivityReportCavAndSubmittedCasesRequest = {
statuses: string[];
Expand Down Expand Up @@ -38,7 +37,7 @@ export type CavAndSubmittedFilteredCasesType = {
};

export const getCasesByStatusAndByJudgeInteractor = async (
applicationContext,
applicationContext: IApplicationContext,
params: JudgeActivityReportCavAndSubmittedCasesRequest,
): Promise<{
cases: CavAndSubmittedFilteredCasesType[];
Expand Down Expand Up @@ -189,8 +188,10 @@ const calculateNumberOfConsolidatedCases = async (
return 0;
}

return await getCountOfConsolidedCases({
applicationContext,
leadDocketNumber: caseInfo.leadDocketNumber,
});
return await applicationContext
.getPersistenceGateway()
.getCountOfConsolidedCases({
applicationContext,
leadDocketNumber: caseInfo.leadDocketNumber,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export type CasesClosedType = {
};

export type CasesClosedReturnType = {
aggregations: CasesClosedType;
aggregations: CasesClosedType | {};
total: number | undefined;
};

export const getCasesClosedByJudgeInteractor = async (
applicationContext,
applicationContext: IApplicationContext,
params: JudgeActivityReportFilters,
): Promise<CasesClosedReturnType> => {
const authorizedUser = applicationContext.getCurrentUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ export type CaseDocumentsAggregationReturnType = {
opinions: AggregatedEventCodesType;
};

// TODO: refactor JudgeActivityReportFilters to be only types for request to BE
export type JudgeActivityReportFilters = {
endDate: string;
startDate: string;
judgeName?: string;
judgeId?: string;
judges?: string[];
judgeNameToDisplayForHeader?: string;
judges: string[];
};

export const getCountOfCaseDocumentsFiledByJudgesInteractor = async (
Expand Down
11 changes: 2 additions & 9 deletions shared/src/proxies/reports/getCasesByStatusAndByJudgeProxy.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import { ClientApplicationContext } from '@web-client/applicationContext';
import { JudgeActivityReportCavAndSubmittedCasesRequest } from '@shared/business/useCases/judgeActivityReport/getCasesByStatusAndByJudgeInteractor';
import { post } from '../requests';

/**
* getCasesByStatusAndByJudgeInteractor
* @param {object} applicationContext the application context
* @param {object} providers the providers object
* @param {string} providers.judgeName the judge name for the report query
* @param {string} providers.statuses case statuses array for the report query
* @returns {Promise<*>} the promise of the api call
*/
export const getCasesByStatusAndByJudgeInteractor = (
applicationContext,
applicationContext: ClientApplicationContext,
params: JudgeActivityReportCavAndSubmittedCasesRequest,
): Promise<{
cases: RawCase[];
Expand Down
12 changes: 2 additions & 10 deletions shared/src/proxies/reports/getCasesClosedByJudgeProxy.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import { CasesClosedType } from '@shared/business/useCases/judgeActivityReport/getCasesClosedByJudgeInteractor';
import { ClientApplicationContext } from '@web-client/applicationContext';
import { JudgeActivityReportFilters } from '@shared/business/useCases/judgeActivityReport/getCountOfCaseDocumentsFiledByJudgesInteractor';
import { post } from '../requests';

/**
* getCasesClosedByJudgeInteractor
* @param {object} applicationContext the application context
* @param {object} providers the providers object
* @param {string} providers.endDate the end date for the report query
* @param {string} providers.judgeName the judge name for the report query
* @param {string} providers.startDate the start date for the report query
* @returns {Promise<CasesClosedType>} the promise of the api call
*/
export const getCasesClosedByJudgeInteractor = (
applicationContext,
applicationContext: ClientApplicationContext,
params: JudgeActivityReportFilters,
): Promise<CasesClosedType> => {
return post({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ClientApplicationContext } from '@web-client/applicationContext';
import { JudgeActivityReportFilters } from '@shared/business/useCases/judgeActivityReport/getCountOfCaseDocumentsFiledByJudgesInteractor';
import { TrialSessionTypes } from '@shared/business/useCases/judgeActivityReport/getTrialSessionsForJudgeActivityReportInteractor';
import { post } from '../requests';

export const getTrialSessionsForJudgeActivityReportInteractor = (
applicationContext,
applicationContext: ClientApplicationContext,
{ endDate, judgeId, startDate }: JudgeActivityReportFilters,
): Promise<TrialSessionTypes> =>
post({
Expand Down
2 changes: 2 additions & 0 deletions web-api/src/getPersistenceGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import { getCognitoUserIdByEmail } from './persistence/cognito/getCognitoUserIdB
import { getCompletedSectionInboxMessages } from './persistence/elasticsearch/messages/getCompletedSectionInboxMessages';
import { getCompletedUserInboxMessages } from './persistence/elasticsearch/messages/getCompletedUserInboxMessages';
import { getConfigurationItemValue } from './persistence/dynamo/deployTable/getConfigurationItemValue';
import { getCountOfConsolidedCases } from '@web-api/persistence/elasticsearch/getCountOfConsolidedCases';
import { getDeployTableStatus } from './persistence/dynamo/getDeployTableStatus';
import { getDispatchNotification } from './persistence/dynamo/notifications/getDispatchNotification';
import { getDocketEntriesServedWithinTimeframe } from './persistence/elasticsearch/getDocketEntriesServedWithinTimeframe';
Expand Down Expand Up @@ -329,6 +330,7 @@ const gatewayMethods = {
getCognitoUserIdByEmail,
getCompletedSectionInboxMessages,
getCompletedUserInboxMessages,
getCountOfConsolidedCases,
getDeployTableStatus,
getDispatchNotification,
getDocketEntriesServedWithinTimeframe,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CASE_STATUS_TYPES } from '@shared/business/entities/EntityConstants';
import { CasesClosedReturnType } from '@shared/business/useCases/judgeActivityReport/getCasesClosedByJudgeInteractor';
import { QueryDslQueryContainer } from '@opensearch-project/opensearch/api/types';
import { search } from './searchClient';

Expand All @@ -12,7 +13,7 @@ export const getCasesClosedCountByJudge = async ({
endDate: string;
judges: string[];
startDate: string;
}) => {
}): Promise<CasesClosedReturnType> => {
const source = ['status'];

const shouldFilters: QueryDslQueryContainer[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ export const getCountOfConsolidedCases = async ({
index: 'efcms-case',
},
});

return results;
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { CAV_AND_SUBMITTED_CASES_PAGE_SIZE } from '../../../../../shared/src/business/entities/EntityConstants';
import { state } from '@web-client/presenter/app.cerebral';

/**
* Retrieves the cases with a status of CAV or Submitted by judge
* @param {object} providers the providers object
* @param {object} providers.applicationContext the application context
* @param {object} providers.get the cerebral get function
* @returns {object} an array of case entities and a map containing consolidated cases group counts
*/
export const getSubmittedAndCavCasesByJudgeAction = async ({
applicationContext,
get,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('getTrialSessionsForJudgeActivityReportAction', () => {
);
});

it('should call the interactor to set state.judgeActivityReport.judgeActivityReportData.trialSessions with the trialSessions types based on the selected judge id', async () => {
it('should retrieve trialSessions types based on a selected judges id', async () => {
const { output } = await runAction(
getTrialSessionsForJudgeActivityReportAction,
{
Expand All @@ -43,9 +43,9 @@ describe('getTrialSessionsForJudgeActivityReportAction', () => {
judgeActivityReport: {
filters: {
endDate: mockEndDate,
judgeName,
startDate: mockStartDate,
},
judgeName,
},
judges: mockJudges,
},
Expand All @@ -64,28 +64,24 @@ describe('getTrialSessionsForJudgeActivityReportAction', () => {
expect(output.trialSessions).toMatchObject(trialSessionTypesResult);
});

it('should set state.judgeActivityReport.judgeActivityReportData.trialSessions with the trialSessions types for all judges if no selected judge id is prescribed', async () => {
const { output } = await runAction(
getTrialSessionsForJudgeActivityReportAction,
{
modules: {
presenter,
},
props: {},
state: {
judgeActivityReport: {
filters: {
endDate: mockEndDate,
judgeName: 'All Judges',
startDate: mockStartDate,
},
it('should retrieve ALL trialSession types if no selected judge id is prescribed', async () => {
await runAction(getTrialSessionsForJudgeActivityReportAction, {
modules: {
presenter,
},
props: {},
state: {
judgeActivityReport: {
filters: {
endDate: mockEndDate,
startDate: mockStartDate,
},
judges: mockJudges,
judgeName: 'All Judges',
},
judges: mockJudges,
},
);
});

expect(output.trialSessions).toMatchObject(trialSessionTypesResult);
expect(
applicationContext.getUseCases()
.getTrialSessionsForJudgeActivityReportInteractor.mock.calls[0][1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export const getTrialSessionsForJudgeActivityReportAction = async ({
applicationContext,
get,
}: ActionProps) => {
const { endDate, judgeName, startDate } = get(
state.judgeActivityReport.filters,
);
const { endDate, startDate } = get(state.judgeActivityReport.filters);

const { judgeName } = get(state.judgeActivityReport);

let judgeIdForRequest: string = ID_FOR_ALL_JUDGES;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import { setJudgeActivityReportFiltersAction } from './setJudgeActivityReportFil
presenter.providers.applicationContext = applicationContextForClient;

describe('setJudgeActivityReportFiltersAction', () => {
let filters;
beforeEach(() => {
filters = {
endDate: '',
judgeName: '',
startDate: '',
};
});
const filters = {
endDate: '',
startDate: '',
};

const testEndDate = '2019-05-17';
const testStartDate = '2019-05-14';

Expand Down Expand Up @@ -56,7 +53,7 @@ describe('setJudgeActivityReportFiltersAction', () => {
expect(result.state.judgeActivityReport.filters.endDate).toEqual('');
});

it('sets state.judgeActivityReport.filters.startDate to the formatted props.startDate', async () => {
it('sets state.judgeActivityReport.filters.startDate to props.startDate', async () => {
const result = await runAction(setJudgeActivityReportFiltersAction, {
modules: { presenter },
props: {
Expand All @@ -73,7 +70,8 @@ describe('setJudgeActivityReportFiltersAction', () => {
testStartDate,
);
});
it('sets state.judgeActivityReport.filters.endDate to the formatted props.endDate', async () => {

it('sets state.judgeActivityReport.filters.endDate to props.endDate', async () => {
const result = await runAction(setJudgeActivityReportFiltersAction, {
modules: { presenter },
props: {
Expand All @@ -91,7 +89,7 @@ describe('setJudgeActivityReportFiltersAction', () => {
);
});

it('should set state.judgeActivityReport.filters.judgeName to props.judgeName', async () => {
it('should set state.judgeActivityReport.judgeName to props.judgeName', async () => {
const result = await runAction(setJudgeActivityReportFiltersAction, {
modules: { presenter },
props: {
Expand All @@ -104,8 +102,6 @@ describe('setJudgeActivityReportFiltersAction', () => {
},
});

expect(result.state.judgeActivityReport.filters.judgeName).toEqual(
judgeUser.name,
);
expect(result.state.judgeActivityReport.judgeName).toEqual(judgeUser.name);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const setJudgeActivityReportFiltersAction = ({
const selectedJudge: string = props.judgeName;

if (selectedJudge) {
store.set(state.judgeActivityReport.filters.judgeName, selectedJudge);
store.set(state.judgeActivityReport.judgeName, selectedJudge);
}
if (filterStartDate || filterStartDate === '') {
store.set(state.judgeActivityReport.filters.startDate, filterStartDate);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext';
import {
colvinsChambersUser,
judgeUser,
} from '../../../../../shared/src/test/mockUsers';
import { presenter } from '../../presenter-mock';
import { colvinsChambersUser, judgeUser } from '@shared/test/mockUsers';
import { presenter } from '@web-client/presenter/presenter-mock';
import { runAction } from '@web-client/presenter/test.cerebral';
import { setJudgeLastNameOnJudgeActivityReportAction } from './setJudgeLastNameOnJudgeActivityReportAction';

Expand All @@ -22,8 +19,8 @@ describe('setJudgeLastNameOnJudgeActivityReportAction', () => {
},
);

expect(state.judgeActivityReport.filters.judgeName).toBe(judgeUser.name);
expect(state.judgeActivityReport.filters.judgeNameToDisplayForHeader).toBe(
expect(state.judgeActivityReport.judgeName).toBe(judgeUser.name);
expect(state.judgeActivityReport.judgeNameToDisplayForHeader).toBe(
judgeUser.name,
);
});
Expand All @@ -40,9 +37,9 @@ describe('setJudgeLastNameOnJudgeActivityReportAction', () => {
},
);

expect(state.judgeActivityReport.filters.judgeNameToDisplayForHeader).toBe(
expect(state.judgeActivityReport.judgeNameToDisplayForHeader).toBe(
'Colvin',
);
expect(state.judgeActivityReport.filters.judgeName).toBe('Colvin');
expect(state.judgeActivityReport.judgeName).toBe('Colvin');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ export const setJudgeLastNameOnJudgeActivityReportAction = ({

judgeName = applicationContext
.getUtilities()
.getJudgeLastName(userSectionInfo.judgeFullName);
.getJudgeLastName(userSectionInfo!.judgeFullName);
} else {
judgeName = user.name;
}

store.set(state.judgeActivityReport.filters.judgeName, judgeName);
store.set(
state.judgeActivityReport.filters.judgeNameToDisplayForHeader,
judgeName,
);
store.set(state.judgeActivityReport.judgeName, judgeName);
store.set(state.judgeActivityReport.judgeNameToDisplayForHeader, judgeName);
};
Loading

0 comments on commit 0cd8d8f

Please sign in to comment.