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): LÖKE File Upload #16732

Merged
merged 4 commits into from
Nov 8, 2024
Merged

fix(j-s): LÖKE File Upload #16732

merged 4 commits into from
Nov 8, 2024

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented Nov 5, 2024

LÖKE File Upload

Seinka hvenær þingbok og dómur er sent í LÖKE- þarf að vera með staðfestingu

What

  • Send confirmed ruling and court record to LÖKE in S-Cases.
  • Note that the files were sent at the correct time, bun an unconfirmed version was being sent.

Why

  • Verified bug.

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
    • Improved file retrieval method for case documents delivered to police.
  • Bug Fixes
    • Enhanced error handling with logging for file retrieval failures.
  • Documentation
    • Updated comments for clarity on error handling processes.

@gudjong gudjong requested a review from a team as a code owner November 5, 2024 22:57
Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes in this pull request primarily focus on the InternalCaseService class within the internalCase.service.ts file. The method for retrieving case files from S3 has been modified, replacing this.awsS3Service.getObject with this.fileService.getCaseFileFromS3. This affects the deliverIndictmentCaseToPolice and deliverAppealToPolice methods, which now include enhanced error handling that logs failures during file retrieval. Minor adjustments to comments have also been made for clarity, while the overall logic of the methods remains unchanged.

Changes

File Path Change Summary
apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts - Updated method for retrieving case files from S3.
- Enhanced error handling with logging in deliverIndictmentCaseToPolice and deliverAppealToPolice methods.
- Minor comment adjustments for clarity.
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAppealToPolice.spec.ts - Replaced AwsS3Service with FileService in tests.
- Updated method calls and mock implementations to reflect new file retrieval method.
- Adjusted object structure in tests.
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCaseToPolice.spec.ts - Replaced AwsS3Service with FileService in tests.
- Updated method calls and mock implementations to reflect new file retrieval method.
- Adjusted object structure in tests.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • unakb

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

🧹 Outside diff range and nitpick comments (2)
apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (2)

1008-1010: Consider enhancing error handling for individual file retrievals.

While there is error handling at the function level, individual file retrievals could benefit from more specific error handling to ensure proper logging and error recovery.

-          const file = await this.fileService.getCaseFileFromS3(
-            theCase,
-            caseFile,
-          )
+          try {
+            const file = await this.fileService.getCaseFileFromS3(
+              theCase,
+              caseFile,
+            )
+            return {
+              type: caseFile.category === CaseFileCategory.COURT_RECORD
+                ? PoliceDocumentType.RVTB
+                : PoliceDocumentType.RVDO,
+              courtDocument: Base64.btoa(file.toString('binary')),
+            }
+          } catch (error) {
+            this.logger.warn(
+              `Failed to retrieve file ${caseFile.id} for case ${theCase.id}`,
+              { error }
+            )
+            return null
+          }

1157-1159: Apply consistent error handling pattern for file retrievals.

Similar to the previous suggestion, implement granular error handling for individual file retrievals in the appeal delivery process.

-          const file = await this.fileService.getCaseFileFromS3(
-            theCase,
-            caseFile,
-          )
+          try {
+            const file = await this.fileService.getCaseFileFromS3(
+              theCase,
+              caseFile,
+            )
+            return {
+              type: PoliceDocumentType.RVUL,
+              courtDocument: Base64.btoa(file.toString('binary')),
+            }
+          } catch (error) {
+            this.logger.warn(
+              `Failed to retrieve appeal file ${caseFile.id} for case ${theCase.id}`,
+              { error }
+            )
+            return null
+          }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3724852 and 874854e.

📒 Files selected for processing (1)
  • apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
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."
🔇 Additional comments (1)
apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (1)

1008-1010: LGTM: File retrieval changes align with PR objectives.

The switch to using fileService.getCaseFileFromS3 provides better control over when and how files are retrieved, addressing the core issue of ensuring confirmed rulings and court records are sent at the appropriate time.

Also applies to: 1157-1159

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 5, 2024

Datadog Report

Branch report: j-s/confirmed-files-loke
Commit report: 06ec1c9
Test service: judicial-system-backend

✅ 0 Failed, 21217 Passed, 0 Skipped, 16m 1.93s Total Time
➡️ Test Sessions change in coverage: 1 no change

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

🧹 Outside diff range and nitpick comments (4)
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAppealToPolice.spec.ts (2)

70-70: Consider adding test cases for unconfirmed documents

While the test correctly handles the confirmed APPEAL_RULING case, we should also verify that unconfirmed documents are not sent to LÖKE.

Consider adding test cases for:

  • Documents with different categories
  • Cases with multiple files
  • Cases with unconfirmed rulings

Also applies to: 82-82


88-100: LGTM: Consider adding response validation

The service interaction testing is properly implemented. However, consider adding assertions to validate the structure and content of the response object beyond just the delivered flag.

Add assertions for:

expect(then.result).toEqual({
  delivered: true,
  // Add other expected properties
});
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCaseToPolice.spec.ts (2)

35-35: Consider using a more specific error message in the mock

The mock setup is well-structured, but the error message 'Some error' could be more specific to aid in debugging.

-    mockGetCaseFileFromS3.mockRejectedValue(new Error('Some error'))
+    mockGetCaseFileFromS3.mockRejectedValue(new Error('Failed to retrieve case file from S3'))

Also applies to: 43-43, 48-49


74-83: LGTM: Well-structured case file objects

The case file objects are well-structured and properly typed. Consider adding a brief comment explaining what each case file represents in the test context.

+    // Test case files representing court record and ruling documents
     const caseFile1 = {
       id: uuid(),
       key: uuid(),
       category: CaseFileCategory.COURT_RECORD,
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 874854e and 9d973b9.

📒 Files selected for processing (2)
  • apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAppealToPolice.spec.ts (4 hunks)
  • apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCaseToPolice.spec.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAppealToPolice.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/test/internalCaseController/deliverIndictmentCaseToPolice.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."
📓 Learnings (1)
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAppealToPolice.spec.ts (1)
Learnt from: gudjong
PR: island-is/island.is#16389
File: apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCaseFilesRecordPdfRolesRules.spec.ts:1-1
Timestamp: 2024-10-17T11:30:12.482Z
Learning: The usage of `defenderRule` in the following test files is intentional and should remain unchanged:

- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createPresignedPostRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/deleteCaseFileRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createCaseFileRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/getCaseFileSignedUrlRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getRulingPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getRequestPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCourtRecordPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getByIdRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getAllFilesZipRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/caseController/getAllRolesRules.spec.ts`
🔇 Additional comments (4)
apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAppealToPolice.spec.ts (2)

16-16: LGTM: Service transition implemented correctly

The switch from AwsS3Service to FileService is properly implemented in the test setup, maintaining consistency with the service layer changes.

Also applies to: 32-32, 37-42


43-44: Verify error handling coverage

The error handling setup looks good, but let's verify that we're testing all potential error scenarios from FileService.

✅ Verification successful

Error handling coverage is appropriate

The error handling in the test is sufficient as it covers the main error path from getCaseFileFromS3. Looking at the implementation:

  1. The test mocks getCaseFileFromS3 to reject with a generic error, which is appropriate since this method can throw errors from:

    • AWS S3 service calls
    • File verification checks
    • Document confirmation process
  2. The error propagation is handled at the controller level, which is the correct architectural approach.

  3. Other test files (deliverIndictmentToPolice.spec.ts, deliverIndictmentCaseToPolice.spec.ts) follow the same error handling pattern, showing consistency across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other error handling scenarios in FileService
ast-grep --pattern 'getCaseFileFromS3($_) {
  $$$
  throw new $_($_)
  $$$
}'

Length of output: 79


Script:

#!/bin/bash
# Let's first find the FileService implementation
fd "FileService" --type f

# Then examine its content and error handling
rg -A 5 "getCaseFileFromS3" 

Length of output: 12948


Script:

#!/bin/bash
# Let's examine the implementation of FileService and its error handling
cat apps/judicial-system/backend/src/app/modules/file/file.service.ts

Length of output: 17143

apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCaseToPolice.spec.ts (2)

16-16: LGTM: FileService import added correctly

The import statement for FileService is properly added, aligning with the service replacement changes.


92-92: Verify test coverage for error scenarios

The happy path testing is well implemented. However, we should verify that error scenarios are properly covered, especially since this PR fixes a bug related to document transmission timing.

Let's check if there are other test files covering error scenarios:

Also applies to: 98-101, 110-116

Copy link

codecov bot commented Nov 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.55%. Comparing base (30a0e38) to head (26db107).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16732      +/-   ##
==========================================
- Coverage   36.55%   36.55%   -0.01%     
==========================================
  Files        6892     6892              
  Lines      143767   143630     -137     
  Branches    40964    40919      -45     
==========================================
- Hits        52557    52504      -53     
+ Misses      91210    91126      -84     
Flag Coverage Δ
judicial-system-backend 55.22% <100.00%> (ø)

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

Files with missing lines Coverage Δ
...ckend/src/app/modules/case/internalCase.service.ts 85.12% <100.00%> (ø)

... and 53 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 30a0e38...26db107. Read the comment docs.

@oddsson oddsson added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 7, 2024
@kodiakhq kodiakhq bot merged commit 3445c32 into main Nov 8, 2024
30 checks passed
@kodiakhq kodiakhq bot deleted the j-s/confirmed-files-loke branch November 8, 2024 09:57
jonnigs pushed a commit that referenced this pull request Nov 12, 2024
* Fix loke file upload

* Updates unit tests

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Ívar Oddsson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants