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

fix(j-s): Rovot Indictment Subject #15343

Merged
merged 2 commits into from
Jun 26, 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
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
Loading