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

feat(j-s): Send correct indictment pdf with subpoena #16353

Merged
merged 9 commits into from
Oct 11, 2024
Merged

Conversation

unakb
Copy link
Member

@unakb unakb commented Oct 10, 2024

Bæta inn caseId og 3 skjölum í fyrirkall sem er sent til RLS

What

  • Send uploaded indictment or generated indictment with subpoena depending on which one is the valid one.

Why

  • Because we need to be able to send indictments with the subpoena and we have 2 ways of storing them.

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

  • New Features

    • Introduced a method to retrieve indictment PDFs based on case types.
    • Enhanced error handling in subpoena creation and delivery processes.
  • Bug Fixes

    • Improved logging for error traceability during subpoena creation.
  • Tests

    • Added unit tests for the deliverSubpoenaToPolice method to ensure correct functionality.
    • Updated tests to incorporate the Defendant model for better validation.

Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 16 lines in your changes missing coverage. Please review.

Project coverage is 36.75%. Comparing base (ca1cc4e) to head (fe896f3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ckend/src/app/modules/subpoena/subpoena.service.ts 23.52% 13 Missing ⚠️
...ackend/src/app/modules/subpoena/subpoena.module.ts 0.00% 2 Missing ⚠️
...m/backend/src/app/modules/police/police.service.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16353      +/-   ##
==========================================
+ Coverage   36.73%   36.75%   +0.01%     
==========================================
  Files        6804     6804              
  Lines      140861   140828      -33     
  Branches    40118    40082      -36     
==========================================
+ Hits        51751    51760       +9     
+ Misses      89110    89068      -42     
Flag Coverage Δ
judicial-system-backend 55.14% <33.33%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...dules/subpoena/test/createTestingSubpoenaModule.ts 100.00% <100.00%> (ø)
...m/backend/src/app/modules/police/police.service.ts 63.39% <0.00%> (ø)
...ackend/src/app/modules/subpoena/subpoena.module.ts 0.00% <0.00%> (ø)
...ckend/src/app/modules/subpoena/subpoena.service.ts 29.87% <23.52%> (-0.78%) ⬇️

... and 37 files with indirect coverage changes


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 ca1cc4e...fe896f3. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 10, 2024

Datadog Report

Branch report: j-s/subpoena-files
Commit report: 2ea9ad8
Test service: judicial-system-backend

✅ 0 Failed, 21303 Passed, 0 Skipped, 18m 37.14s Total Time
➡️ Test Sessions change in coverage: 1 no change

@unakb unakb marked this pull request as ready for review October 10, 2024 14:33
@unakb unakb requested a review from a team as a code owner October 10, 2024 14:33
Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

Walkthrough

The pull request introduces modifications to the PoliceService, SubpoenaModule, and SubpoenaService classes, along with new unit tests for the InternalSubpoenaController. Key changes include updates to the createSubpoena method for improved error logging and handling, the addition of a new method getIndictmentPdf in the SubpoenaService, and the inclusion of a new import for FileModule in the SubpoenaModule. Additionally, unit tests are established to ensure the proper functionality of the deliverSubpoenaToPolice method.

Changes

File Change Summary
apps/judicial-system/backend/src/app/modules/police/police.service.ts Updated createSubpoena method to log defendantId as defendant?.id and enhanced error handling in the method.
apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts Added import for FileModule in SubpoenaModule using forwardRef(() => FileModule).
apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts Introduced getIndictmentPdf method, updated deliverSubpoenaToPolice to use this new method, and improved error handling for updates in the service.
apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts Added unit tests for deliverSubpoenaToPolice method in InternalSubpoenaController.
apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/getSubpoenaPdf.spec.ts Added import for Defendant model and updated test setup to include defendant object in tests for getSubpoenaPdf method.

Possibly related PRs

Suggested labels

automerge


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5b80f9b and fe896f3.

📒 Files selected for processing (2)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts (5 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.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 (6)
apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts (6)

16-16: LGTM: FileService import added correctly

The import of FileService is properly placed and follows the existing import structure. This addition aligns with the PR objective of enhancing subpoena functionality.


29-29: LGTM: FileService mock added

The FileService mock is correctly added, maintaining consistency with other service mocks in the file. This ensures isolated testing of the subpoena module.


46-46: LGTM: FileService added to providers

FileService is correctly added to the providers array, enabling proper dependency injection within the testing module. This addition is consistent with the module's structure and necessary for the enhanced functionality.


85-86: LGTM: PoliceService retrieval added

The addition of PoliceService retrieval from the module is appropriate and consistent with the retrieval of other services. This change supports the PR's objective of enhancing subpoena functionality, potentially allowing for improved interaction with police-related features.


87-88: LGTM: FileService retrieval and return added

The FileService is correctly retrieved from the module and added to the returned object. These additions are consistent with the handling of other services and make FileService available for use in tests. This change completes the integration of FileService into the testing module, supporting the PR's objective of enhancing subpoena functionality.

Also applies to: 111-112


Line range hint 1-120: Overall assessment: Changes are well-implemented and align with PR objectives

The modifications to createTestingSubpoenaModule.ts consistently integrate FileService and PoliceService into the testing module. These changes support the PR's objective of enhancing subpoena functionality, particularly in relation to sending correct indictment PDFs with subpoenas. The implementation adheres to NextJS best practices and maintains type safety. No issues or concerns were identified during this review.


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 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.

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: 2

🧹 Outside diff range and nitpick comments (4)
apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts (1)

18-18: LGTM: FileModule correctly added to module imports

The addition of forwardRef(() => FileModule) to the imports array is correct and consistent with the module's structure. This change properly incorporates the FileModule into the SubpoenaModule, adhering to NestJS best practices for module composition.

Consider adding a comment explaining the reason for using forwardRef with FileModule, especially if there are circular dependencies involved. This would improve code maintainability.

apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts (2)

17-30: LGTM: Test setup and mock data are well-structured.

The test setup and mock data creation follow Jest best practices. Using uuid ensures unique identifiers for each test run, which is excellent for test isolation.

Consider using jest.spyOn() instead of directly assigning a mock function to mockSubpoenaService.deliverSubpoenaToPolice. This approach provides more flexibility and allows for easier reset between tests if needed.


63-76: LGTM: Test case for successful subpoena delivery is well-structured.

The test case effectively verifies that the deliverSubpoenaToPolice method is called with the correct parameters when a subpoena is successfully delivered to the police. The structure is clear and follows Jest best practices.

Consider adding more test cases to cover different scenarios:

  1. Test the behavior when the deliverSubpoenaToPolice method throws an error.
  2. Verify the return value of the deliverSubpoenaToPolice method.
  3. Test with different user roles or permissions, if applicable.

These additional test cases will improve the overall test coverage and ensure the robustness of the InternalSubpoenaController.

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

688-688: Approved: Improved error logging with consistent identifier

The change from defendant?.nationalId to defendant?.id enhances error traceability by using a consistent identifier for the defendant. This aligns well with the PR objective and improves the overall robustness of the error logging system.

For consistency, consider updating the defendantId property name in the error event object to match the new identifier being used (e.g., defendantId: defendant?.id).

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between df4b50b and 5b80f9b.

📒 Files selected for processing (5)
  • apps/judicial-system/backend/src/app/modules/police/police.service.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (5 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/getSubpoenaPdf.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
apps/judicial-system/backend/src/app/modules/police/police.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/subpoena/subpoena.module.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/subpoena/subpoena.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/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.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/subpoena/test/limitedAccessSubpoenaController/getSubpoenaPdf.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."
🪛 Biome
apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts

[error] 38-38: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🔇 Additional comments (11)
apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts (1)

6-6: LGTM: FileModule import added correctly

The import of FileModule is syntactically correct and follows the established pattern for module imports in this file. This addition aligns with the PR objective of enhancing functionality related to sending indictments, which likely involves file handling.

apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/getSubpoenaPdf.spec.ts (3)

7-7: LGTM: New import enhances type safety

The addition of the Defendant import improves type safety in the test suite, which aligns with our TypeScript best practices. This change supports the PR's objective of enhancing subpoena functionality.


Line range hint 19-71: LGTM: Test updates correctly incorporate new functionality

The changes to the test setup and execution appropriately incorporate the new Defendant object and its usage in the getSubpoenaPdf method. This ensures that the new functionality is properly tested, aligning with the PR objectives.

A few observations:

  1. The defendant object is correctly typed and initialized with a subpoena.
  2. The givenWhenThen function now passes the defendant object to getSubpoenaPdf.
  3. The test case verifies that getSubpoenaPdf is called with the correct parameters, including the new defendant object.

These updates maintain the existing test structure while effectively covering the new functionality.


Line range hint 1-71: Overall assessment: Changes align well with PR objectives

The modifications to this test file effectively incorporate the Defendant model, aligning with the PR's objective of enhancing subpoena functionality. The changes are minimal and targeted, maintaining the original test structure while adding the necessary elements to test the new functionality.

Key points:

  1. The new import and usage of the Defendant model improve type safety.
  2. Test setup and execution have been updated appropriately to include the Defendant object.
  3. The changes ensure that the new functionality is properly tested without disrupting the existing test cases.

These updates contribute to the overall goal of improving the accuracy and reliability of documents sent with subpoenas.

apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts (2)

1-16: LGTM: Imports and type definitions are well-structured.

The imports and type definitions are appropriate for the test file. The Then interface and GivenWhenThen type are well-defined, providing a clear structure for error handling in the tests.


1-77: LGTM: File structure and coding guidelines are well-followed.

The overall structure of the test file adheres to NextJS best practices and Jest conventions. The use of TypeScript enhances type safety, which is crucial for maintaining a robust test suite. The file organization is clear and appropriate for a NextJS application.

Great job on maintaining consistency with the project's coding standards and best practices for testing in a NextJS environment.

🧰 Tools
🪛 Biome

[error] 38-38: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (5)

17-21: Imports are appropriate and necessary

The added imports CaseFileCategory, isTrafficViolationCase, and User are appropriate for the new functionality introduced in the code.


27-27: FileService import is correctly added

Importing FileService from '../file' is necessary for accessing file-related methods used in the service.


153-172: getIndictmentPdf method is well-implemented

The getIndictmentPdf method correctly retrieves the indictment PDF based on the case type. It handles traffic violation cases appropriately and includes error handling for cases where the indictment is not found. The use of optional chaining and type safety with TypeScript is well-applied.


187-187: Integration of getIndictmentPdf in deliverSubpoenaToPolice

The inclusion of getIndictmentPdf(theCase) in the deliverSubpoenaToPolice method enhances functionality by ensuring the correct indictment PDF is retrieved and sent. This change aligns with the overall objective of sending the correct indictment with the subpoena.


46-47: 🛠️ Refactor suggestion

Review the use of forwardRef in FileService injection

The use of forwardRef when injecting FileService suggests a potential circular dependency between SubpoenaService and FileService. Consider refactoring to eliminate the circular dependency if possible, as this can improve code maintainability and reduce complexity.

To verify if FileService depends on SubpoenaService, you can run the following script:

✅ Verification successful

Circular dependency not found. You can safely remove forwardRef from FileService injection.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if FileService imports SubpoenaService, indicating a circular dependency.

rg --type typescript 'from.*subpoena.service' src/app/modules/file

Length of output: 103


Script:

#!/bin/bash
# Description: Check if FileService imports SubpoenaService, indicating a circular dependency.

rg 'from\s+.*subpoena\.service' 'src/app/modules/file/**/*.{ts,tsx}'

Length of output: 145


Script:

#!/bin/bash
# Description: Find all FileService TypeScript files and check if they import SubpoenaService.

# Find all TypeScript files related to FileService
file_service_files=$(fd 'file\.service\.ts$' . -e ts)

# Check each FileService file for imports from SubpoenaService
for file in $file_service_files; do
    rg 'from\s+["'\''].*subpoena\.service["'\'']' "$file"
done

Length of output: 2481

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants