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

chore(j-s): add police case numbers to revoke indictment notification email #17385

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

thorhildurt
Copy link
Member

@thorhildurt thorhildurt commented Jan 2, 2025

What

  • Asana task
  • Instead of sending "...ákæru í máli sem ekki hefur enn fengið málsnúmer" we want to add the policeCaseNumbers as stated in the task description

Why

  • To add more context to what case is being revoked

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced case notification system with improved message formatting.
    • Added support for including police case numbers in court notifications.
  • Bug Fixes

    • Corrected a typo in method name for revoke notifications.
    • Improved handling of case number references in notifications.
  • Improvements

    • More detailed and precise messaging for indictment cancellation notices.
    • Better information display when court case number is not available.

@thorhildurt thorhildurt requested a review from a team as a code owner January 2, 2025 12:18
Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request focuses on enhancing the notification system for judicial cases, specifically improving how indictment cancellation notices are handled. The changes primarily involve modifying message templates, updating service methods, and refining how case numbers are referenced in notifications. The modifications aim to provide more precise and informative messaging when a court revokes an indictment, incorporating police case numbers when a court case number is not available.

Changes

File Change Summary
apps/judicial-system/backend/src/app/messages/notifications.ts Updated courtRevokedIndictmentEmail message body to include policeCaseNumbers when court case number is not available.
apps/judicial-system/backend/src/app/modules/case/case.service.ts Added withCourtCaseNumber: false for cases in WAITING_FOR_CANCELLATION state.
apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts Introduced policeCaseNumbers variable in deliverIndictmentCancellationNoticeToCourt method.
apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts Renamed sendRevodeNotificationsForIndictmentCase to sendRevokeNotificationsForIndictmentCase, updated notification methods to include police case numbers.
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRevokedNotifications.spec.ts Added policeCaseNumbers to theCase object in test for notification sending.
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCancellationNoticeToCourt.spec.ts Updated test to reflect changes in notification structure including police case numbers.

Sequence Diagram

sequenceDiagram
    participant Case
    participant CaseService
    participant NotificationService
    participant Court

    Case->>CaseService: Request indictment cancellation
    CaseService->>NotificationService: Prepare notification
    NotificationService->>NotificationService: Generate message with police case numbers
    NotificationService->>Court: Send revocation notice
Loading

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • oddsson

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -860,6 +860,7 @@ export class CaseService {
type: MessageType.DELIVERY_TO_COURT_INDICTMENT_CANCELLATION_NOTICE,
user,
caseId: theCase.id,
// Q: Why do we have to pass this flag? Why can't we rely on the court case numbers not being defined on the case object?
Copy link
Member Author

@thorhildurt thorhildurt Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question targeting the flag withCourtCaseNumber, which is set to false when CaseState.WAITING_FOR_CANCELLATION is true and I am curious to understand why we can´t simply check if the the case number field is undefined 👀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a little confusing, I'll try to explain 😄

Basically the requirement here was to send an exact copy of the e-mail that gets sent to the court when a prosecutor asks for cancellation. If a prosecutor could only ask for cancellation after the court sets a court case number, then we wouldn't need this. But we have cases where :

  1. Prosecutor creates case and sends to court
  2. Prosecutor wants to cancel case, so he asks for cancellation
  3. Email of cancellation is sent to the courts (with the text not including the court case number as it hasn't been set by the court yet)
  4. When the court opens said case, they get a modal which tells them the case has been cancelled, and in this modal they set the court case number and close the case (to store the info in Auður)
  5. Once they have set a court case number, a number of deliveries get pushed to the queue, including the cancellation notice
  6. Cancellation notice is picked up from the queue. At this point, the case actually does have a court case number, but we want to send the text that was without the court case number to the robot (so that it matches the email sent to the court)

We can discuss further offline if you want, it's quite a specific piece of logic that isn't easy to infer from just the code, maybe we should add a comment or something

@thorhildurt thorhildurt changed the title J s/show police case numbers in email chore(j-s): add police case numbers to revoke indictment notification email Jan 2, 2025
@thorhildurt thorhildurt self-assigned this Jan 2, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCancellationNoticeToCourt.spec.ts (1)

112-112: Consider enumerating all police case numbers
Right now, the test code references hardcoded policeCase1 and policeCase2 within the string. If you add more police case numbers later, you'll need to update this manually. You could dynamically join the array within the string for scalability.

- `${prosecutorsOffice} hefur afturkallað ákæru í máli ${policeCase1}, ${policeCase2}...`
+ const joinedCaseNumbers = policeCaseNumbers.join(', ')
+ `${prosecutorsOffice} hefur afturkallað ákæru í máli ${joinedCaseNumbers}...`
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 029015c and eeab192.

📒 Files selected for processing (5)
  • apps/judicial-system/backend/src/app/messages/notifications.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCancellationNoticeToCourt.spec.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCancellationNoticeToCourt.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/messages/notifications.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/case.service.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
📓 Learnings (3)
apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (1)
Learnt from: gudjong
PR: island-is/island.is#15393
File: apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts:28-28
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The `DeliverCancellationNoticeDto` import in `apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts` is used in the `deliverIndictmentCancellationNoticeToCourt` method.
apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts (1)
Learnt from: gudjong
PR: island-is/island.is#16452
File: apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts:1845-1854
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In the `sendCaseFilesUpdatedNotifications` method within `internalNotification.service.ts`, when the `user` is a defence user, it is intended to send notifications to the prosecutor.
apps/judicial-system/backend/src/app/modules/case/case.service.ts (1)
Learnt from: gudjong
PR: island-is/island.is#15393
File: apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts:691-711
Timestamp: 2024-11-12T15:15:20.158Z
Learning: The `deliverIndictmentCancellationNoticeToCourt` method in `InternalCaseService` returns `{ delivered: false }` in case of an exception, as error handling is managed by a message queue handler.
🔇 Additional comments (16)
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCancellationNoticeToCourt.spec.ts (3)

28-30: Use descriptive variable naming or a shared fixture for test data
It's good to see police case numbers explicitly declared, but consider adding a comment or using shared fixtures to clarify the context of these test constants.


39-39: Nice addition of policeCaseNumbers to the case object
This clearly associates the new data with the test scenario.


96-96: Good descriptive test name
Renaming the test to focus on police case numbers makes the purpose clearer.

apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (6)

Line range hint 28-30: Clarify intent of hardcoded test data
Same comment as in your spec file–the test constants are clear, but might be more maintainable if grouped in common test data utilities.


Line range hint 31-31: Explicitly grouping police case numbers
Bundling the two variables into one array is a good way to pass them around as a collection.


Line range hint 39-39: Adding policeCaseNumbers
Looks solid. Ensure all references handle an empty array scenario correctly.


675-678: Verify empty or large arrays
Joining the police case numbers with “, ” works fine when there's at least one item. Ensure it behaves as expected if the array is empty or has more than two items.


686-686: Passing courtCaseNumber
This code paths into the format function seamlessly. No issues found.


693-694: Inserting placeholders
The placeholders for courtCaseNumber and policeCaseNumbers are consistent with the new email template.

apps/judicial-system/backend/src/app/messages/notifications.ts (1)

842-842: Graceful fallback to policeCaseNumbers
The updated select statement elegantly handles the scenario where no court case number is provided. Great use of fallback placeholders.

apps/judicial-system/backend/src/app/modules/case/case.service.ts (1)

863-863: Confirm correct usage of withCourtCaseNumber: false
When the state is WAITING_FOR_CANCELLATION, we explicitly disable the court case number usage. Verify that no scenario requires the actual courtCaseNumber in the subsequent logic.

apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts (5)

1442-1444: Consider handling empty arrays gracefully.
Assigning a default 'NONE' to courtCaseNumber is fine. However, for policeCaseNumbers.join(', '), ensure there's no unexpected behavior if policeCaseNumbers is empty. Either handle an empty array scenario or confirm such a case cannot occur.


1448-1448: No issues found.
This reference to courtCaseNumber aligns with the variable defined above.


1455-1456: Check for user clarity with appended police case numbers.
Including courtCaseNumber and policeCaseNumbers in the email template is a good addition. Consider verifying that these values render properly, especially when courtCaseNumber is 'NONE'.


1463-1463: Good fix of the method name typo.
Renaming sendRevodeNotificationsForIndictmentCase to sendRevokeNotificationsForIndictmentCase improves code readability and flow.


1541-1541: Method call consistency.
This change to call sendRevokeNotificationsForIndictmentCase appropriately reflects the corrected method name, ensuring consistency.

@datadog-island-is
Copy link

datadog-island-is bot commented Jan 2, 2025

Datadog Report

Branch report: j-s/show-police-case-numbers-in-email
Commit report: 358e30b
Test service: judicial-system-backend

✅ 0 Failed, 21072 Passed, 0 Skipped, 18m 14s Total Time
⬆️ Test Sessions change in coverage: 1 increased (+0.01%)

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.68%. Comparing base (029015c) to head (ef5f516).
Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17385   +/-   ##
=======================================
  Coverage   35.68%   35.68%           
=======================================
  Files        6931     6931           
  Lines      148786   148786           
  Branches    42510    42508    -2     
=======================================
  Hits        53092    53092           
  Misses      95694    95694           
Flag Coverage Δ
judicial-system-backend 55.98% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...l-system/backend/src/app/messages/notifications.ts 100.00% <ø> (ø)
...ystem/backend/src/app/modules/case/case.service.ts 89.51% <ø> (ø)
...ckend/src/app/modules/case/internalCase.service.ts 84.04% <100.00%> (ø)
...vices/caseNotification/caseNotification.service.ts 79.51% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 029015c...ef5f516. Read the comment docs.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRevokedNotifications.spec.ts (1)

38-39: Add tests for multiple police case numbers.

Currently, the array only contains a single police case number. Consider adding covering test scenarios for multiple police case numbers or an empty array scenario to ensure broader coverage and robustness.

apps/judicial-system/backend/src/app/messages/notifications.ts (1)

840-842: Manage multiple police case numbers gracefully.

When courtCaseNumber is NONE, the template displays {policeCaseNumbers}. For multiple case numbers in an array, consider a format that clearly separates them (e.g., comma-separated). This will enrich the clarity of the notification and match user expectations.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eeab192 and ef5f516.

📒 Files selected for processing (2)
  • apps/judicial-system/backend/src/app/messages/notifications.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRevokedNotifications.spec.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRevokedNotifications.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/messages/notifications.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (1)
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRevokedNotifications.spec.ts (1)

54-54: Confirm consistent parameter usage.

This addition to theCase aligns well with the rest of the code. Ensure that all references in other modules (e.g., services, controllers) expect or handle this new policeCaseNumbers field appropriately.

@@ -672,23 +672,26 @@ export class InternalCaseService {
): Promise<DeliverResponse> {
await this.refreshFormatMessage()

const courtCaseNumber =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider simplifying this so that the message just takes in a single variable called caseNumber or something along those lines, and then you can just send it straight in since there are no other changes to the string except which case number(s) are getting sent in.

The string in notifications.ts could then simply be

'{prosecutorsOffice} hefur afturkallað ákæru í máli {caseNumber}.',

where the caseNumber is decided with a const here depending on whether or not withCourtCaseNumber is true/false and the courtCaseNumber is set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants