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(ids-admin): Delegation-Delegation-Type #16068

Merged
merged 18 commits into from
Sep 23, 2024

Conversation

GunnlaugurG
Copy link
Member

@GunnlaugurG GunnlaugurG commented Sep 18, 2024

What

Add delegation_delegation_type to db and support General Mandate delegations (Allsherjarumboð)

Why

So the new delegations-admin module can create GeneralMandate delegation

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 support for "General Mandate" delegation type across various components and services.
    • Enhanced delegation handling, allowing for improved retrieval and management of delegation data.
    • Added new methods to fetch valid and available general mandates based on national IDs.
  • Bug Fixes

    • Improved test coverage for delegation functionalities, ensuring accurate behavior of API endpoints related to general mandates.

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Walkthrough

The changes enhance the delegation management system by introducing a new delegation type, "General Mandate." This includes updates to various models, services, and controllers to ensure proper handling, retrieval, and testing of general mandates. The modifications involve creating new relationships in the database, updating data transfer object (DTO) methods, and expanding test coverage to include scenarios related to the new delegation type.

Changes

File Change Summary
apps/services/auth/ids-api/src/app/delegations/delegations.controller.spec.ts Enhanced tests for "General Mandate" delegations, including retrieval and validation scenarios, and introduced a new test file for Personal Representative delegations.
libs/api/domains/auth/src/lib/models/delegation.model.ts Established a relationship for multiple delegation types and modified DTO methods for flexibility in handling delegation types.
libs/auth-api-lib/src/lib/delegations/delegation-scope.service.ts Introduced findValidGeneralMandateScopesTo method for retrieving general mandates based on national IDs, enhancing delegation management capabilities.
libs/auth-api-lib/src/lib/delegations/delegations-incoming-custom.service.ts Added methods for retrieving valid and available general mandates, including logic for handling user names and API scopes.
libs/auth-api-lib/src/lib/delegations/delegations-incoming.service.ts Expanded functionality to manage general mandates by incorporating new methods for retrieving valid and available general mandates.
libs/auth-api-lib/src/lib/delegations/models/delegation-delegation-type.model.ts Introduced a new model for managing many-to-many relationships between delegations and delegation types.
libs/portals/admin/delegation-admin/project.json Modified project configuration for improved readability and added a new target for extracting strings from TypeScript files.

Possibly related PRs

Suggested reviewers

  • Herdismaria
  • saevarma
---

<details>
Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7cd4249 and 7acc178.

<details>
Files selected for processing (1)
  • libs/auth-api-lib/src/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • libs/auth-api-lib/src/index.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

codecov bot commented Sep 18, 2024

Codecov Report

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

Project coverage is 36.71%. Comparing base (a4421c5) to head (7acc178).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...delegations/delegations-incoming-custom.service.ts 73.68% 10 Missing ⚠️
...legations/admin/delegation-admin-custom.service.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16068      +/-   ##
==========================================
+ Coverage   36.63%   36.71%   +0.08%     
==========================================
  Files        6749     6747       -2     
  Lines      138852   138633     -219     
  Branches    39457    39402      -55     
==========================================
+ Hits        50863    50903      +40     
+ Misses      87989    87730     -259     
Flag Coverage Δ
api 3.39% <ø> (ø)
api-domains-auth-admin 48.86% <ø> (ø)
application-system-api 41.50% <ø> (ø)
application-template-api-modules 23.45% <ø> (-0.01%) ⬇️
services-auth-admin-api 52.84% <36.58%> (-0.12%) ⬇️
services-auth-delegation-api 61.31% <54.87%> (+0.03%) ⬆️
services-auth-ids-api 54.13% <75.60%> (+0.13%) ⬆️
services-auth-personal-representative 47.86% <36.58%> (-0.09%) ⬇️
services-auth-personal-representative-public 43.81% <35.36%> (-0.03%) ⬇️
services-auth-public-api 51.94% <67.07%> (+0.17%) ⬆️
services-user-notification 47.16% <ø> (ø)
services-user-profile 62.28% <ø> (ø)

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

Files with missing lines Coverage Δ
libs/auth-api-lib/src/index.ts 100.00% <100.00%> (ø)
...ib/src/lib/delegations/delegation-scope.service.ts 93.68% <100.00%> (+0.74%) ⬆️
...rc/lib/delegations/delegations-incoming.service.ts 98.18% <100.00%> (+0.05%) ⬆️
...-api-lib/src/lib/delegations/delegations.module.ts 100.00% <100.00%> (ø)
...gations/models/delegation-delegation-type.model.ts 100.00% <100.00%> (ø)
...rc/lib/delegations/models/delegation-type.model.ts 100.00% <100.00%> (ø)
...lib/src/lib/delegations/models/delegation.model.ts 92.10% <100.00%> (+3.53%) ⬆️
...es/auth/testing/src/fixtures/delegation.fixture.ts 100.00% <ø> (+3.70%) ⬆️
...legations/admin/delegation-admin-custom.service.ts 48.64% <0.00%> (ø)
...delegations/delegations-incoming-custom.service.ts 92.07% <73.68%> (-5.57%) ⬇️

... and 52 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 a4421c5...7acc178. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 18, 2024

Datadog Report

All test runs 1eb45fa 🔗

13 Total Test Services: 0 Failed, 13 Passed
🔻 Test Sessions change in coverage: 3 decreased, 3 increased, 22 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
api 0 0 0 4 0 2.8s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 12.65s 1 no change Link
application-system-api 0 0 0 111 2 3m 5.42s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 51.89s 1 no change Link
auth-api-lib 0 0 0 20 0 35.26s 1 no change Link
services-auth-admin-api 0 0 0 113 0 2m 45.17s 1 decreased (-0.08%) Link
services-auth-delegation-api 0 0 0 256 0 2m 45.29s 1 increased (+0.24%) Link
services-auth-ids-api 0 0 0 149 0 54.53s 1 increased (+0.15%) Link
services-auth-personal-representative 0 0 0 59 0 1m 12.07s 1 decreased (-0.06%) Link
services-auth-personal-representative-public 0 0 0 10 0 24.89s 1 decreased (-0.02%) Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • services-auth-admin-api - jest 52.93% (-0.08%) - Details
  • services-auth-personal-representative - jest 50.02% (-0.06%) - Details
  • services-auth-personal-representative-public - jest 45.89% (-0.02%) - Details

@GunnlaugurG GunnlaugurG marked this pull request as ready for review September 19, 2024 10:50
@GunnlaugurG GunnlaugurG requested review from a team as code owners September 19, 2024 10:50
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: 9

Outside diff range and nitpick comments (4)
libs/auth-api-lib/migrations/20240916092301-delegation-delegation-type.js (1)

1-1: Remove the redundant 'use strict' directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.

Apply this diff to remove the redundant directive:

-'use strict'
-
 module.exports = {
   async up(queryInterface, Sequelize) {
Tools
Biome

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

libs/auth-api-lib/src/lib/delegations/delegation-scope.service.ts (2)

Line range hint 210-214: Ensure TypeScript return types match the method implementations

In the findAllScopesTo method, consider explicitly defining the return type for better clarity and to leverage TypeScript's type checking.

Apply this diff to specify the return type:

async findAllScopesTo(
  user: User,
  fromNationalId: string,
  delegationTypes: string[],
-): Promise<string[]> {
+): Promise<string[]> {

While the return type is inferred, explicitly declaring it enhances code maintainability and readability.


Line range hint 126-150: Confirm the necessity of the async keyword in findValidCustomScopesTo

The method findValidCustomScopesTo is now marked as async, but there is no use of await within its body. If there are no asynchronous operations that require await, the async keyword might be unnecessary.

Consider removing the async keyword if not needed:

- private async findValidCustomScopesTo(
+ private findValidCustomScopesTo(
    toNationalId: string,
    fromNationalId: string,
  ): Promise<DelegationScope[]> {

Alternatively, if you anticipate adding asynchronous operations in the future or for consistency with other methods, it is acceptable to keep it as is.

apps/services/auth/ids-api/src/app/delegations/delegations.controller.spec.ts (1)

304-309: Enhance test assertions to verify response content

Currently, the test checks the status code and the length of the response body. Consider adding assertions to verify the actual content of the mergedDelegationDTO to ensure it contains the expected general mandate data.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ca6099e and 062a582.

Files selected for processing (18)
  • apps/services/auth/ids-api/src/app/delegations/delegations.controller.spec.ts (4 hunks)
  • apps/services/auth/ids-api/test/stubs/personalRepresentativeStubs.ts (1 hunks)
  • apps/services/auth/public-api/src/app/modules/delegations/actorDelegations.controller.spec.ts (6 hunks)
  • apps/services/auth/public-api/test/setup.ts (1 hunks)
  • libs/api/domains/auth/src/lib/models/delegation.model.ts (1 hunks)
  • libs/auth-api-lib/migrations/20240916092301-delegation-delegation-type.js (1 hunks)
  • libs/auth-api-lib/seeders/local/012-general-mandate.js (1 hunks)
  • libs/auth-api-lib/src/index.ts (1 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegation-scope.service.ts (6 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegations-incoming-custom.service.ts (4 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegations-incoming.service.ts (2 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegations.module.ts (2 hunks)
  • libs/auth-api-lib/src/lib/delegations/models/delegation-delegation-type.model.ts (1 hunks)
  • libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts (2 hunks)
  • libs/auth-api-lib/src/lib/delegations/models/delegation.model.ts (4 hunks)
  • libs/portals/shared-modules/delegations/src/components/access/AccessCard.tsx (1 hunks)
  • libs/portals/shared-modules/delegations/src/lib/messages.ts (1 hunks)
  • libs/shared/types/src/lib/delegation.ts (1 hunks)
Additional context used
Path-based instructions (18)
apps/services/auth/ids-api/src/app/delegations/delegations.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."
apps/services/auth/ids-api/test/stubs/personalRepresentativeStubs.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."
apps/services/auth/public-api/src/app/modules/delegations/actorDelegations.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."
apps/services/auth/public-api/test/setup.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/api/domains/auth/src/lib/models/delegation.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/auth-api-lib/migrations/20240916092301-delegation-delegation-type.js (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/auth-api-lib/seeders/local/012-general-mandate.js (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/auth-api-lib/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."
libs/auth-api-lib/src/lib/delegations/delegation-scope.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/auth-api-lib/src/lib/delegations/delegations-incoming-custom.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/auth-api-lib/src/lib/delegations/delegations-incoming.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/auth-api-lib/src/lib/delegations/delegations.module.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/auth-api-lib/src/lib/delegations/models/delegation-delegation-type.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/auth-api-lib/src/lib/delegations/models/delegation-type.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/auth-api-lib/src/lib/delegations/models/delegation.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/portals/shared-modules/delegations/src/components/access/AccessCard.tsx (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/portals/shared-modules/delegations/src/lib/messages.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."
Biome
libs/auth-api-lib/migrations/20240916092301-delegation-delegation-type.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

Additional comments not posted (35)
libs/shared/types/src/lib/delegation.ts (1)

7-7: LGTM!

The new enumeration value GeneralMandate is a valid addition to the AuthDelegationType enum. It follows the naming convention used by other enumeration values and does not alter existing values or their semantics. The change adheres to the TypeScript best practices for defining enums and is consistent with the provided PR objectives and AI-generated summary.

libs/auth-api-lib/seeders/local/012-general-mandate.js (3)

1-2: LGTM!

The import statement is correct and the uuid function is used appropriately in the script.


4-40: LGTM!

The up function is implemented correctly and follows best practices for database seeding:

  • It uses a transaction to ensure atomicity of the database operations.
  • It generates a unique identifier for the delegation record.
  • It inserts records into the necessary tables.
  • It commits the transaction if the insertions are successful, otherwise it rolls back the transaction and logs the error.

3-44: LGTM!

The exported object is structured correctly and follows the expected format for a database seeder script.

libs/auth-api-lib/src/lib/delegations/models/delegation-delegation-type.model.ts (1)

20-61: LGTM! The model definition follows best practices and effectively utilizes Sequelize features.

The DelegationDelegationType model is well-structured and adheres to best practices:

  • The model is correctly defined using the @Table decorator and extends the Sequelize Model class with appropriate type parameters for attribute inference.
  • The foreign keys delegationId and delegationTypeId are properly marked as primary keys and required, ensuring data integrity and preventing orphaned records.
  • The optional validTo date field provides flexibility for specifying the validity period of the delegation type association.
  • Automatic timestamping is implemented using the @CreatedAt and @UpdatedAt decorators, enabling tracking of creation and modification dates for auditing and debugging purposes.
  • The relationships with Delegation and DelegationTypeModel are established correctly using the @BelongsTo decorator, allowing for easy access to related data and simplifying queries.

Overall, the model definition is solid and lays a strong foundation for managing delegation types effectively.

libs/auth-api-lib/migrations/20240916092301-delegation-delegation-type.js (2)

4-45: LGTM!

The migration script correctly creates the delegation_delegation_type table to establish the many-to-many relationship between delegation and delegation_type tables. The field definitions are appropriate, and the unique constraint ensures the integrity of the relationship.


47-54: LGTM!

The migration rollback script correctly removes the unique constraint and drops the delegation_delegation_type table.

libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts (1)

83-84: LGTM! The new @HasMany association enhances the data model.

The addition of the delegationDelegationTypes property allows a delegation type to have multiple associated delegation-delegation types, potentially expanding the functionality of the delegation management system.

Please ensure that:

  1. The integration of this change with related components is verified.
  2. The new relationship is properly handled in the relevant services, controllers, and other parts of the application that interact with delegation types.
libs/api/domains/auth/src/lib/models/delegation.model.ts (1)

34-34: LGTM! The change aligns with the PR objective.

Adding the AuthDelegationType.GeneralMandate case to the exhaustiveCheck function is a crucial step in supporting the new General Mandate delegation type. By returning CustomDelegation for this type, the code ensures that General Mandate delegations are correctly resolved and handled similarly to Custom delegations.

This change is consistent with the PR objective of adding support for General Mandate delegations and lays the foundation for their proper handling in the broader application context.

apps/services/auth/ids-api/test/stubs/personalRepresentativeStubs.ts (1)

118-118: LGTM!

The addition of the new delegation type AuthDelegationType.GeneralMandate to the delegationTypes array is consistent with the PR objective and enables testing the new functionality. The change is made in the appropriate location and does not introduce any issues.

libs/auth-api-lib/src/lib/delegations/models/delegation.model.ts (5)

28-28: LGTM!

The import statement is relevant and the import path seems correct.


44-44: LGTM!

The id property is defined correctly with appropriate decorators and data type.


109-110: LGTM!

The @HasMany association between Delegation and DelegationDelegationType is defined correctly with the appropriate onDelete behavior.


Line range hint 112-124: LGTM!

The modification to the toDTO method to accept an optional type parameter is a good enhancement. It provides flexibility while maintaining backward compatibility. The type property is correctly set in the returned DTO object.


129-136: LGTM!

The modification to the toMergedDTO method to accept an optional types parameter is a good enhancement. It allows for specifying multiple delegation types while maintaining backward compatibility. The types property is correctly set in the returned DTO object.

libs/auth-api-lib/src/lib/delegations/delegations.module.ts (2)

37-37: LGTM!

The import statement for DelegationDelegationType aligns with the PR objective of adding support for the new "General Mandate" delegation type. This is a necessary step to integrate the new type into the module.


61-61: Looks good!

Adding DelegationDelegationType to the imports array of the @Module decorator is necessary to make it available for dependency injection within the module. This change aligns with the PR objective of supporting the new "General Mandate" delegation type.

apps/services/auth/public-api/test/setup.ts (1)

75-75: LGTM!

The addition of AuthDelegationType.GeneralMandate to the delegationTypes array is consistent with the PR objective of supporting General Mandate delegations.

Please ensure that the test cases adequately cover the scenarios related to the new delegation type to verify its proper functioning across the relevant models, services, and controllers.

libs/portals/shared-modules/delegations/src/lib/messages.ts (1)

33-36: LGTM!

The new message definition for delegationTypeGeneralMandate follows the existing pattern and naming conventions. It allows for the representation of a general mandate delegation type in the user interface without affecting the existing functionality.

libs/portals/shared-modules/delegations/src/components/access/AccessCard.tsx (1)

103-105: LGTM!

The new case correctly handles the GeneralMandate delegation type and assigns the appropriate label using the formatMessage function. The code follows the existing pattern and should not introduce any issues.

libs/auth-api-lib/src/index.ts (1)

55-55: LGTM!

The change adheres to the existing pattern of exporting models from the index file and is consistent with the PR objective of adding a new field, delegation_delegation_type, to the database to support General Mandate delegations.

libs/auth-api-lib/src/lib/delegations/delegations-incoming.service.ts (2)

105-109: LGTM!

The addition of the promise to fetch valid general mandates based on the user's national ID is a logical enhancement to the service's functionality.


191-200: LGTM!

The conditional handling of fetching available general mandates based on the delegation types, user context, and client-related API scopes is a thoughtful enhancement to the service's functionality.

libs/auth-api-lib/src/lib/delegations/delegations-incoming-custom.service.ts (5)

86-111: LGTM!

The function logic is correct, and the implementation is well-structured. The usage of the private method findAllIncomingGeneralMandates promotes code reusability and maintainability.


180-216: LGTM!

The function logic is correct, and the implementation is well-structured. It properly filters the API scopes based on the supported delegation type and handles the case when no matching API scopes are found. The usage of the private method findAllIncomingGeneralMandates promotes code reusability and maintainability.


218-289: LGTM!

The function logic is correct, and the implementation is well-structured. It constructs a complex query to fetch the delegations along with the necessary associations. It correctly handles the deletion of deceased delegations and logs the action for auditing purposes. The usage of the getLiveStatusFromDelegations method promotes code reusability and maintainability.


Line range hint 290-380: LGTM!

The function logic is correct, and the implementation is well-structured. It constructs a query to fetch the delegations along with the necessary associations. It correctly handles the deletion of deceased delegations and logs the action for auditing purposes. The usage of the getLiveStatusFromDelegations method promotes code reusability and maintainability.


Line range hint 453-520: LGTM!

The function logic is correct, and the implementation is well-structured. It correctly divides the delegations into alive and deceased delegations based on the specified criteria. It handles errors gracefully by returning all delegations as alive delegations in case of an error. The usage of the partitionWithIndex utility function promotes code readability and maintainability.

apps/services/auth/public-api/src/app/modules/delegations/actorDelegations.controller.spec.ts (6)

155-155: LGTM!

The variable declaration is correct and follows the naming convention. It is likely used in the test suite to interact with the DelegationDelegationType model.


177-179: LGTM!

The code correctly retrieves the DelegationDelegationType model using the getModelToken function and the app.get method. This follows the NestJS dependency injection pattern for obtaining a reference to a Sequelize model.


299-334: LGTM!

The test case is well-structured and follows the Arrange-Act-Assert pattern. It covers an important scenario of returning both custom delegations and general mandate when both types are requested and exist. The assertions verify the response status, the number of returned delegations, and the presence of the expected delegation types.


336-372: LGTM!

The test case is well-structured and follows the Arrange-Act-Assert pattern. It covers an important scenario of returning a merged object with both custom and general mandate types when both types are requested and exist for the same delegation. The assertions verify the response status, the number of returned delegations, and the presence of both custom and general mandate types in the merged object.


Line range hint 374-401: LGTM!

The test case is well-structured and follows the Arrange-Act-Assert pattern. It covers an important scenario of filtering delegations based on the otherUser national ID. The assertions verify the response status, the number of returned delegations, and the matching of the returned delegation with the expected delegation.


Line range hint 402-429: LGTM!

The test case is well-structured and follows the Arrange-Act-Assert pattern. It covers an important scenario of filtering delegations based on the otherUser national ID and the absence of a general mandate. The assertions verify the response status, the number of returned delegations, and the matching of the returned delegation with the expected delegation.

apps/services/auth/ids-api/src/app/delegations/delegations.controller.spec.ts (1)

9-11: Imports added for required models

The added imports for Client, Delegation, DelegationDelegationType, and DelegationScope are appropriate and necessary for the code changes.

Also applies to: 13-13

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

191-196: Enhance assertion by checking response content

Currently, the test only checks the length of the response body. To make the test more robust, consider asserting the actual content of the response to ensure it contains the expected data:

expect(response.status).toEqual(200)
-expect(response.body).toHaveLength(1)
+expect(response.body).toEqual([
+  {
+    // Expected delegation data
+  },
+])

255-256: Ensure date calculations handle timezones accurately

When setting validFrom and validTo dates relative to the current date, consider potential issues with timezones that might affect test reliability. To avoid flaky tests, you might fix the dates or use a consistent timezone.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 707cedd and d652ba7.

Files selected for processing (2)
  • apps/services/auth/ids-api/src/app/delegations/delegations-personal-representative.controller.spec.ts (3 hunks)
  • apps/services/auth/ids-api/src/app/delegations/test/delegations.controller.spec.ts (1 hunks)
Additional context used
Path-based instructions (2)
apps/services/auth/ids-api/src/app/delegations/delegations-personal-representative.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."
apps/services/auth/ids-api/src/app/delegations/test/delegations.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."
Additional comments not posted (8)
apps/services/auth/ids-api/src/app/delegations/delegations-personal-representative.controller.spec.ts (5)

9-13: LGTM!

The new imports are valid and likely necessary for the updated test suite.


58-59: LGTM!

The new imports uuid and addDays are valid and likely necessary for the updated test suite.


61-61: LGTM!

The updated test suite description accurately reflects the focus on personal representative delegations.


67-67: LGTM!

The clientModel variable is properly declared and initialized by retrieving the Client model from the application context. This suggests that the tests may now involve interactions with the Client model.


153-153: LGTM!

The clientModel is properly assigned by retrieving the Client model from the application context using app.get(), which is consistent with the variable declaration.

apps/services/auth/ids-api/src/app/delegations/test/delegations.controller.spec.ts (3)

243-248: Avoid redundant creation of existing delegation types

You are creating a delegation type with the ID AuthDelegationType.Custom, which might already exist in the database or test setup. This could lead to conflicts or redundant data. Verify if this creation is necessary, and remove it if it's redundant:

await delegationTypeModel.create({
  id: AuthDelegationType.Custom,
  name: 'custom',
  description: 'custom',
  providerId: AuthDelegationProvider.Custom,
})

221-222: Testing expired delegations

In the test setup, you set validTo to a past date to simulate expired delegations. Ensure that this aligns with the test case’s purpose and that other tests are not affected by this expired delegation. Consider isolating this delegation within the specific test case.


35-278: Overall test coverage is comprehensive

The test suite thoroughly covers different scenarios related to general mandate delegations, including valid cases, expired delegations, and combined delegation types. The use of mocked services and data setup is appropriate.

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/portals/admin/delegation-admin/project.json (1)

23-28: New target for string extraction added

The new extract-strings target is a valuable addition for internationalization support. It adheres to the coding guidelines by enhancing reusability across different NextJS apps.

Consider improving readability by breaking the long command into multiple lines:

"extract-strings": {
  "executor": "nx:run-commands",
  "options": {
    "command": "yarn ts-node -P libs/localization/tsconfig.lib.json \
                libs/localization/scripts/extract \
                'libs/portals/admin/delegation-admin/src/**/*.{ts,tsx}'"
  }
}

This format maintains functionality while enhancing readability.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1286f75 and 76f6a98.

Files selected for processing (6)
  • apps/services/auth/ids-api/src/app/delegations/delegations-personal-representative.controller.spec.ts (3 hunks)
  • apps/services/auth/ids-api/src/app/delegations/test/delegations.controller.spec.ts (1 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegation-scope.service.ts (6 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegations-incoming-custom.service.ts (4 hunks)
  • libs/auth-api-lib/src/lib/delegations/models/delegation-delegation-type.model.ts (1 hunks)
  • libs/portals/admin/delegation-admin/project.json (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • apps/services/auth/ids-api/src/app/delegations/delegations-personal-representative.controller.spec.ts
  • apps/services/auth/ids-api/src/app/delegations/test/delegations.controller.spec.ts
  • libs/auth-api-lib/src/lib/delegations/delegation-scope.service.ts
  • libs/auth-api-lib/src/lib/delegations/delegations-incoming-custom.service.ts
  • libs/auth-api-lib/src/lib/delegations/models/delegation-delegation-type.model.ts
Additional context used
Path-based instructions (1)
libs/portals/admin/delegation-admin/project.json (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/portals/admin/delegation-admin/project.json (2)

6-9: Improved readability of tags

The multi-line format for tags enhances readability without affecting functionality. This change aligns with best practices for configuration file formatting.


16-18: Enhanced readability of test outputs configuration

The multi-line format for the outputs field in the test target improves code readability. This change is consistent with the formatting style used elsewhere in the file.

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
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.

4 participants