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 a function to get indictment deadline date #17583

Merged
merged 24 commits into from
Jan 27, 2025

Conversation

thorhildurt
Copy link
Member

@thorhildurt thorhildurt commented Jan 21, 2025

Áfrýjunarfrestur miðist við miðnætti síðasta dags

What

  • Fixing the case appeal deadlines to be set at midnight on the deadline date.
  • Extracting this logic into a seperate functions including tests to avoid repeadtly implementing the deadline setting, including tests for that functionality.

Why

  • The deadline is not working as expected, they want it to be the number of days and including the whole day.

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 new utility functions for calculating appeal deadlines.
    • Enhanced date handling for judicial system cases.
  • Refactor

    • Centralized appeal deadline calculation logic.
    • Simplified date-related utility functions.
    • Improved clarity of GraphQL schema with additional field descriptions.
  • Bug Fixes

    • Improved precision of appeal deadline calculations.
    • Standardized end-of-day deadline settings.
  • Chores

    • Cleaned up unused imports and constants.
    • Removed legacy date utility functions.

@thorhildurt thorhildurt requested a review from a team as a code owner January 21, 2025 10:52
Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Walkthrough

This pull request introduces comprehensive changes to the judicial system's appeal deadline calculation and handling. The modifications primarily focus on centralizing and standardizing the logic for determining appeal deadlines across multiple components and modules. Key changes include introducing new utility functions like getAppealDeadlineDate, getIndictmentAppealDeadlineDate, and hasDatePassed, removing deprecated constants, and updating the calculation of appeal deadlines in various files to use these new functions. Additionally, test cases have been adjusted to reflect these changes.

Changes

File Change Summary
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.spec.ts Updated test cases for transformCase and getAppealInfo functions, fixing expected outputs to static dates.
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts Refactored appeal deadline logic, added new utility functions, and modified return structures in getIndictmentInfo.
apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx Replaced appeal expiration date calculation method with getIndictmentAppealDeadlineDate.
apps/judicial-system/web/src/utils/utils.spec.tsx Removed getAppealEndDate test suite and associated imports.
apps/judicial-system/web/src/utils/utils.ts Deleted getAppealEndDate function and related imports.
libs/judicial-system/types/src/index.ts Updated exports, removed constants, and added new date-related functions.
libs/judicial-system/types/src/lib/dates.spec.ts Added test suite for getIndictmentAppealDeadlineDate, getAppealDeadlineDate, and hasDatePassed functions.
libs/judicial-system/types/src/lib/dates.ts Introduced new utility functions for date handling and appeal deadline calculations.
libs/judicial-system/types/src/lib/indictmentCase.ts Removed date-related constants, updated logic for calculating appeal deadline status.
apps/judicial-system/api/src/app/modules/case/models/case.model.ts Enhanced GraphQL field definitions for appealDeadline and indictmentAppealDeadline with descriptions.

Possibly related PRs

Suggested Labels

automerge

Suggested Reviewers

  • unakb
  • thorhildurt

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 701b4a2 and 69d5831.

📒 Files selected for processing (1)
  • libs/judicial-system/types/src/lib/indictmentCase.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/judicial-system/types/src/lib/indictmentCase.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: prepare

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.

@thorhildurt thorhildurt self-assigned this Jan 21, 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: 1

🧹 Nitpick comments (4)
libs/judicial-system/types/src/lib/dates.ts (1)

3-4: Consider making appeal window constants configurable.

These constants might need to be adjusted based on different jurisdictions or future policy changes.

Consider moving these to a configuration file or environment variables for easier maintenance.

libs/judicial-system/types/src/lib/dates.spec.ts (2)

4-14: Add edge case tests for fine appeal deadline.

While the happy path is tested, consider adding tests for:

  • Null/undefined baseDate
  • Past dates
  • Date at start vs end of day

16-26: Add edge case tests for verdict appeal deadline.

Similar to fine appeal tests, consider adding edge cases:

  • Leap year handling
  • Month boundary transitions
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts (1)

209-216: Consider adding type safety for date handling

While the implementation is correct, we could improve type safety for the date handling.

- const baseDate = serviceRequired ? verdictViewDate : theCase.rulingDate
+ const baseDateString = serviceRequired ? verdictViewDate : theCase.rulingDate
+ const baseDate = baseDateString ? new Date(baseDateString) : undefined
  const verdictAppealDeadline = baseDate
-   ? getAppealDeadlineDate({ baseDate: new Date(baseDate), isFine })
+   ? getAppealDeadlineDate({ baseDate, isFine })
    : undefined
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5f81d55 and cac9f57.

📒 Files selected for processing (9)
  • apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.spec.ts (5 hunks)
  • apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts (6 hunks)
  • apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx (2 hunks)
  • apps/judicial-system/web/src/utils/utils.spec.tsx (1 hunks)
  • apps/judicial-system/web/src/utils/utils.ts (0 hunks)
  • libs/judicial-system/types/src/index.ts (1 hunks)
  • libs/judicial-system/types/src/lib/dates.spec.ts (1 hunks)
  • libs/judicial-system/types/src/lib/dates.ts (1 hunks)
  • libs/judicial-system/types/src/lib/indictmentCase.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • apps/judicial-system/web/src/utils/utils.ts
🧰 Additional context used
📓 Path-based instructions (8)
apps/judicial-system/web/src/utils/utils.spec.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."
libs/judicial-system/types/src/lib/dates.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.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."
libs/judicial-system/types/src/lib/indictmentCase.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/judicial-system/types/src/lib/dates.spec.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.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/api/src/app/modules/case/interceptors/case.transformer.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."
libs/judicial-system/types/src/index.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
📓 Learnings (1)
apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx (1)
Learnt from: oddsson
PR: island-is/island.is#16495
File: apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx:102-103
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In the TypeScript file `apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx`, within the `handleSetDate` function, the else block is intentionally kept to handle an unlikely scenario and should not be removed, even if it appears unnecessary due to prior validation checks.
🔇 Additional comments (11)
libs/judicial-system/types/src/lib/dates.ts (3)

6-6: LGTM! Well-defined utility function.

The setEndOfDay function is correctly typed and handles millisecond precision.


10-22: LGTM! Well-structured and type-safe implementation.

The function is:

  • Properly typed with TypeScript
  • Uses named parameters for clarity
  • Handles both fine and verdict cases

8-8: Consider timezone handling in date comparison.

The Date.now() comparison might be affected by timezone differences.

Consider using a date library's comparison function or explicitly handling timezones:

-export const hasDatePassed = (deadline: Date) => Date.now() > deadline.getTime()
+export const hasDatePassed = (deadline: Date) => {
+  const now = new Date()
+  return now.getTime() > deadline.getTime()
+}
libs/judicial-system/types/src/lib/indictmentCase.ts (1)

1-1: LGTM! Clean integration of new date utilities.

Good refactoring to use the new date utilities, improving code maintainability.

Also applies to: 35-40

libs/judicial-system/types/src/index.ts (1)

105-107: LGTM! Export structure supports tree-shaking.

The granular exports allow for effective tree-shaking in consuming applications.

apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts (3)

1-4: Clean import additions!

The new utility functions for date handling are properly imported.


127-127: Good use of centralized date validation!

The hasDatePassed function is consistently used for date validation, improving code maintainability.

Also applies to: 132-132


Line range hint 161-195: Clean refactoring of indictment info!

The changes improve code readability through:

  • Early return for missing ruling date
  • Consistent use of the new date utility function
  • Clear object property structure
apps/judicial-system/web/src/utils/utils.spec.tsx (1)

12-12: Clean removal of deprecated test dependencies!

The import statement has been correctly updated to remove the reference to the deprecated getAppealEndDate function.

apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx (1)

143-146: Good use of the new date utility function!

The appeal deadline calculation has been properly updated to use the centralized utility function.

apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.spec.ts (1)

346-346: Test expectations properly updated!

The test cases have been correctly updated to expect appeal deadlines at the end of the day (23:59:59.999), aligning with the PR objective.

Also applies to: 386-386, 463-463, 482-482, 587-587

@datadog-island-is
Copy link

datadog-island-is bot commented Jan 21, 2025

Datadog Report

All test runs 3bcc325 🔗

10 Total Test Services: 0 Failed, 10 Passed
🔻 Test Sessions change in coverage: 5 decreased, 4 increased, 191 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-backend 0 0 0 63 0 29.47s N/A Link
air-discount-scheme-web 0 0 0 2 0 6.07s N/A Link
api 0 0 0 4 0 2.32s N/A Link
api-catalogue-services 0 0 0 23 0 8.23s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 15.74s N/A Link
api-domains-assets 0 0 0 3 0 9.03s N/A Link
api-domains-auth-admin 0 0 0 18 0 8.76s N/A Link
api-domains-communications 0 0 0 5 0 31.41s N/A Link
api-domains-criminal-record 0 0 0 5 0 8.2s N/A Link
api-domains-driving-license 0 0 0 23 0 28.9s N/A Link

🔻 Code Coverage Decreases vs Default Branch (5)

  • judicial-system-formatters - jest 87.09% (-0.41%) - Details
  • judicial-system-scheduler - jest 76.44% (-0.21%) - Details
  • judicial-system-xrd-api - jest 74.3% (-0.16%) - Details
  • license-api - jest 34.11% (-0.02%) - Details
  • judicial-system-web - jest 32.45% (-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: 2

🧹 Nitpick comments (3)
libs/judicial-system/types/src/lib/dates.ts (2)

10-10: Consider adding null check for improved type safety.

While the implementation is correct, consider adding a null check to handle potential undefined dates more gracefully.

-export const hasDatePassed = (deadline: Date) => Date.now() > deadline.getTime()
+export const hasDatePassed = (deadline: Date | null | undefined): boolean => 
+  deadline ? Date.now() > deadline.getTime() : false

26-29: Consider reducing code duplication with getIndictmentAppealDeadlineDate.

The function could reuse logic from getIndictmentAppealDeadlineDate to maintain consistency and reduce duplication.

-export const getAppealDeadlineDate = ({ baseDate }: { baseDate: Date }) => {
-  const deadlineDate = addDays(baseDate, APPEAL_WINDOW_DAYS)
-  return setEndOfDay(deadlineDate)
-}
+export const getAppealDeadlineDate = ({ baseDate }: { baseDate: Date }) => 
+  getIndictmentAppealDeadlineDate({ baseDate, isFine: true })
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts (1)

Line range hint 161-195: Consider using early return pattern more consistently.

The implementation could be more concise by using the early return pattern consistently.

 export const getIndictmentInfo = (
   rulingDecision?: CaseIndictmentRulingDecision,
   rulingDate?: string,
   defendants?: Defendant[],
   eventLog?: EventLog[],
 ): IndictmentInfo => {
+  if (!rulingDate) return {}
+
   const isFine = rulingDecision === CaseIndictmentRulingDecision.FINE
   const isRuling = rulingDecision === CaseIndictmentRulingDecision.RULING
-
-  if (!rulingDate) {
-    return {}
-  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cac9f57 and 91397b4.

📒 Files selected for processing (6)
  • apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts (6 hunks)
  • apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx (2 hunks)
  • libs/judicial-system/types/src/index.ts (1 hunks)
  • libs/judicial-system/types/src/lib/dates.spec.ts (1 hunks)
  • libs/judicial-system/types/src/lib/dates.ts (1 hunks)
  • libs/judicial-system/types/src/lib/indictmentCase.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • libs/judicial-system/types/src/lib/indictmentCase.ts
  • libs/judicial-system/types/src/index.ts
🧰 Additional context used
📓 Path-based instructions (4)
libs/judicial-system/types/src/lib/dates.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/judicial-system/types/src/lib/dates.spec.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.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."
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.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/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx (1)
Learnt from: oddsson
PR: island-is/island.is#16495
File: apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx:102-103
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In the TypeScript file `apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx`, within the `handleSetDate` function, the else block is intentionally kept to handle an unlikely scenario and should not be removed, even if it appears unnecessary due to prior validation checks.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: prepare
🔇 Additional comments (4)
libs/judicial-system/types/src/lib/dates.ts (2)

1-8: LGTM! Well-defined constants and utility function.

The appeal window constants are clearly defined, and the setEndOfDay utility function correctly sets the time to the end of day with millisecond precision.


12-24: LGTM! Correctly implements appeal deadline calculation.

The function properly:

  • Selects the appropriate appeal window based on case type
  • Sets the deadline to end of day, meeting the PR objective of ensuring deadlines encompass the entire day
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts (2)

99-101: Previous review feedback about isFine parameter remains relevant.

A past review identified that the isFine parameter should be determined based on case type or ruling decision.


127-132: LGTM! Proper date validation implementation.

The code correctly uses the new hasDatePassed utility to validate dates.

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/api/src/app/modules/case/models/case.model.ts (2)

355-358: Enhance the field description with format details.

The description should specify the date format and timezone to ensure consistent interpretation across the application.

   @Field(() => String, {
     nullable: true,
-    description: 'appeal deadline in R cases',
+    description: 'Appeal deadline in R cases (ISO 8601 format in UTC, e.g., YYYY-MM-DDT23:59:59Z)',
   })

436-439: Enhance the field description with format details.

The description should specify the date format and timezone to ensure consistent interpretation across the application.

   @Field(() => String, {
     nullable: true,
-    description: 'appeal deadline for public prosecutor',
+    description: 'Appeal deadline for public prosecutor (ISO 8601 format in UTC, e.g., YYYY-MM-DDT23:59:59Z)',
   })
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 91397b4 and 2d1a460.

📒 Files selected for processing (1)
  • apps/judicial-system/api/src/app/modules/case/models/case.model.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/api/src/app/modules/case/models/case.model.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."
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: prepare

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 (3)
libs/judicial-system/types/src/lib/dates.spec.ts (3)

7-31: Add edge cases to strengthen test coverage.

While the current tests are well-structured using the AAA pattern, consider adding these edge cases:

  • Month transitions (e.g., Jan 31 → Feb)
  • Year transitions (e.g., Dec 31 → Jan)
  • Non-leap years for February dates
test('should handle month transition correctly', () => {
  const baseDate = new Date(2024, 0, 31) // Jan 31
  const isFine = false
  const actualDate = getIndictmentAppealDeadlineDate({ baseDate, isFine })
  expect(actualDate).toStrictEqual(new Date(2024, 1, 28, 23, 59, 59, 999))
})

test('should handle year transition correctly', () => {
  const baseDate = new Date(2024, 11, 31) // Dec 31
  const isFine = true
  const actualDate = getIndictmentAppealDeadlineDate({ baseDate, isFine })
  expect(actualDate).toStrictEqual(new Date(2025, 0, 3, 23, 59, 59, 999))
})

33-44: Add similar edge cases for getAppealDeadlineDate.

The test suite would benefit from the same edge cases as suggested for getIndictmentAppealDeadlineDate.

test('should handle month transition correctly', () => {
  const baseDate = new Date(2024, 0, 31) // Jan 31
  const actualDate = getAppealDeadlineDate({ baseDate })
  expect(actualDate).toStrictEqual(new Date(2024, 1, 3, 23, 59, 59, 999))
})

test('should handle year transition correctly', () => {
  const baseDate = new Date(2024, 11, 31) // Dec 31
  const actualDate = getAppealDeadlineDate({ baseDate })
  expect(actualDate).toStrictEqual(new Date(2025, 0, 3, 23, 59, 59, 999))
})

46-67: Add edge cases for same-day comparison and timezone handling.

The current tests cover basic past/future scenarios, but consider adding:

  1. Same-day comparison at different times
  2. Timezone edge cases
test('should handle same-day comparison correctly', () => {
  const mockNow = new Date(2024, 0, 1, 12, 0) // noon
  const sameDay = new Date(2024, 0, 1, 23, 59) // end of day
  
  jest.useFakeTimers().setSystemTime(mockNow)
  expect(hasDatePassed(sameDay)).toBe(false)
})

test('should handle timezone transitions correctly', () => {
  // Mock a specific timezone for consistent testing
  const mockDate = new Date('2024-01-01T00:00:00Z') // UTC midnight
  const dateToCheck = new Date('2024-01-01T23:59:59Z') // UTC end of day
  
  jest.useFakeTimers().setSystemTime(mockDate)
  expect(hasDatePassed(dateToCheck)).toBe(false)
})
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2d1a460 and 245ffed.

📒 Files selected for processing (1)
  • libs/judicial-system/types/src/lib/dates.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/judicial-system/types/src/lib/dates.spec.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (2)
libs/judicial-system/types/src/lib/dates.spec.ts (2)

1-6: LGTM! Clean and focused imports.

The imports are well-organized and only include the necessary functions being tested.


1-67: Well-structured test suite that aligns with requirements!

The implementation effectively validates that:

  • Appeal deadlines are correctly set to end of day (23:59:59.999)
  • TypeScript types are properly used
  • Functions are reusable across the codebase

The test structure follows best practices with clear arrange-act-assert patterns.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 245ffed and c193073.

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

1-5: LGTM! Good job centralizing the deadline calculation logic.

The imported utility functions help standardize deadline calculations across the codebase, improving maintainability.


99-102: LGTM! Standardized appeal deadline calculation.

The use of getAppealDeadlineDate ensures consistent deadline calculation across the codebase.


130-136: LGTM! Consistent date comparison logic.

Good use of the hasDatePassed utility function for standardized date comparisons.


168-171: LGTM! Standardized indictment appeal deadline calculation.

Good use of getIndictmentAppealDeadlineDate with proper parameters.


193-198: LGTM! Clean and clear return structure.

The direct object return improves code readability.


212-218: LGTM! Consistent deadline handling for defendants.

Good use of utility functions for standardized deadline calculations and date comparisons.

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

♻️ Duplicate comments (1)
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts (1)

99-101: ⚠️ Potential issue

Add missing isFine parameter to getAppealDeadlineDate call.

The appeal deadline calculation might be incorrect as it's missing the isFine parameter which determines the deadline period.

  appealInfo.appealDeadline = getAppealDeadlineDate({
    baseDate: theRulingDate,
+   isFine: theCase.type === 'FINE' || theCase.indictmentRulingDecision === 'FINE',
  }).toISOString()
🧹 Nitpick comments (2)
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts (2)

Line range hint 161-195: Enhance type safety for indictment info.

While the implementation is correct, consider adding runtime type checks for the optional parameters to improve type safety.

  export const getIndictmentInfo = (
    rulingDecision?: CaseIndictmentRulingDecision,
    rulingDate?: string,
    defendants?: Defendant[],
    eventLog?: EventLog[],
  ): IndictmentInfo => {
+   if (rulingDate && !Date.parse(rulingDate)) {
+     throw new Error('Invalid ruling date format')
+   }
    // ... rest of the implementation
  }

209-219: Add error handling for invalid dates in verdict appeal deadline calculation.

Consider adding error handling for invalid date values to prevent runtime errors.

    const baseDate = serviceRequired ? verdictViewDate : theCase.rulingDate
+   if (baseDate && !Date.parse(baseDate)) {
+     throw new Error('Invalid base date for verdict appeal deadline calculation')
+   }
    const verdictAppealDeadline = baseDate
      ? getIndictmentAppealDeadlineDate({
          baseDate: new Date(baseDate),
          isFine,
        })
      : undefined
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c193073 and 9777093.

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

1-5: LGTM! Well-structured imports.

The imports follow TypeScript best practices with clear separation of concerns by importing utility functions from the types package.


127-132: LGTM! Improved date validation.

Good use of the centralized hasDatePassed utility for consistent date validation across the codebase.

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 91.42857% with 3 lines in your changes missing coverage. Please review.

Project coverage is 35.56%. Comparing base (fa5f883) to head (69d5831).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...stem/api/src/app/modules/case/models/case.model.ts 0.00% 2 Missing ⚠️
...src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17583   +/-   ##
=======================================
  Coverage   35.56%   35.56%           
=======================================
  Files        7033     7031    -2     
  Lines      150624   150698   +74     
  Branches    43023    43020    -3     
=======================================
+ Hits        53562    53600   +38     
- Misses      97062    97098   +36     
Flag Coverage Δ
judicial-system-api 20.25% <94.11%> (+0.18%) ⬆️
judicial-system-backend 55.79% <59.09%> (-0.01%) ⬇️
judicial-system-formatters 78.45% <59.09%> (-0.42%) ⬇️
judicial-system-message 66.16% <ø> (ø)
judicial-system-message-handler 47.72% <ø> (ø)
judicial-system-scheduler 70.94% <59.09%> (-0.26%) ⬇️
judicial-system-types 38.80% <81.81%> (+1.03%) ⬆️
judicial-system-web 27.95% <37.50%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
.../app/modules/case/interceptors/case.transformer.ts 100.00% <100.00%> (ø)
apps/judicial-system/web/src/utils/utils.ts 61.11% <ø> (-1.56%) ⬇️
libs/judicial-system/types/src/index.ts 100.00% <100.00%> (ø)
libs/judicial-system/types/src/lib/dates.ts 100.00% <100.00%> (ø)
...bs/judicial-system/types/src/lib/indictmentCase.ts 100.00% <100.00%> (ø)
...src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx 58.69% <0.00%> (ø)
...stem/api/src/app/modules/case/models/case.model.ts 0.00% <0.00%> (ø)

... and 60 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 fa5f883...69d5831. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Jan 24, 2025

Datadog Report

All test runs fa6acae 🔗

9 Total Test Services: 0 Failed, 9 Passed
🔻 Test Sessions change in coverage: 4 decreased, 2 increased, 6 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 61 0 6.06s 1 increased (+0.23%) Link
judicial-system-backend 0 0 0 21156 0 12m 38.61s 1 no change Link
judicial-system-formatters 0 0 0 40 0 5.29s 1 decreased (-0.41%) Link
judicial-system-message 0 0 0 41 0 10.31s 1 no change Link
judicial-system-message-handler 0 0 0 4 0 3.2s 1 no change Link
judicial-system-scheduler 0 0 0 4 0 3.72s 1 decreased (-0.21%) Link
judicial-system-types 0 0 0 28 0 6.58s 1 increased (+0.88%) Link
judicial-system-web 0 0 0 332 0 57.22s 1 decreased (-0.02%) Link
judicial-system-xrd-api 0 0 0 6 0 4.8s 1 decreased (-0.16%) Link

🔻 Code Coverage Decreases vs Default Branch (4)

  • judicial-system-formatters - jest 87.09% (-0.41%) - Details
  • judicial-system-scheduler - jest 76.4% (-0.21%) - Details
  • judicial-system-xrd-api - jest 74.26% (-0.16%) - Details
  • judicial-system-web - jest 32.45% (-0.02%) - Details

@oddsson oddsson added this pull request to the merge queue Jan 27, 2025
Merged via the queue into main with commit 1d49089 Jan 27, 2025
39 checks passed
@oddsson oddsson deleted the j-s/fixAppealDeadline branch January 27, 2025 08:45
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