Skip to content

Commit

Permalink
9970: Create a TrialSessionFactory and multiple trial session types t…
Browse files Browse the repository at this point in the history
…o better handle operations that are unique to a trial session status.
  • Loading branch information
rachelschneiderman committed Jul 4, 2023
1 parent b11902f commit 1a638da
Show file tree
Hide file tree
Showing 50 changed files with 586 additions and 651 deletions.
10 changes: 5 additions & 5 deletions shared/src/business/entities/cases/Case.isHearing.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TrialSessionFactory } from '../trialSessions/TrialSessionFactory';
const {
applicationContext,
} = require('../../test/createTestApplicationContext');
const { Case } = require('./Case');
const { MOCK_CASE } = require('../../../test/mockCase');
const { TrialSession } = require('../trialSessions/TrialSession');

describe('isHearing', () => {
it('checks if the given trialSessionId is a hearing (true)', () => {
const trialSessionHearing = new TrialSession(
const trialSessionHearing = TrialSessionFactory(
{
isCalendared: true,
judge: { name: 'Judge Buch' },
Expand All @@ -18,7 +18,7 @@ describe('isHearing', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
const caseToUpdate = new Case(
{
Expand All @@ -36,7 +36,7 @@ describe('isHearing', () => {
});

it('checks if the given trialSessionId is a hearing (false)', () => {
const trialSessionHearing = new TrialSession(
const trialSessionHearing = TrialSessionFactory(
{
isCalendared: true,
judge: { name: 'Judge Buch' },
Expand All @@ -47,7 +47,7 @@ describe('isHearing', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
const caseToUpdate = new Case(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TrialSessionFactory } from '../trialSessions/TrialSessionFactory';
const {
applicationContext,
} = require('../../test/createTestApplicationContext');
const { Case } = require('./Case');
const { MOCK_CASE } = require('../../../test/mockCase');
const { TrialSession } = require('../trialSessions/TrialSession');

describe('removeFromHearing', () => {
it('removes the hearing from the case', () => {
const trialSessionHearing = new TrialSession(
const trialSessionHearing = TrialSessionFactory(
{
isCalendared: true,
judge: { name: 'Judge Buch' },
Expand All @@ -18,7 +18,7 @@ describe('removeFromHearing', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
const caseToUpdate = new Case(
{
Expand Down
14 changes: 7 additions & 7 deletions shared/src/business/entities/cases/Case.removeFromTrial.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TrialSessionFactory } from '../trialSessions/TrialSessionFactory';
const {
applicationContext,
} = require('../../test/createTestApplicationContext');
const { Case } = require('./Case');
const { CASE_STATUS_TYPES, CHIEF_JUDGE } = require('../EntityConstants');
const { MOCK_CASE } = require('../../../test/mockCase');
const { TrialSession } = require('../trialSessions/TrialSession');

describe('removeFromTrial', () => {
it('removes the case from trial, unsetting trial details and setting status to general docket ready for trial', () => {
Expand All @@ -16,7 +16,7 @@ describe('removeFromTrial', () => {
applicationContext,
},
);
const trialSession = new TrialSession(
const trialSession = TrialSessionFactory(
{
isCalendared: true,
judge: { name: 'Judge Buch' },
Expand All @@ -27,7 +27,7 @@ describe('removeFromTrial', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
const user = 'Petitions Clerk';

Expand Down Expand Up @@ -68,7 +68,7 @@ describe('removeFromTrial', () => {
applicationContext,
},
);
const trialSession = new TrialSession(
const trialSession = TrialSessionFactory(
{
isCalendared: true,
judge: { name: 'Judge Buch' },
Expand All @@ -79,7 +79,7 @@ describe('removeFromTrial', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
caseToUpdate.setAsCalendared(trialSession);

Expand All @@ -105,7 +105,7 @@ describe('removeFromTrial', () => {
applicationContext,
},
);
const trialSession = new TrialSession(
const trialSession = TrialSessionFactory(
{
isCalendared: true,
judge: { name: 'Judge Buch' },
Expand All @@ -116,7 +116,7 @@ describe('removeFromTrial', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
caseToUpdate.setAsCalendared(trialSession);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TrialSessionFactory } from '../trialSessions/TrialSessionFactory';
const {
applicationContext,
} = require('../../test/createTestApplicationContext');
const { Case } = require('./Case');
const { CASE_STATUS_TYPES } = require('../EntityConstants');
const { MOCK_CASE } = require('../../../test/mockCase');
const { TrialSession } = require('../trialSessions/TrialSession');

describe('removeFromTrialWithAssociatedJudge', () => {
it('removes the case from trial, updating the associated judge if one is passed in', () => {
Expand All @@ -16,7 +16,7 @@ describe('removeFromTrialWithAssociatedJudge', () => {
applicationContext,
},
);
const trialSession = new TrialSession(
const trialSession = TrialSessionFactory(
{
isCalendared: true,
judge: { name: 'Judge Buch' },
Expand All @@ -27,7 +27,7 @@ describe('removeFromTrialWithAssociatedJudge', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
caseToUpdate.setAsCalendared(trialSession);

Expand Down Expand Up @@ -56,7 +56,7 @@ describe('removeFromTrialWithAssociatedJudge', () => {
applicationContext,
},
);
const trialSession = new TrialSession(
const trialSession = TrialSessionFactory(
{
isCalendared: true,
judge: { name: 'Judge Buch' },
Expand All @@ -67,7 +67,7 @@ describe('removeFromTrialWithAssociatedJudge', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
caseToUpdate.setAsCalendared(trialSession);

Expand Down
10 changes: 5 additions & 5 deletions shared/src/business/entities/cases/Case.setAsCalendared.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TrialSessionFactory } from '../trialSessions/TrialSessionFactory';
const {
applicationContext,
} = require('../../test/createTestApplicationContext');
const { Case } = require('./Case');
const { CASE_STATUS_TYPES, CHIEF_JUDGE } = require('../EntityConstants');
const { MOCK_CASE } = require('../../../test/mockCase');
const { TrialSession } = require('../trialSessions/TrialSession');

describe('setAsCalendared', () => {
it('should set case as calendared with only judge and trialSessionId if the trial session is calendared', () => {
Expand All @@ -31,7 +31,7 @@ describe('setAsCalendared', () => {
applicationContext,
},
);
const trialSession = new TrialSession(
const trialSession = TrialSessionFactory(
{
isCalendared: true,
judge: { name: 'Judge Buch' },
Expand All @@ -42,7 +42,7 @@ describe('setAsCalendared', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
myCase.setAsCalendared(trialSession);

Expand All @@ -63,7 +63,7 @@ describe('setAsCalendared', () => {
applicationContext,
},
);
const trialSession = new TrialSession(
const trialSession = TrialSessionFactory(
{
isCalendared: false,
judge: { name: 'Judge Buch' },
Expand All @@ -74,7 +74,7 @@ describe('setAsCalendared', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
myCase.setAsCalendared(trialSession);

Expand Down
4 changes: 2 additions & 2 deletions shared/src/business/entities/cases/Case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { Petitioner } from '../contacts/Petitioner';
import { PrivatePractitioner } from '../PrivatePractitioner';
import { PublicCase } from './PublicCase';
import { Statistic } from '../Statistic';
import { TrialSession } from '../trialSessions/TrialSession';
import { TrialSessionFactory } from '../trialSessions/TrialSessionFactory';
import { UnprocessableEntityError } from '../../../errors/errors';
import { User } from '../User';
import { clone, compact, includes, isEmpty, startCase } from 'lodash';
Expand Down Expand Up @@ -862,7 +862,7 @@ export class Case extends JoiValidationEntity {
assignHearings({ applicationContext, rawCase }) {
if (Array.isArray(rawCase.hearings)) {
this.hearings = rawCase.hearings
.map(hearing => new TrialSession(hearing, { applicationContext }))
.map(hearing => TrialSessionFactory(hearing, applicationContext))
.sort((a, b) => compareStrings(a.createdAt, b.createdAt));
} else {
this.hearings = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TrialSessionFactory } from '../trialSessions/TrialSessionFactory';
const {
applicationContext,
} = require('../../test/createTestApplicationContext');
const { Case } = require('./Case');
const { CASE_STATUS_TYPES, CHIEF_JUDGE } = require('../EntityConstants');
const { MOCK_CASE } = require('../../../test/mockCase');
const { TrialSession } = require('../trialSessions/TrialSession');

describe('updateTrialSessionInformation', () => {
it('should not change the status of the case', () => {
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('updateTrialSessionInformation', () => {
applicationContext,
},
);
const trialSession = new TrialSession(
const trialSession = TrialSessionFactory(
{
isCalendared: true,
judge: { name: 'Judge Buch' },
Expand All @@ -58,7 +58,7 @@ describe('updateTrialSessionInformation', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
myCase.updateTrialSessionInformation(trialSession);

Expand All @@ -78,7 +78,7 @@ describe('updateTrialSessionInformation', () => {
applicationContext,
},
);
const trialSession = new TrialSession(
const trialSession = TrialSessionFactory(
{
isCalendared: false,
judge: { name: 'Judge Buch' },
Expand All @@ -89,7 +89,7 @@ describe('updateTrialSessionInformation', () => {
termYear: '2025',
trialLocation: 'Birmingham, Alabama',
},
{ applicationContext },
applicationContext,
);
myCase.setAsCalendared(trialSession);

Expand Down
12 changes: 12 additions & 0 deletions shared/src/business/entities/trialSessions/ClosedTrialSession.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { SESSION_STATUS_TYPES } from '../EntityConstants';
import { TrialSession } from './TrialSession';

export class ClosedTrialSession extends TrialSession {
constructor(rawSession: RawClosedTrialSession) {
super(rawSession);

this.sessionStatus = SESSION_STATUS_TYPES.closed;
}
}

export type RawClosedTrialSession = ExcludeMethods<ClosedTrialSession>;
17 changes: 14 additions & 3 deletions shared/src/business/entities/trialSessions/NewTrialSession.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { JoiValidationConstants } from '../JoiValidationConstants';
import { OpenTrialSession } from './OpenTrialSession';
import { SESSION_STATUS_TYPES } from '../EntityConstants';
import { TrialSession } from './TrialSession';
import joi from 'joi';

export class NewTrialSession extends TrialSession {
public trialClerkId: string;
public trialClerkId?: string;

constructor(rawSession: RawNewTrialSession, { applicationContext }) {
super(rawSession, { applicationContext });
super(rawSession);

this.trialClerkId = rawSession.trialClerkId;
this.trialSessionId =
rawSession.trialSessionId || applicationContext.getUniqueId();
this.sessionStatus = SESSION_STATUS_TYPES.new;
}

getErrorToMessageMap() {
Expand All @@ -21,7 +26,7 @@ export class NewTrialSession extends TrialSession {

getValidationRules() {
return {
...TrialSession.validationRules.COMMON,
...TrialSession.VALIDATION_RULES,
alternateTrialClerkName: joi.when('trialClerkId', {
is: 'Other',
otherwise: joi.optional(),
Expand All @@ -30,6 +35,12 @@ export class NewTrialSession extends TrialSession {
startDate: JoiValidationConstants.ISO_DATE.min('now').required(),
};
}

setAsCalendared(): OpenTrialSession {
this.isCalendared = true;
this.sessionStatus = SESSION_STATUS_TYPES.open;
return new OpenTrialSession(this);
}
}

export type RawNewTrialSession = ExcludeMethods<NewTrialSession>;
Loading

0 comments on commit 1a638da

Please sign in to comment.