-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '10434-story' into 10434-test
- Loading branch information
Showing
3 changed files
with
305 additions
and
202 deletions.
There are no files selected for viewing
223 changes: 223 additions & 0 deletions
223
...i/src/business/useCases/trialSessions/getTrialSessionPlanningReportDataInteractor.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
import { RawTrialSession } from '@shared/business/entities/trialSessions/TrialSession'; | ||
import { SESSION_TYPES } from '@shared/business/entities/EntityConstants'; | ||
import { UnauthorizedError } from '@web-api/errors/errors'; | ||
import { applicationContext } from '@shared/business/test/createTestApplicationContext'; | ||
import { getTrialSessionPlanningReportDataInteractor } from '@web-api/business/useCases/trialSessions/getTrialSessionPlanningReportDataInteractor'; | ||
import { | ||
mockPetitionerUser, | ||
mockPetitionsClerkUser, | ||
} from '@shared/test/mockAuthUsers'; | ||
|
||
describe('getTrialSessionPlanningReportDataInteractor', () => { | ||
const ALL_TRIAL_SESSIONS_MOCK: RawTrialSession[] = [ | ||
{ | ||
isCalendared: true, | ||
judge: { | ||
name: 'TEST_JUDGE_4', | ||
userId: 'TEST_JUDGE_ID', | ||
}, | ||
sessionType: 'Hybrid', | ||
startDate: '2099-03-01T00:00:00.000Z', | ||
term: 'winter', | ||
termYear: '2023', | ||
trialLocation: 'Denver, Colorado', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: true, | ||
judge: { | ||
name: 'TEST_JUDGE_3', | ||
userId: 'TEST_JUDGE_ID', | ||
}, | ||
sessionType: SESSION_TYPES.hybridSmall, | ||
startDate: '2098-03-01T00:00:00.000Z', | ||
term: 'winter', | ||
termYear: '2023', | ||
trialLocation: 'Denver, Colorado', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: true, | ||
judge: { | ||
name: 'TEST_JUDGE_2', | ||
userId: 'TEST_JUDGE_ID', | ||
}, | ||
sessionType: 'Hybrid', | ||
startDate: '2099-03-01T00:00:00.000Z', | ||
term: 'spring', | ||
termYear: '2023', | ||
trialLocation: 'Denver, Colorado', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: true, | ||
judge: { | ||
name: 'TEST_JUDGE_1', | ||
userId: 'TEST_JUDGE_ID', | ||
}, | ||
sessionType: 'Hybrid', | ||
startDate: '2099-03-01T00:00:00.000Z', | ||
term: 'fall', | ||
termYear: '2023', | ||
trialLocation: 'Denver, Colorado', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: true, | ||
sessionType: 'Special', | ||
startDate: '2024-03-01T00:00:00.000Z', | ||
term: 'winter', | ||
termYear: '2024', | ||
trialLocation: 'Denver, Colorado', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: true, | ||
sessionType: 'Hybrid', | ||
startDate: '2024-03-01T00:00:00.000Z', | ||
term: 'winter', | ||
termYear: '2024', | ||
trialLocation: 'Denver, Colorado', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: false, | ||
sessionType: 'Special', | ||
startDate: '2024-03-01T00:00:00.000Z', | ||
term: 'winter', | ||
termYear: '2024', | ||
trialLocation: 'Denver, Colorado', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: true, | ||
sessionType: 'Special', | ||
startDate: '1998-03-01T00:00:00.000Z', | ||
term: 'winter', | ||
termYear: '2024', | ||
trialLocation: 'Fresno, California', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: true, | ||
sessionType: 'Special', | ||
startDate: '1999-03-01T00:00:00.000Z', | ||
term: 'winter', | ||
termYear: '2024', | ||
trialLocation: 'Fresno, California', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: true, | ||
sessionType: 'Special', | ||
startDate: '1997-03-01T00:00:00.000Z', | ||
term: 'winter', | ||
termYear: '2024', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: true, | ||
sessionType: 'Special', | ||
startDate: '2024-03-01T00:00:00.000Z', | ||
term: 'winter', | ||
termYear: '2024', | ||
trialLocation: 'Denver, Colorado', | ||
} as RawTrialSession, | ||
{ | ||
isCalendared: true, | ||
sessionType: 'Hybrid', | ||
startDate: '2019-03-01T00:00:00.000Z', | ||
term: 'winter', | ||
termYear: '2024', | ||
trialLocation: 'Denver, Colorado', | ||
} as RawTrialSession, | ||
]; | ||
const SMALL_ELIGIBLE_CASES_FOR_TRIAL_CITY_MOCK = [{}]; | ||
const REGULAR_ELIGIBLE_CASES_FOR_TRIAL_CITY_MOCK = [{}, {}]; | ||
const BLOCKED_CASES_MOCK = [{}, {}, {}]; | ||
|
||
beforeEach(() => { | ||
applicationContext | ||
.getPersistenceGateway() | ||
.getTrialSessions.mockResolvedValue(ALL_TRIAL_SESSIONS_MOCK); | ||
|
||
applicationContext | ||
.getPersistenceGateway() | ||
.getEligibleCasesForTrialCity.mockImplementation(({ procedureType }) => { | ||
if (procedureType === 'Small') | ||
return SMALL_ELIGIBLE_CASES_FOR_TRIAL_CITY_MOCK; | ||
return REGULAR_ELIGIBLE_CASES_FOR_TRIAL_CITY_MOCK; | ||
}); | ||
|
||
applicationContext | ||
.getPersistenceGateway() | ||
.getBlockedCases.mockResolvedValue(BLOCKED_CASES_MOCK); | ||
}); | ||
|
||
it('should throw error if the user is "Unauthorized"', async () => { | ||
applicationContext | ||
.getPersistenceGateway() | ||
.getTrialSessionById.mockReturnValue({}); | ||
|
||
await expect( | ||
getTrialSessionPlanningReportDataInteractor( | ||
applicationContext, | ||
{ | ||
term: 'winter', | ||
year: 2024, | ||
}, | ||
mockPetitionerUser, | ||
), | ||
).rejects.toThrow(UnauthorizedError); | ||
}); | ||
|
||
it('should return the correct Trial Session Planning Data for the correct term', async () => { | ||
const { previousTerms, trialLocationData } = | ||
await getTrialSessionPlanningReportDataInteractor( | ||
applicationContext, | ||
{ | ||
term: 'winter', | ||
year: 2024, | ||
}, | ||
mockPetitionsClerkUser, | ||
); | ||
|
||
const DENVER_TRIAL_SESSION = trialLocationData.find( | ||
ts => ts.trialCityState === 'Denver, Colorado', | ||
); | ||
|
||
expect(DENVER_TRIAL_SESSION).toEqual({ | ||
allCaseCount: 3, | ||
blockedCaseCount: 3, | ||
lastVisitedDate: '2099-03-01T00:00:00.000Z', | ||
previousTermsData: [ | ||
['(H) TEST_JUDGE_1'], | ||
['(H) TEST_JUDGE_2'], | ||
['(HS) TEST_JUDGE_3', '(H) TEST_JUDGE_4'], | ||
], | ||
regularCaseCount: 2, | ||
smallCaseCount: 1, | ||
specialCaseCount: 2, | ||
stateAbbreviation: 'CO', | ||
trialCityState: 'Denver, Colorado', | ||
}); | ||
|
||
expect(previousTerms).toEqual([ | ||
{ term: 'fall', termDisplay: 'Fall 2023', year: 2023 }, | ||
{ term: 'spring', termDisplay: 'Spring 2023', year: 2023 }, | ||
{ term: 'winter', termDisplay: 'Winter 2023', year: 2023 }, | ||
]); | ||
}); | ||
|
||
it('should return the correct last visited date when there is no scheduled trial session in past 3 terms', async () => { | ||
const { trialLocationData } = | ||
await getTrialSessionPlanningReportDataInteractor( | ||
applicationContext, | ||
{ | ||
term: 'winter', | ||
year: 2024, | ||
}, | ||
mockPetitionsClerkUser, | ||
); | ||
|
||
const FRESNO_TRIAL_SESSION = trialLocationData.find( | ||
ts => ts.trialCityState === 'Fresno, California', | ||
); | ||
|
||
expect(FRESNO_TRIAL_SESSION).toMatchObject({ | ||
lastVisitedDate: '1999-03-01T00:00:00.000Z', | ||
specialCaseCount: 2, | ||
trialCityState: 'Fresno, California', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.