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): Subpoena PDF #16098

Merged
merged 5 commits into from
Sep 24, 2024
Merged

feat(j-s): Subpoena PDF #16098

merged 5 commits into from
Sep 24, 2024

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented Sep 20, 2024

Subpoena PDF

Sýna fyrirkallið á yfirliti máls hjá ákæranda

What

  • Shows subpoenas on overviews for prosecution and defence.

Why

  • They should have access to the subpoenas.

Screenshots / Gifs

image

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

    • Introduced a new method to retrieve subpoena PDFs for defendants, enhancing access to case-related documents.
    • Added a new controller specifically for handling limited access defendant requests.
    • Implemented role-based access control for additional user roles within the defendant controller.
    • Enhanced the Indictment Case Files List with new UI elements for displaying and downloading subpoena PDFs.
  • Bug Fixes

    • Minor formatting adjustments for improved code readability.
  • Documentation

    • Updated message definitions for better clarity in the user interface.

@gudjong gudjong requested a review from a team as a code owner September 20, 2024 12:52
Copy link
Contributor

coderabbitai bot commented Sep 20, 2024

Walkthrough

The changes introduce a new method getSubpoenaPdf in the LimitedAccessFileController to handle requests for subpoena PDFs, enhancing the judicial system's functionality. Additionally, a new LimitedAccessDefendantController is created to manage related requests, while role-based access control is expanded in the DefendantController. Minor formatting adjustments are made in the LimitedAccessCaseController, and new strings for UI elements related to subpoenas are added in the web components.

Changes

File Change Summary
.../limitedAccessFile.controller.ts Added method getSubpoenaPdf to handle GET requests for subpoena PDFs, updated type imports.
.../limitedAccessCase.controller.ts Removed a blank line between property declarations for formatting.
.../defendant/defendant.controller.ts Introduced three new role-based access control rules: prosecutorRule, prosecutorRepresentativeRule, and publicProsecutorStaffRule.
.../defendant/defendant.module.ts Added new controller LimitedAccessDefendantController to the module.
.../defendant/limitedAccessDefendant.controller.ts Created LimitedAccessDefendantController to handle GET requests for subpoena PDFs, including security guards and a method getSubpoenaPdf.
.../IndictmentCaseFilesList/IndictmentCaseFilesList.strings.ts Added new message definitions for subpoenaTitle and subpoenaButtonText.
.../IndictmentCaseFilesList/IndictmentCaseFilesList.tsx Introduced conditional rendering for subpoena PDFs based on workingCase properties, including new buttons for downloading PDFs.

Possibly related PRs

Suggested reviewers

  • unakb

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 63864c5 and 95e6633.

Files selected for processing (1)
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts

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

Outside diff range and nitpick comments (3)
apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (1)

Line range hint 75-279: Approve the changes with a suggestion for refactoring.

The changes introduce a new section for displaying subpoena-related information based on the presence of an arraignment date and defendants in the workingCase. The rendering logic is clear and the PdfButton components are configured correctly to enable accessing subpoena PDFs for each defendant.

Consider extracting the rendering logic for the subpoena section into a separate component for better readability and maintainability. This will help keep the IndictmentCaseFilesList component focused on its primary responsibility and make the code easier to understand and modify in the future.

For example, you can create a new component called SubpoenaSection and move the rendering logic there:

interface SubpoenaSectionProps {
  workingCase: Case
}

const SubpoenaSection: FC<SubpoenaSectionProps> = ({ workingCase }) => {
  const { formatMessage } = useIntl()

  return (
    <Box marginBottom={5}>
      <Text variant="h4" as="h4" marginBottom={1}>
        {formatMessage(strings.subpoenaTitle)}
      </Text>
      {workingCase.defendants.map((defendant) => (
        <Box marginBottom={2} key={`subpoena-${workingCase.id}`}>
          <PdfButton
            caseId={workingCase.id}
            title={formatMessage(strings.subpoenaButtonText, {
              name: defendant.name,
            })}
            pdfType="subpoena"
            elementId={defendant.id}
            renderAs="row"
          />
        </Box>
      ))}
    </Box>
  )
}

Then, you can use the SubpoenaSection component in the IndictmentCaseFilesList component like this:

{showSubpoenaPdf && workingCase.defendants && workingCase.defendants.length > 0 && (
  <SubpoenaSection workingCase={workingCase} />
)}

This refactoring will make the code more modular and easier to maintain.

apps/judicial-system/backend/src/app/modules/defendant/limitedAccessDefendant.controller.ts (2)

56-56: Set Content-Disposition Header for PDF Response

To ensure that the PDF is correctly handled by the client, consider setting the Content-Disposition header. This informs the browser how to display the PDF, either inline or as an attachment.

Apply this diff to add the header:

  @Get()
  @Header('Content-Type', 'application/pdf')
+ @Header('Content-Disposition', 'inline; filename="subpoena.pdf"')
  @ApiOkResponse({
    content: { 'application/pdf': {} },
    description: 'Gets the subpoena for a given defendant as a pdf document',
  })

61-84: Add Unit Tests for getSubpoenaPdf Method

Currently, there are no unit tests provided for the getSubpoenaPdf method. Implementing unit tests will ensure that the method functions as expected and will help catch future regressions.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e977e91 and c485565.

Files selected for processing (7)
  • apps/judicial-system/api/src/app/modules/file/limitedAccessFile.controller.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.controller.ts (0 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.controller.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/limitedAccessDefendant.controller.ts (1 hunks)
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.strings.ts (1 hunks)
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (2 hunks)
Files not reviewed due to no reviewable changes (1)
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.controller.ts
Additional context used
Path-based instructions (6)
apps/judicial-system/api/src/app/modules/file/limitedAccessFile.controller.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/defendant/defendant.controller.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/defendant/defendant.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/defendant/limitedAccessDefendant.controller.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/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.strings.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/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (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 not posted (8)
apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts (2)

15-15: LGTM!

The import statement for the new LimitedAccessDefendantController is correctly added, following the proper syntax and naming convention.


27-27: Verify the impact of the new controller on the API endpoints.

The LimitedAccessDefendantController is correctly added to the DefendantModule. This addition is expected to introduce new endpoints or modify existing ones related to limited access for defendants.

Please run the following script to verify the impact on the API endpoints:

apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.strings.ts (2)

31-36: LGTM!

The new message definition for subpoenaTitle follows the expected structure and conventions. The message ID, default message, and description are appropriate for the intended usage.


37-42: Looks good!

The new message definition for subpoenaButtonText is structured correctly and follows the established conventions. The message ID, default message with the {name} placeholder, and description are suitable for the intended purpose of generating the text for a PDF button to download the subpoena.

apps/judicial-system/backend/src/app/modules/defendant/defendant.controller.ts (1)

159-161: LGTM!

The addition of the new roles prosecutorRule, prosecutorRepresentativeRule, and publicProsecutorStaffRule to the @RolesRules decorator for the getSubpoenaPdf method is a positive change. It expands the role-based access control, allowing the prosecution side to access the subpoena PDF, which aligns with the PR objective of improving transparency and accessibility of subpoenas for both prosecution and defense.

apps/judicial-system/backend/src/app/modules/defendant/limitedAccessDefendant.controller.ts (1)

54-54: Verify Role-Based Access Control Configuration

The @RolesRules(defenderRule) decorator applies the defenderRule to this route. Ensure that this rule accurately reflects the intended access permissions for defenders accessing subpoenas. Additionally, confirm that the defenderRule is correctly defined and imported.

Run the following script to verify the defenderRule definition:

Verification successful

Verification Successful: Role-Based Access Control Correctly Configured

The defenderRule is correctly defined in the guards module as UserRole.DEFENDER and is consistently imported and used across various controllers, including the limitedAccessDefendant.controller.ts file. The rule accurately reflects the intended access permissions for defenders, and its usage is verified in multiple test files.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that defenderRule is correctly defined and used.

# Test: Search for the definition of defenderRule.
# Expect: The defenderRule should be defined with appropriate permissions.
rg --type ts --files-with-matches 'defenderRule' | xargs rg 'defenderRule'

Length of output: 6168

apps/judicial-system/api/src/app/modules/file/limitedAccessFile.controller.ts (2)

9-9: Import of Query is appropriate

The added import of Query from @nestjs/common is necessary for handling query parameters in the new method.


23-23: Import of SubpoenaType is appropriate

Including SubpoenaType in the import statement ensures type safety for the subpoenaType query parameter.

Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 71.79487% with 11 lines in your changes missing coverage. Please review.

Project coverage is 36.65%. Comparing base (00ad0d4) to head (95e6633).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...c/app/modules/file/limitedAccessFile.controller.ts 0.00% 6 Missing ⚠️
...ndictmentCaseFilesList/IndictmentCaseFilesList.tsx 33.33% 4 Missing ⚠️
...kend/src/app/modules/defendant/defendant.module.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16098      +/-   ##
==========================================
- Coverage   36.71%   36.65%   -0.07%     
==========================================
  Files        6761     6749      -12     
  Lines      139082   138772     -310     
  Branches    39504    39446      -58     
==========================================
- Hits        51059    50860     -199     
+ Misses      88023    87912     -111     
Flag Coverage Δ
judicial-system-api 18.57% <0.00%> (-0.04%) ⬇️
judicial-system-backend 54.86% <96.29%> (+0.05%) ⬆️
judicial-system-web 28.57% <33.33%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
...c/app/modules/case/limitedAccessCase.controller.ts 97.60% <ø> (ø)
.../src/app/modules/defendant/defendant.controller.ts 97.95% <ø> (ø)
...les/defendant/limitedAccessDefendant.controller.ts 100.00% <100.00%> (ø)
...les/defendant/test/createTestingDefendantModule.ts 100.00% <100.00%> (ø)
...ntCaseFilesList/IndictmentCaseFilesList.strings.ts 100.00% <ø> (ø)
...kend/src/app/modules/defendant/defendant.module.ts 0.00% <0.00%> (ø)
...ndictmentCaseFilesList/IndictmentCaseFilesList.tsx 67.53% <33.33%> (-2.90%) ⬇️
...c/app/modules/file/limitedAccessFile.controller.ts 0.00% <0.00%> (ø)

... and 42 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 00ad0d4...95e6633. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 20, 2024

Datadog Report

All test runs feb1f52 🔗

9 Total Test Services: 0 Failed, 9 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.02%), 1 increased (+0.05%), 10 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
judicial-system-api 0 0 0 57 0 6.12s 1 decreased (-0.02%) Link
judicial-system-backend 0 0 0 21154 0 19m 2.07s 1 increased (+0.05%) Link
judicial-system-formatters 0 0 0 38 0 5.16s 1 no change Link
judicial-system-message 0 0 0 32 0 10.81s 1 no change Link
judicial-system-message-handler 0 0 0 4 0 3.45s 1 no change Link
judicial-system-scheduler 0 0 0 4 0 4.17s 1 no change Link
judicial-system-types 0 0 0 23 0 7.27s 1 no change Link
judicial-system-web 0 0 0 338 0 1m 6.12s 1 no change Link
judicial-system-xrd-api 0 0 0 6 0 5.09s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • judicial-system-api - jest 19.73% (-0.02%) - Details

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

Outside diff range and nitpick comments (7)
apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/defendantControllerGuards.spec.ts (1)

13-16: Improved test structure and readability.

The changes to this test case are well-implemented:

  1. The test name is now more descriptive and accurately reflects its purpose.
  2. The test structure has been simplified, combining assertions for both guards into a single, concise test case.
  3. The new implementation is more readable and maintains the same level of test coverage.

These improvements align well with best practices for writing clear and maintainable tests.

Consider adding the following assertions to further enhance the test coverage:

expect(guards[0]).toBe(JwtAuthGuard);
expect(guards[1]).toBe(RolesGuard);

This would ensure that the guards are applied in the correct order, which can be important for proper authentication and authorization flow.

apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/getSubpoenaPdfRolesRules.spec.ts (2)

15-18: LGTM: Test case is concise and verifies the correct permissions.

The test case effectively checks that there's only one rule for accessing the subpoena PDF and that it matches the defenderRule. This ensures that only the defender role has the necessary permissions.

Consider adding a more descriptive test name to clarify the exact permission being tested:

-  it('should give permission to roles', () => {
+  it('should give permission only to the defender role', () => {

1-19: LGTM: Overall structure follows best practices.

The test file is well-structured, following NextJS and TypeScript best practices. It uses Jest effectively and focuses on a single responsibility. The use of Reflect.getMetadata suggests a clean, decorator-based approach for defining role rules.

To improve robustness, consider adding a test case to verify the behavior when no rules are present:

it('should handle case with no rules', () => {
  // Mock Reflect.getMetadata to return undefined or an empty array
  jest.spyOn(Reflect, 'getMetadata').mockReturnValueOnce([]);
  
  const noRules = Reflect.getMetadata(
    'roles-rules',
    LimitedAccessDefendantController.prototype.getSubpoenaPdf,
  );
  
  expect(noRules).toHaveLength(0);
});

This additional test would ensure that the system behaves correctly even when no rules are defined.

apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/limitedAccessDefendantControllerGuards.spec.ts (1)

16-27: Test case is comprehensive and well-structured.

The test case thoroughly verifies the guard configuration for the LimitedAccessDefendantController. It checks both the number of guards and their specific types, which is excellent. The assertions are clear and follow good practices for unit testing.

One minor suggestion for improvement:

Consider extracting the expected guard types into an array or object at the beginning of the test. This would make the test more maintainable and easier to update if the guard configuration changes in the future. For example:

it('should have the right guard configuration', () => {
  const expectedGuards = [
    { type: JwtAuthGuard },
    { type: RolesGuard },
    { type: CaseExistsGuard },
    { type: CaseTypeGuard, config: { allowedCaseTypes: indictmentCases } },
    { type: CaseReadGuard },
    { type: DefendantExistsGuard }
  ];

  expect(guards).toHaveLength(expectedGuards.length);
  
  expectedGuards.forEach((expected, index) => {
    if ('config' in expected) {
      expect(guards[index]).toBeInstanceOf(expected.type);
      expect(guards[index]).toEqual(expected.config);
    } else {
      expect(new guards[index]()).toBeInstanceOf(expected.type);
    }
  });
});

This approach makes the test more declarative and easier to maintain.

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

15-31: LGTM: Test suite setup is well-structured.

The test suite setup follows Jest best practices, using beforeEach to set up the testing environment and mock data. The use of uuid for generating unique identifiers is appropriate.

Consider extracting the mock data creation (lines 16-20) into a separate function for better readability and reusability. For example:

function createMockData() {
  const caseId = uuid();
  const defendantId = uuid();
  return {
    caseId,
    defendantId,
    defendant: { id: defendantId } as Defendant,
    theCase: { id: caseId } as Case,
    res: { end: jest.fn() } as unknown as Response,
  };
}

Then, you can use it in your describe block:

describe('LimitedAccessDefendantController - Get subpoena pdf', () => {
  const { caseId, defendantId, defendant, theCase, res } = createMockData();
  // ... rest of the code
});

33-50: LGTM: givenWhenThen function is well-implemented.

The givenWhenThen function follows the Given-When-Then pattern, which enhances readability and maintainability. The error handling and asynchronous implementation are appropriate for testing asynchronous operations.

Consider adding a result property to the Then interface to capture the successful result of the operation. This would allow for more comprehensive testing of both success and error scenarios. For example:

interface Then {
  error?: Error;
  result?: any; // Or a more specific type if known
}

// In the givenWhenThen function:
const then: Then = {};
try {
  then.result = await limitedAccessDefendantController.getSubpoenaPdf(
    caseId,
    defendantId,
    theCase,
    defendant,
    res,
  );
} catch (error) {
  then.error = error as Error;
}

This change would allow for more flexible assertions in your test cases.


52-68: LGTM with suggestions: Test case is well-structured but could be expanded.

The test case is clear and follows Jest best practices. The assertions appropriately verify the expected behavior of the getSubpoenaPdf method.

To improve test coverage and robustness, consider adding the following test cases:

  1. Test error handling:

    it('should handle errors when generating PDF', async () => {
      const error = new Error('PDF generation failed');
      mockPdfService.getSubpoenaPdf.mockRejectedValueOnce(error);
      const { error: thrownError } = await givenWhenThen();
      expect(thrownError).toEqual(error);
    });
  2. Test with different input parameters:

    it('should call getSubpoenaPdf with correct parameters including optional ones', async () => {
      const additionalParams = {
        param1: 'value1',
        param2: 'value2',
        param3: 'value3',
      };
      await limitedAccessDefendantController.getSubpoenaPdf(
        caseId,
        defendantId,
        theCase,
        defendant,
        res,
        additionalParams.param1,
        additionalParams.param2,
        additionalParams.param3
      );
      expect(mockPdfService.getSubpoenaPdf).toHaveBeenCalledWith(
        theCase,
        defendant,
        additionalParams.param1,
        additionalParams.param2,
        additionalParams.param3
      );
    });

These additional test cases will help ensure that the getSubpoenaPdf method handles various scenarios correctly, including error cases and different input parameters.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c485565 and 63864c5.

Files selected for processing (9)
  • apps/judicial-system/backend/src/app/modules/defendant/test/createTestingDefendantModule.ts (4 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/defendantControllerGuards.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/getSubpoenaPdfGuards.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/getSubpoenaPdfRolesRules.spec.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/getSubpoenaPdf.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/getSubpoenaPdfRolesRules.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/limitedAccessDefendantControllerGuards.spec.ts (1 hunks)
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.strings.ts (1 hunks)
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (2 hunks)
Files skipped from review due to trivial changes (1)
  • apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/getSubpoenaPdfGuards.spec.ts
Files skipped from review as they are similar to previous changes (2)
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.strings.ts
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx
Additional context used
Path-based instructions (6)
apps/judicial-system/backend/src/app/modules/defendant/test/createTestingDefendantModule.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/defendant/test/defendantController/defendantControllerGuards.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/defendant/test/defendantController/getSubpoenaPdfRolesRules.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/defendant/test/limitedAccessDefendantController/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."
apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/getSubpoenaPdfRolesRules.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/defendant/test/limitedAccessDefendantController/limitedAccessDefendantControllerGuards.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."
Additional comments not posted (12)
apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/getSubpoenaPdfRolesRules.spec.ts (1)

1-13: LGTM: Imports and test setup are well-structured.

The imports are appropriate for the test, and the describe block clearly outlines the purpose of the test suite. The setup in the beforeEach block correctly retrieves the metadata for the getSubpoenaPdf method.

apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/getSubpoenaPdfRolesRules.spec.ts (4)

5-7: LGTM: New role imports added correctly

The new role imports (prosecutorRepresentativeRule, prosecutorRule, and publicProsecutorStaffRule) are correctly added and follow the existing naming conventions. They are also appropriately grouped with similar imports, maintaining good code organization.


11-11: Improved test description accuracy

The test description has been updated to correctly reflect the DefendantController and specify the functionality being tested (custody notice pdf rules). This change enhances the clarity and accuracy of the test suite.


23-26: LGTM: Updated expectations and new role checks

The test has been appropriately updated to reflect the addition of new roles:

  1. The expected length of rules has been correctly increased to 6.
  2. New role checks for prosecutorRule, prosecutorRepresentativeRule, and publicProsecutorStaffRule have been added.

These changes improve the comprehensiveness of the test and maintain consistency with the newly imported rules.


Line range hint 1-31: Overall assessment: Well-implemented changes

The changes in this file are well-implemented and consistent with the PR objectives. The test suite has been updated to include new roles and improve its accuracy. The modifications adhere to TypeScript best practices and maintain good code organization. No issues or concerns were identified during this review.

apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/limitedAccessDefendantControllerGuards.spec.ts (2)

1-6: Imports look good and follow best practices.

The imports are well-organized, grouped by external and internal modules, and all seem relevant to the test file's purpose.


1-28: Overall, excellent test implementation with minor improvement opportunities.

This test file for the LimitedAccessDefendantController guard configuration is well-structured and comprehensive. It effectively verifies the number and types of guards applied to the controller. The test follows good practices for unit testing in a TypeScript/Jest environment.

While the implementation is solid, there are a few minor opportunities for improvement:

  1. Enhancing type safety in the test setup.
  2. Improving the maintainability of the test case by extracting expected guard configurations.

These suggestions aim to make the tests more robust and easier to maintain in the long run. Great job on implementing thorough tests for this critical part of the application!

apps/judicial-system/backend/src/app/modules/defendant/test/limitedAccessDefendantController/getSubpoenaPdf.spec.ts (1)

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

The imports are appropriate for the test file, and the custom Then interface and GivenWhenThen type are well-defined, following TypeScript best practices.

apps/judicial-system/backend/src/app/modules/defendant/test/createTestingDefendantModule.ts (4)

19-19: LGTM: Import statement for LimitedAccessDefendantController

The import statement for LimitedAccessDefendantController is correctly added and follows the existing import style in the file. This addition aligns with the PR objectives of enhancing defendant data access control.


31-35: LGTM: LimitedAccessDefendantController added to testing module

The LimitedAccessDefendantController is correctly added to the controllers array in the testing module configuration. This ensures that the new controller is included in the testing setup, maintaining comprehensive test coverage for the defendant module.


89-92: LGTM: LimitedAccessDefendantController instance added to module exports

The LimitedAccessDefendantController instance is correctly retrieved from the module and added to the returned object. This follows the established pattern in the file and ensures that the new controller is available for testing. The naming convention is consistent with other controller instances.

Also applies to: 105-105


Line range hint 1-107: Overall assessment: Changes successfully integrate LimitedAccessDefendantController

The modifications to createTestingDefendantModule.ts effectively incorporate the new LimitedAccessDefendantController into the testing setup. These changes align with the PR objectives of enhancing defendant data access control and maintain consistency with existing code structure and NextJS/NestJS best practices. The new controller is properly imported, added to the module configuration, and made available for testing, ensuring comprehensive test coverage for the defendant module.

@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Sep 24, 2024
@kodiakhq kodiakhq bot merged commit 737d9b3 into main Sep 24, 2024
34 checks passed
@kodiakhq kodiakhq bot deleted the j-s/indictment-case-files-subpoena branch September 24, 2024 22:19
thoreyjona pushed a commit that referenced this pull request Oct 2, 2024
* Shows subpoenas to prosecution, defence and riksak

* Updates unit tests

* Fixes key issue

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Oct 21, 2024
6 tasks
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