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(auth-api-lib): Use db to look up delegation types and providers when validating #16116

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

baering
Copy link
Member

@baering baering commented Sep 23, 2024

What

☝️

Why

Specify why you need to achieve this

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
    • Introduced a new delegation type: PersonalRepresentativePostbox.
  • Enhancements
    • Improved validation logic for delegation types and providers, enhancing clarity and maintainability.
    • Streamlined the creation process for delegation providers and types in the testing suite.
  • Refactor
    • Removed outdated validation function to simplify the codebase.

@baering baering requested review from a team as code owners September 23, 2024 13:07
Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Walkthrough

The changes consist of updates to the delegation handling within the codebase, including the addition of a constant array for delegation providers, a new function for creating delegation providers and types, and modifications to validation logic. The validation method has been refactored to improve clarity, and a new enumeration value for delegation types has been introduced. Overall, these changes enhance the structure and maintainability of the delegation-related functionality.

Changes

Files Change Summary
apps/services/auth/delegation-api/src/app/delegations/test/delegation-index/delegation-index.controller.spec.ts Added DELEGATION_PROVIDERS constant and createDelegationProvidersAndTypes function; updated test suite initialization for delegation provider and type models.
libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts Introduced validateDelegationTypeAndProvider method and refactored validateCrudParams to be asynchronous, improving validation logic for delegation types and providers.
libs/auth-api-lib/src/lib/delegations/utils/delegations.ts Removed validateDelegationTypeAndProvider function, indicating that its validation logic is no longer present in the codebase.
libs/shared/types/src/lib/delegation.ts Added new enum value PersonalRepresentativePostbox to AuthDelegationType, expanding the delegation types available.

Possibly related PRs

Suggested labels

automerge, high priority

Suggested reviewers

  • GunnlaugurG
  • Herdismaria
  • saevarma

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 52f1575 and 982004c.

Files selected for processing (4)
  • apps/services/auth/delegation-api/src/app/delegations/test/delegation-index/delegation-index.controller.spec.ts (7 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (5 hunks)
  • libs/auth-api-lib/src/lib/delegations/utils/delegations.ts (0 hunks)
  • libs/shared/types/src/lib/delegation.ts (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • libs/auth-api-lib/src/lib/delegations/utils/delegations.ts
Additional context used
Path-based instructions (3)
apps/services/auth/delegation-api/src/app/delegations/test/delegation-index/delegation-index.controller.spec.ts (2)

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

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

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/auth-api-lib/src/lib/delegations/delegations-index.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."
libs/shared/types/src/lib/delegation.ts (2)

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

  • Cross-application utility functions, types, and constants.
  • TypeScript best practices to ensure type safety and reusability.
  • Documentation and examples for library consumers."

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)
apps/services/auth/delegation-api/src/app/delegations/test/delegation-index/delegation-index.controller.spec.ts (2)

10-14: LGTM: New imports and DELEGATION_PROVIDERS constant

The addition of new imports (DelegationProviderModel, DelegationTypeModel) and the DELEGATION_PROVIDERS constant improves the structure and maintainability of the test file. The constant provides a centralized definition of delegation providers and their types, which can be easily updated if needed.

Also applies to: 77-94


Line range hint 95-476: LGTM with suggestion: Impact on existing tests

The changes to the test setup enhance the test environment by providing necessary data without altering the existing test logic. This is a good approach to extending the test coverage.

However, given the new models and data setup, it might be beneficial to:

  1. Verify if any new tests are needed to cover scenarios related to the newly added delegation providers and types.
  2. Ensure that the existing tests still cover all relevant scenarios with the new setup.

To assist with this verification, you could run the following script:

This script will help identify which delegation providers and types are currently covered in the tests, allowing you to spot any gaps in test coverage.

libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (4)

31-31: Import statement is appropriate.

The import of DelegationTypeModel is correctly added and necessary for the new validation logic.


135-136: Injection of DelegationTypeModel is correctly implemented.

The DelegationTypeModel is properly injected into the service using @InjectModel, enabling database interactions.


666-687: Validation method updated correctly with appropriate exception handling.

The validateCrudParams function is properly updated to be asynchronous, and the inclusion of validation checks enhances data integrity. Exception messages are clear and informative, aiding in debugging and user feedback.


266-266: Ensure all calls to validateCrudParams are correctly awaited.

Since validateCrudParams is now an async function, it's important to await its execution to handle validations properly. Verify that all other calls to validateCrudParams within the codebase are updated to use await.

Run the following script to find all usages of validateCrudParams:

This script searches for any calls to validateCrudParams not preceded by await.

Also applies to: 277-277

Verification successful

All calls to validateCrudParams are correctly awaited.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to validateCrudParams to ensure they are awaited.

# Test: Search for validateCrudParams usage. Expect: All calls should be preceded by 'await'.
rg --type ts --pcre2 '(?<!await\s+)this\.validateCrudParams\(' -A 0 -B 2

Length of output: 159


Script:

#!/bin/bash
# Description: Find all calls to validateCrudParams to ensure they are awaited.

# Test: Search for validateCrudParams usage. Expect: All calls should be preceded by 'await'.
rg --type ts --pcre2 '(?<!await )this\.validateCrudParams\(' -A 0 -B 2

Length of output: 72

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

Outside diff range and nitpick comments (1)
apps/services/auth/delegation-api/src/app/delegations/test/delegation-index/delegation-index.controller.spec.ts (1)

10-14: LGTM! Consider adding JSDoc comments for DELEGATION_PROVIDERS

The new imports and the DELEGATION_PROVIDERS constant align well with the PR objective of using the database for delegation types and providers lookup. This enhances the test setup by providing a clear definition of the available providers and types.

Consider adding JSDoc comments to the DELEGATION_PROVIDERS constant to improve code documentation:

/**
 * Defines the available delegation providers and their corresponding types.
 * Used for setting up test data in the database.
 */
const DELEGATION_PROVIDERS = [
  // ... existing array content
];

Also applies to: 77-94

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 982004c and 4d8e38c.

Files selected for processing (2)
  • apps/services/auth/delegation-api/src/app/delegations/test/delegation-index/delegation-index.controller.spec.ts (7 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (5 hunks)
Additional context used
Path-based instructions (2)
apps/services/auth/delegation-api/src/app/delegations/test/delegation-index/delegation-index.controller.spec.ts (2)

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

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

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/auth-api-lib/src/lib/delegations/delegations-index.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)
apps/services/auth/delegation-api/src/app/delegations/test/delegation-index/delegation-index.controller.spec.ts (2)

452-464: LGTM! Well-structured setup function

The setupDelegationModels function is a well-implemented encapsulation of the setup logic for delegation models. It follows NestJS patterns for dependency injection and effectively serves its purpose in the test setup.

This function will help reduce duplication in the test suites and improve maintainability.


Line range hint 1-490: Overall LGTM: Changes align well with PR objective

The modifications to this test file effectively incorporate the new database-driven approach for delegation types and providers lookup, aligning well with the PR objective. The changes include:

  1. New imports for database models
  2. A constant defining delegation providers and types
  3. Updated test setup to initialize the necessary models
  4. New helper functions for setting up delegation models and creating test data

The changes maintain the existing test structure while enhancing it to work with the new database lookup functionality. The code follows NestJS testing practices and patterns, ensuring consistency with the project's architecture.

To further improve the code:

  1. Consider adding JSDoc comments to the DELEGATION_PROVIDERS constant
  2. Implement the suggested refactoring to reduce duplication in test setup
  3. Add error handling to the createDelegationProvidersAndTypes function

These enhancements will improve code documentation, maintainability, and robustness.

libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (4)

31-31: LGTM: Import added for new validation logic

The addition of the DelegationTypeModel import is appropriate for the new validation logic being introduced. This change adheres to the TypeScript usage guideline for importing types.


135-136: LGTM: Constructor updated for new validation logic

The addition of DelegationTypeModel to the constructor is consistent with the new validation logic and follows the existing dependency injection pattern. This change supports the reusability aspect mentioned in the coding guidelines.


266-266: LGTM: Async validation properly handled

The await keyword has been correctly added to the validateCrudParams call, ensuring that the validation is completed before proceeding with the upsert operation. This change improves error handling and maintains the logical flow of the method.


277-277: LGTM: Async validation properly handled

The await keyword has been correctly added to the validateCrudParams call in the removeDelegationRecord method, ensuring that the validation is completed before proceeding with the delete operation. This change is consistent with the update in createOrUpdateDelegationRecord and improves error handling.

Copy link
Member

@saevarma saevarma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@saevarma saevarma added the automerge Merge this PR as soon as all checks pass label Sep 23, 2024
@kodiakhq kodiakhq bot removed the automerge Merge this PR as soon as all checks pass label Sep 29, 2024
Copy link
Contributor

kodiakhq bot commented Sep 29, 2024

This PR currently has a merge conflict. Please resolve this and then re-add the automerge label.

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.72%. Comparing base (d1c22d8) to head (0055bc2).
Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16116      +/-   ##
==========================================
- Coverage   36.75%   36.72%   -0.04%     
==========================================
  Files        6835     6835              
  Lines      141330   141336       +6     
  Branches    40238    40239       +1     
==========================================
- Hits        51949    51904      -45     
- Misses      89381    89432      +51     
Flag Coverage Δ
air-discount-scheme-backend 54.08% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.37% <ø> (ø)
api-domains-air-discount-scheme 36.93% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.91% <100.00%> (+<0.01%) ⬆️
api-domains-criminal-record 48.00% <ø> (ø)
api-domains-driving-license 44.43% <ø> (ø)
api-domains-education 31.58% <ø> (ø)
api-domains-health-insurance 34.77% <ø> (ø)
api-domains-mortgage-certificate 34.95% <ø> (ø)
api-domains-payment-schedule 41.16% <ø> (ø)
application-api-files 56.86% <ø> (ø)
application-core 71.64% <ø> (+0.40%) ⬆️
application-system-api 41.37% <100.00%> (+<0.01%) ⬆️
application-template-api-modules 27.85% <100.00%> (-0.01%) ⬇️
application-templates-accident-notification 29.27% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 26.34% <ø> (ø)
application-templates-driving-license 18.32% <ø> (ø)
application-templates-estate 12.32% <ø> (ø)
application-templates-example-payment 25.14% <ø> (ø)
application-templates-financial-aid 15.50% <ø> (ø)
application-templates-general-petition 23.44% <ø> (ø)
application-templates-inheritance-report 6.49% <ø> (ø)
application-templates-marriage-conditions 15.17% <ø> (ø)
application-templates-mortgage-certificate 43.85% <100.00%> (+0.02%) ⬆️
application-templates-parental-leave 29.96% <ø> (ø)
application-types 6.63% <ø> (ø)
application-ui-components 1.28% <ø> (ø)
application-ui-shell 21.37% <ø> (ø)
auth-nest-tools 30.02% <100.00%> (+0.18%) ⬆️
auth-react 22.77% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.67% <ø> (ø)
clients-driving-license-book 43.80% <ø> (ø)
clients-financial-statements-inao 49.32% <ø> (ø)
clients-license-client 1.83% <ø> (ø)
clients-middlewares 73.11% <100.00%> (+0.27%) ⬆️
clients-regulations 42.80% <ø> (ø)
clients-rsk-company-registry 29.76% <ø> (ø)
clients-syslumenn 49.44% <ø> (ø)
cms 0.42% <ø> (ø)
cms-translations 39.04% <100.00%> (+<0.01%) ⬆️
content-search-index-manager 95.65% <ø> (ø)
content-search-toolkit 8.16% <ø> (ø)
contentful-apps 5.44% <ø> (ø)
download-service 44.22% <ø> (ø)
financial-aid-backend 56.37% <ø> (ø)
financial-aid-shared 18.94% <ø> (ø)
icelandic-names-registry-backend 53.97% <ø> (ø)
island-ui-core 28.39% <ø> (ø)
judicial-system-api 18.36% <ø> (ø)
judicial-system-backend 55.15% <100.00%> (+<0.01%) ⬆️
judicial-system-web 27.91% <ø> (ø)
license-api 42.77% <ø> (+0.07%) ⬆️
localization 10.15% <ø> (ø)
nest-audit 68.20% <ø> (ø)
nest-aws ?
nest-feature-flags 51.52% <ø> (ø)
nest-problem 45.85% <ø> (ø)
nest-swagger 51.71% <ø> (ø)
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 16.15% <ø> (ø)
reference-backend 49.79% <ø> (ø)
services-auth-delegation-api 57.31% <100.00%> (-0.06%) ⬇️
services-auth-personal-representative 45.13% <15.00%> (-0.01%) ⬇️
services-sessions 65.39% <100.00%> (+0.06%) ⬆️
services-university-gateway 48.31% <ø> (-0.06%) ⬇️
services-user-notification 47.02% <100.00%> (+0.03%) ⬆️
services-user-profile 62.19% <ø> (+0.16%) ⬆️
shared-components 27.65% <ø> (ø)
shared-form-fields 31.59% <ø> (ø)
shared-problem 87.50% <ø> (ø)
shared-utils 27.69% <ø> (ø)
skilavottord-ws 24.24% <ø> (ø)
web 1.82% <ø> (ø)

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

Files with missing lines Coverage Δ
...b/src/lib/delegations/delegations-index.service.ts 87.44% <100.00%> (+0.43%) ⬆️
...h-api-lib/src/lib/delegations/utils/delegations.ts 100.00% <ø> (ø)
libs/shared/types/src/lib/delegation.ts 100.00% <100.00%> (ø)

... and 5 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 18b2931...0055bc2. Read the comment docs.

@datadog-island-is
Copy link

Datadog Report

All test runs 5750c1e 🔗

81 Total Test Services: 1 Failed, 77 Passed
🔻 Test Sessions change in coverage: 3 decreased, 6 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
services-auth-ids-api 1 0 0 151 0 1m 7.2s 1 decreased (-0.01%) Link
air-discount-scheme-backend 0 0 0 81 0 30.76s N/A Link
air-discount-scheme-web 0 0 0 2 0 8.11s N/A Link
api 0 0 0 4 0 2.59s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 17.57s N/A Link
api-domains-assets 0 0 0 3 0 11.45s N/A Link
api-domains-auth-admin 0 0 0 18 0 12.06s N/A Link
api-domains-communications 0 0 0 5 0 29.19s N/A Link
api-domains-criminal-record 0 0 0 5 0 9.21s N/A Link
api-domains-driving-license 0 0 0 23 0 29.06s N/A Link

❌ Failed Tests (1)

  • DelegationsController verify POST /v1/delegations/verify returns non-verified response - apps/services/auth/ids-api/src/app/delegations/test/delegations-filters.spec.ts - Details

    Expand for error
     Invalid delegation type and provider combination
    

🔻 Code Coverage Decreases vs Default Branch (3)

  • services-auth-delegation-api - jest 51.23% (-0.18%) - Details
  • services-university-gateway - jest 44.84% (-0.02%) - Details
  • services-auth-ids-api - jest 45.01% (-0.01%) - Details

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.

2 participants