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(service-portal-health): small refactor #14939

Merged
merged 3 commits into from
May 30, 2024
Merged

Conversation

thorkellmani
Copy link
Member

@thorkellmani thorkellmani commented May 27, 2024

What

  • Bit of streamlining

Why

  • More predictable output

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

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

    • Added a message for users without health insurance: "Síðasta trygging: {arg}".
  • Bug Fixes

    • Improved handling of insurance data, ensuring consistent return types and default values.
  • Refactor

    • Removed unnecessary Inject import to streamline code.

Copy link
Contributor

coderabbitai bot commented May 27, 2024

Walkthrough

The recent updates focus on refining the InsuranceOverview model and related services within the rights-portal module. Key changes include making the from property mandatory and the status property nullable. The getInsuranceOverview method now consistently returns an InsuranceOverview object with improved handling of missing data. Additionally, a new health insurance message was added to the service portal's messages file.

Changes

Files Change Summary
libs/api/domains/rights-portal/src/lib/overview/models/insuranceOverview.model.ts Made from property non-nullable and changed status property to nullable.
libs/api/domains/rights-portal/src/lib/overview/overview.resolver.ts Removed the Inject import from @nestjs/common.
libs/api/domains/rights-portal/src/lib/overview/overview.service.ts Ensured getInsuranceOverview returns a Promise of InsuranceOverview with consistent handling of missing data.
libs/service-portal/health/src/lib/messages.ts Added a new message noHealthInsuranceMessage with id sp.health:no-health-insurance-message.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

codecov bot commented May 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 37.02%. Comparing base (5452a2c) to head (126f9f8).
Report is 2 commits behind head on main.

Current head 126f9f8 differs from pull request most recent head f6bebbb

Please upload reports for the commit f6bebbb to get more accurate results.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #14939      +/-   ##
==========================================
- Coverage   37.12%   37.02%   -0.10%     
==========================================
  Files        6390     6385       -5     
  Lines      130064   129777     -287     
  Branches    37107    37024      -83     
==========================================
- Hits        48282    48054     -228     
+ Misses      81782    81723      -59     
Flag Coverage Δ
api 3.46% <ø> (ø)
application-system-api 41.98% <ø> (+0.01%) ⬆️
application-template-api-modules 24.26% <ø> (+0.01%) ⬆️
application-templates-inheritance-report 3.96% <ø> (-0.26%) ⬇️
application-templates-marriage-conditions 10.07% <ø> (ø)
application-ui-shell 21.70% <ø> (-0.03%) ⬇️

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

Files Coverage Δ
libs/service-portal/health/src/lib/messages.ts 0.00% <ø> (ø)

... and 129 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 c4f12fb...f6bebbb. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented May 27, 2024

Datadog Report

All test runs 794c08a 🔗

2 Total Test Services: 0 Failed, 1 Passed
➡️ Test Sessions change in coverage: 3 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.43s 1 no change Link
service-portal-health 0 0 0 0 0 1.11s 1 no change Link

@thorkellmani thorkellmani marked this pull request as ready for review May 29, 2024 08:49
@thorkellmani thorkellmani requested a review from a team as a code owner May 29, 2024 08:49
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)
libs/api/domains/rights-portal/src/lib/overview/overview.resolver.ts (2)

Line range hint 36-36: Remove or correct the misplaced decorators.

- @FeatureFlag(Features.servicePortalHealthRightsModule)
- @FeatureFlag(Features.servicePortalHealthOverviewPage)

Also applies to: 47-47


Line range hint 16-17: Imports used only as types should be imported using import type.

- import { User } from '@island.is/auth-nest-tools'
+ import type { User } from '@island.is/auth-nest-tools'
libs/api/domains/rights-portal/src/lib/overview/overview.service.ts (2)

Line range hint 16-16: Correct the usage of decorators if they are misplaced.

- @Inject(LOGGER_PROVIDER)

Line range hint 1-2: Imports used only as types should be imported using import type.

- import { Inject, Injectable } from '@nestjs/common'
+ import type { Inject } from '@nestjs/common'
+ import { Injectable } from '@nestjs/common'
- import { Auth, AuthMiddleware, User } from '@island.is/auth-nest-tools'
+ import type { Auth, User } from '@island.is/auth-nest-tools'
+ import { AuthMiddleware } from '@island.is/auth-nest-tools'

Also applies to: 2-3, 4-5, 5-6

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 40a0f43 and 58b46d7.
Files selected for processing (4)
  • libs/api/domains/rights-portal/src/lib/overview/models/insuranceOverview.model.ts (1 hunks)
  • libs/api/domains/rights-portal/src/lib/overview/overview.resolver.ts (1 hunks)
  • libs/api/domains/rights-portal/src/lib/overview/overview.service.ts (3 hunks)
  • libs/service-portal/health/src/lib/messages.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • libs/service-portal/health/src/lib/messages.ts
Additional Context Used
Biome (8)
libs/api/domains/rights-portal/src/lib/overview/overview.resolver.ts (3)

36-36: Decorators are not valid here.


47-47: Decorators are not valid here.


16-17: All these imports are only used as types.

libs/api/domains/rights-portal/src/lib/overview/overview.service.ts (5)

16-16: Decorators are not valid here.


1-2: All these imports are only used as types.


2-3: Some named imports are only used as types.


4-5: All these imports are only used as types.


5-6: All these imports are only used as types.

Path-based Instructions (3)
libs/api/domains/rights-portal/src/lib/overview/models/insuranceOverview.model.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/api/domains/rights-portal/src/lib/overview/overview.resolver.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/api/domains/rights-portal/src/lib/overview/overview.service.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 not posted (6)
libs/api/domains/rights-portal/src/lib/overview/models/insuranceOverview.model.ts (2)

13-13: Ensure the from field is always provided by adjusting the type.


15-16: Consider the implications of making status nullable on the consumer side.

Verification successful

The search results indicate numerous instances of the term status across various files and contexts. However, it is crucial to narrow down the search to the specific usage of the status field within the InsuranceOverview model to ensure proper handling of null values.

To achieve this, we need to refine our search to focus on the InsuranceOverview model and its status field specifically. This will help us verify if the nullable status field is being handled correctly in the relevant parts of the codebase.


The previous search did not yield any results, which suggests that the status field in the InsuranceOverview model might not be directly referenced in the expected manner. To ensure thorough verification, we should broaden our search to include any references to the InsuranceOverview model itself. This will help us identify any indirect usages of the status field.


The search results indicate that the InsuranceOverview model is used in several files, specifically in overview.service.ts, overview.resolver.ts, and HealthOverview.tsx. To ensure that the nullable status field is handled correctly, we need to inspect these files for proper null checks and handling of the status field.

Let's generate scripts to extract the relevant code snippets from these files to verify the handling of the status field.


The extracted code snippets show that the InsuranceOverview model is used in the overview.service.ts, overview.resolver.ts, and HealthOverview.tsx files. However, the snippets do not provide enough detail to confirm whether the nullable status field is handled correctly.

To ensure thorough verification, we need to extract more detailed code around the usage of the InsuranceOverview model, specifically focusing on how the status field is accessed and whether null checks are implemented.


The detailed code snippets provide a clearer picture of how the InsuranceOverview model and its status field are used. Here are the key observations:

  1. overview.service.ts:

    • The getInsuranceOverview method fetches data and checks if data is null.
    • The status field is accessed using data.status?.code, indicating that null checks are in place.
  2. overview.resolver.ts:

    • The getInsuranceOverview query returns an InsuranceOverview object or null.
    • This ensures that the resolver can handle cases where the InsuranceOverview might be null.
  3. HealthOverview.tsx:

    • The insurance object is accessed using data?.rightsPortalInsuranceOverview.
    • The status field is not directly accessed here, but the use of optional chaining (?.) suggests that null checks are considered.

Based on these observations, it appears that the nullable status field in the InsuranceOverview model is handled correctly in the relevant parts of the codebase.

  • overview.service.ts: Proper null checks are in place when accessing the status field.
  • overview.resolver.ts: The resolver can handle null values for InsuranceOverview.
  • HealthOverview.tsx: Optional chaining is used, indicating consideration for null values.

Therefore, the concern about making the status field nullable and its implications on the consumer side seems to be addressed adequately.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all usages of the `status` field in the `InsuranceOverview` model to ensure they handle null values.

# Test: Search for the `status` field usage. Expect: Proper null checks where used.
rg --type typescript $'status'

Length of output: 64



Script:

#!/bin/bash
# Description: Verify all usages of the `status` field in the `InsuranceOverview` model to ensure they handle null values.

# Test: Search for the `status` field usage. Expect: Proper null checks where used.
rg --type ts 'status'

Length of output: 408341



Script:

#!/bin/bash
# Description: Verify all usages of the `status` field in the `InsuranceOverview` model to ensure they handle null values.

# Test: Search for the `InsuranceOverview` model and its `status` field usage. Expect: Proper null checks where used.
rg --type ts 'InsuranceOverview.*status'

Length of output: 42



Script:

#!/bin/bash
# Description: Verify all usages of the `InsuranceOverview` model to ensure they handle the nullable `status` field correctly.

# Test: Search for the `InsuranceOverview` model usage. Expect: Proper handling of the `status` field where used.
rg --type ts 'InsuranceOverview'

Length of output: 1846



Script:

#!/bin/bash
# Description: Extract relevant code snippets from files using the `InsuranceOverview` model to verify handling of the nullable `status` field.

# Extract code from overview.service.ts
rg --type ts --context 5 'InsuranceOverview' libs/api/domains/rights-portal/src/lib/overview/overview.service.ts

# Extract code from overview.resolver.ts
rg --type ts --context 5 'InsuranceOverview' libs/api/domains/rights-portal/src/lib/overview/overview.resolver.ts

# Extract code from HealthOverview.tsx
rg --type ts --context 5 'rightsPortalInsuranceOverview' libs/service-portal/health/src/screens/HealthOverview/HealthOverview.tsx

Length of output: 2572



Script:

#!/bin/bash
# Description: Extract detailed code snippets from files using the `InsuranceOverview` model to verify handling of the nullable `status` field.

# Extract detailed code from overview.service.ts
rg --type ts --context 10 'InsuranceOverview' libs/api/domains/rights-portal/src/lib/overview/overview.service.ts

# Extract detailed code from overview.resolver.ts
rg --type ts --context 10 'InsuranceOverview' libs/api/domains/rights-portal/src/lib/overview/overview.resolver.ts

# Extract detailed code from HealthOverview.tsx
rg --type ts --context 10 'rightsPortalInsuranceOverview' libs/service-portal/health/src/screens/HealthOverview/HealthOverview.tsx

Length of output: 3714

libs/api/domains/rights-portal/src/lib/overview/overview.resolver.ts (1)

3-3: Ensure that the UseGuards decorator is correctly applied.

libs/api/domains/rights-portal/src/lib/overview/overview.service.ts (3)

32-34: Log the missing data warning to help with debugging.


45-54: Ensure the getInsuranceOverview method handles cases where data is not available.


67-67: Ensure the from field is handled correctly when data is missing.

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 (1)
libs/api/domains/rights-portal/src/lib/overview/overview.service.ts (1)

Line range hint 1-2: Consider removing unused imports.

- import { Injectable, Inject } from '@nestjs/common'
+ import { Injectable } from '@nestjs/common'
Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 58b46d7 and 126f9f8.
Files selected for processing (2)
  • libs/api/domains/rights-portal/src/lib/overview/overview.service.ts (3 hunks)
  • libs/service-portal/health/src/lib/messages.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • libs/service-portal/health/src/lib/messages.ts
Additional Context Used
Biome (5)
libs/api/domains/rights-portal/src/lib/overview/overview.service.ts (5)

16-16: Decorators are not valid here.


1-2: All these imports are only used as types.


2-3: Some named imports are only used as types.


4-5: All these imports are only used as types.


5-6: All these imports are only used as types.

Path-based Instructions (1)
libs/api/domains/rights-portal/src/lib/overview/overview.service.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 not posted (2)
libs/api/domains/rights-portal/src/lib/overview/overview.service.ts (2)

32-34: Good use of logging to handle missing data scenarios.


Line range hint 45-67: The refactoring to always return an InsuranceOverview object, even when data is missing, makes the output more predictable and aligns with the PR objectives.

@thorkellmani thorkellmani added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label May 30, 2024
@kodiakhq kodiakhq bot merged commit ffda333 into main May 30, 2024
28 checks passed
@kodiakhq kodiakhq bot deleted the fix/health-overview-change branch May 30, 2024 15:16
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