Skip to content

Commit

Permalink
fix(j-s): Rovot Indictment Subject (#15343)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and snaerseljan committed Jul 2, 2024
1 parent 6de12da commit 9e4efea
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ export class InternalCaseService {
.updateIndictmentCaseWithIndictmentInfo(
user,
theCase.id,
theCase.court?.name,
theCase.courtCaseNumber,
theCase.eventLogs?.find(
(eventLog) => eventLog.eventType === EventType.CASE_RECEIVED_BY_COURT,
Expand Down Expand Up @@ -624,9 +625,10 @@ export class InternalCaseService {
user: TUser,
): Promise<DeliverResponse> {
return this.courtService
.updateIndictmentWithDefenderInfo(
.updateIndictmentCaseWithDefenderInfo(
user,
theCase.id,
theCase.court?.name,
theCase.courtCaseNumber,
theCase.defendants,
)
Expand Down Expand Up @@ -663,6 +665,7 @@ export class InternalCaseService {
.updateIndictmentCaseWithAssignedRoles(
user,
theCase.id,
theCase.court?.name,
theCase.courtCaseNumber,
assignedRole,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ type GivenWhenThen = (
describe('InternalCaseController - Deliver assigned roles for indictment case to court', () => {
const user = { id: uuid() } as User
const caseId = uuid()
const courtName = uuid()
const courtCaseNumber = uuid()

const theCase = {
id: caseId,
type: CaseType.INDICTMENT,
court: { name: courtName },
courtCaseNumber,
judge: { name: 'Test Dómari', nationalId: '0101010101' },
registrar: { name: 'Test Ritari', nationalId: '0202020202' },
Expand Down Expand Up @@ -75,7 +77,7 @@ describe('InternalCaseController - Deliver assigned roles for indictment case to
it('should deliver the assigned roles to the court', () => {
expect(
mockCourtService.updateIndictmentCaseWithAssignedRoles,
).toHaveBeenCalledWith(user, theCase.id, theCase.courtCaseNumber, {
).toHaveBeenCalledWith(user, caseId, courtName, courtCaseNumber, {
name: theCase.judge?.name,
role: UserRole.DISTRICT_COURT_JUDGE,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ type GivenWhenThen = (
describe('InternalCaseController - Deliver indictment defender info to court', () => {
const user = { id: uuid() } as User
const caseId = uuid()
const courtName = uuid()
const courtCaseNumber = uuid()

const theCase = {
id: caseId,
type: CaseType.INDICTMENT,
court: { name: courtName },
courtCaseNumber,
defendants: [
{
Expand Down Expand Up @@ -55,7 +57,9 @@ describe('InternalCaseController - Deliver indictment defender info to court', (
await createTestingCaseModule()

mockCourtService = courtService as jest.Mocked<CourtService>
mockCourtService.updateIndictmentWithDefenderInfo.mockResolvedValue(uuid())
mockCourtService.updateIndictmentCaseWithDefenderInfo.mockResolvedValue(
uuid(),
)

givenWhenThen = async (caseId: string, theCase: Case, body: DeliverDto) => {
const then = {} as Then
Expand All @@ -73,11 +77,12 @@ describe('InternalCaseController - Deliver indictment defender info to court', (
const then = await givenWhenThen(caseId, theCase, { user })

expect(
mockCourtService.updateIndictmentWithDefenderInfo,
mockCourtService.updateIndictmentCaseWithDefenderInfo,
).toHaveBeenCalledWith(
user,
theCase.id,
theCase.courtCaseNumber,
caseId,
courtName,
courtCaseNumber,
theCase.defendants,
)

Expand All @@ -87,7 +92,7 @@ describe('InternalCaseController - Deliver indictment defender info to court', (

it('should handle not deliver if error occurs', async () => {
const error = new Error('Service error')
mockCourtService.updateIndictmentWithDefenderInfo.mockRejectedValueOnce(
mockCourtService.updateIndictmentCaseWithDefenderInfo.mockRejectedValueOnce(
error,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type GivenWhenThen = (
describe('InternalCaseController - Deliver indictment info to court', () => {
const user = { id: uuid() } as User
const caseId = uuid()
const courtName = uuid()
const policeCaseNumber = uuid()
const policeCaseNumber2 = uuid()
const courtCaseNumber = uuid()
Expand All @@ -46,6 +47,7 @@ describe('InternalCaseController - Deliver indictment info to court', () => {
],
[policeCaseNumber2]: [IndictmentSubtype.THEFT],
},
court: { name: courtName },
courtCaseNumber,
eventLogs: [
{ eventType: EventType.CASE_RECEIVED_BY_COURT, created: receivedDate },
Expand Down Expand Up @@ -91,8 +93,9 @@ describe('InternalCaseController - Deliver indictment info to court', () => {
mockCourtService.updateIndictmentCaseWithIndictmentInfo,
).toHaveBeenCalledWith(
user,
theCase.id,
theCase.courtCaseNumber,
caseId,
courtName,
courtCaseNumber,
receivedDate,
indictmentDate,
policeCaseNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ export class CourtService {
async updateIndictmentCaseWithIndictmentInfo(
user: User,
caseId: string,
courtName?: string,
courtCaseNumber?: string,
receivedByCourtDate?: Date,
indictmentDate?: Date,
Expand All @@ -571,7 +572,7 @@ export class CourtService {
prosecutor?: { name?: string; nationalId?: string },
): Promise<unknown> {
try {
const subject = `Ákæra - ${courtCaseNumber} - upplýsingar`
const subject = `${courtName} - ${courtCaseNumber} - upplýsingar`
const content = JSON.stringify({
receivedByCourtDate,
indictmentDate,
Expand Down Expand Up @@ -606,9 +607,10 @@ export class CourtService {
}
}

async updateIndictmentWithDefenderInfo(
async updateIndictmentCaseWithDefenderInfo(
user: User,
caseId: string,
courtName?: string,
courtCaseNumber?: string,
defendants?: Defendant[],
): Promise<unknown> {
Expand All @@ -619,7 +621,7 @@ export class CourtService {
defenderEmail: defendant.defenderEmail,
}))

const subject = `Ákæra - ${courtCaseNumber} - verjanda upplýsingar`
const subject = `${courtName} - ${courtCaseNumber} - verjanda upplýsingar`
const content = JSON.stringify(defendantInfo)

return this.sendToRobot(
Expand Down Expand Up @@ -647,11 +649,12 @@ export class CourtService {
async updateIndictmentCaseWithAssignedRoles(
user: User,
caseId: string,
courtName?: string,
courtCaseNumber?: string,
assignedRole?: { name?: string; role?: UserRole },
): Promise<unknown> {
try {
const subject = `Ákæra - ${courtCaseNumber} - úthlutun`
const subject = `${courtName} - ${courtCaseNumber} - úthlutun`
const content = JSON.stringify(assignedRole)

return this.sendToRobot(
Expand Down Expand Up @@ -856,7 +859,7 @@ export class CourtService {
.then((log) => [log.id, log.seqNumber])
}

async sendToRobot(
private async sendToRobot(
subject: string,
content: string,
type: RobotEmailType,
Expand Down

0 comments on commit 9e4efea

Please sign in to comment.