-
Notifications
You must be signed in to change notification settings - Fork 61
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-admin): Check if delegation already exists. #16420
Conversation
WalkthroughThe changes in this pull request enhance the delegation management API by adding new test cases for the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used📓 Learnings (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (4)
libs/shared/utils/src/lib/errorCodes.ts (1)
9-10
: LGTM! Consider adding documentation for new error codes.The new error codes
COULD_NOT_CREATE_DELEGATION
andREFERENCE_ID_ALREADY_EXISTS
are well-named and consistent with the existing enum entries. They align with the PR objective of improving error handling for delegation creation.To enhance maintainability, consider adding a brief comment above each new error code explaining its specific use case. This would help other developers understand when and where these error codes should be used.
Example:
// Used when a delegation cannot be created due to an existing delegation COULD_NOT_CREATE_DELEGATION = 'COULD_NOT_CREATE_DELEGATION', // Used when attempting to create a delegation with a reference ID that already exists REFERENCE_ID_ALREADY_EXISTS = 'REFERENCE_ID_ALREADY_EXISTS',libs/auth-api-lib/src/lib/delegations/models/delegation.model.ts (1)
87-87
: Improved type safety fordomainName
propertyThe change to allow
null
as a possible value fordomainName
improves type safety and clarity. This modification explicitly represents the absence of a value, which is a good TypeScript practice.Consider updating other parts of the codebase that interact with this property to handle the
null
case explicitly. This might include:
- Updating any functions that use
domainName
to handlenull
values.- Reviewing and updating unit tests to cover the
null
case.Would you like me to search for usages of
domainName
in the codebase to identify potential areas that need updates?apps/services/auth/admin-api/src/app/v2/delegations/test/delegation-admin.spec.ts (2)
342-379
: LGTM! Consider adding a descriptive comment.This test case effectively covers the scenario of preventing duplicate delegations based on national IDs. It follows NestJS testing practices and provides good coverage for the new functionality.
Consider adding a brief comment explaining the purpose of this test case at the beginning, for example:
// Test case to ensure that a delegation cannot be created if one already exists with the same national IDs
This would enhance the readability and maintainability of the test suite.
381-419
: LGTM! Consider clarifying the test case name.This test case effectively covers the scenario of preventing the creation of a delegation with an existing reference ID. It follows NestJS testing practices and provides good coverage for the new functionality.
The test case name mentions "delegation id", but it's actually checking for the "reference id". Consider renaming the test case for clarity:
it('POST /delegation-admin should not create delegation since the reference id already exists', async () => {This would make the purpose of the test more immediately clear to other developers.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (5)
- apps/services/auth/admin-api/src/app/v2/delegations/test/delegation-admin.spec.ts (1 hunks)
- libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts (2 hunks)
- libs/auth-api-lib/src/lib/delegations/models/delegation.model.ts (1 hunks)
- libs/services/auth/testing/src/fixtures/types.ts (1 hunks)
- libs/shared/utils/src/lib/errorCodes.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
apps/services/auth/admin-api/src/app/v2/delegations/test/delegation-admin.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/admin/delegation-admin-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/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/services/auth/testing/src/fixtures/types.ts (2)
Pattern
libs/services/**/*
: "Confirm that the code adheres to the following:
- Shared services and modules that can be utilized across NestJS apps.
- Proper implementation of NestJS providers, including custom providers.
- Adherence to NestJS module encapsulation and isolation principles."
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/utils/src/lib/errorCodes.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."
📓 Learnings (1)
apps/services/auth/admin-api/src/app/v2/delegations/test/delegation-admin.spec.ts (2)
Learnt from: saevarma PR: island-is/island.is#16257 File: apps/services/auth/admin-api/src/app/v2/delegations/test/delegation-admin.auth.spec.ts:178-201 Timestamp: 2024-10-04T07:46:37.013Z Learning: In `apps/services/auth/admin-api/src/app/v2/delegations/test/delegation-admin.auth.spec.ts`, ensure that test case names accurately describe the scenario being tested, particularly in cases involving invalid request signatures.
Learnt from: saevarma PR: island-is/island.is#16257 File: apps/services/auth/admin-api/src/app/v2/delegations/test/delegation-admin.auth.spec.ts:178-201 Timestamp: 2024-10-08T15:39:04.351Z Learning: In `apps/services/auth/admin-api/src/app/v2/delegations/test/delegation-admin.auth.spec.ts`, ensure that test case names accurately describe the scenario being tested, particularly in cases involving invalid request signatures.
🔇 Additional comments (5)
libs/services/auth/testing/src/fixtures/types.ts (1)
40-46
: LGTM: Addition ofdomainName
enhances theCreateCustomDelegation
typeThe addition of the
domainName
property to theCreateCustomDelegation
type is well-implemented and aligns with the PR objectives. This change enhances the delegation management API by allowing the inclusion of domain information in custom delegations.The modification:
- Correctly adds
domainName
to thePick
utility type.- Consistently includes
domainName
in the list of optional properties.- Maintains proper TypeScript usage, ensuring type safety.
This localized change improves the type definition without affecting other parts of the file, promoting reusability across different NextJS apps.
libs/auth-api-lib/src/lib/delegations/models/delegation.model.ts (1)
Line range hint
1-180
: Adherence to coding guidelines forlibs
directoryThe file adheres to the coding guidelines for the
libs
directory:
- It uses TypeScript for defining props and exporting types.
- The
Delegation
class is potentially reusable across different NextJS apps.- There are no obvious issues with tree-shaking or bundling practices.
To ensure the
Delegation
model is used correctly across the project, let's verify its usage:This will help us understand how the
Delegation
model is used across different parts of the project and ensure its reusability.✅ Verification successful
Adherence to coding guidelines for
libs
directory verified.The
Delegation
model is correctly implemented and utilized across the project:
- Widely imported and extended by multiple classes.
- Consistently used in type annotations, ensuring type safety.
- No evidence of removed or replaced code affecting functionality.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check usage of Delegation model across the project # Search for imports of the Delegation model echo "Searching for imports of the Delegation model:" rg --type typescript "import.*Delegation.*from.*delegation\.model" # Search for uses of the Delegation class echo "\nSearching for uses of the Delegation class:" rg --type typescript "new Delegation\(" -A 5Length of output: 389
Script:
#!/bin/bash # Description: Check usage of Delegation model across the project # Search for imports of the Delegation model echo "Searching for imports of the Delegation model:" rg --type ts "import.*Delegation.*from.*delegation\.model" # Search for uses of the Delegation class echo "\nSearching for uses of the Delegation class:" rg --type ts "new Delegation\(" -A 5Length of output: 2106
Script:
#!/bin/bash # Description: Further check usage patterns of Delegation model # Search for class inheritance echo "Searching for classes that extend Delegation:" rg --type ts "extends Delegation" # Search for static method calls on Delegation echo "\nSearching for static method calls on Delegation:" rg --type ts "Delegation\." # Search for Delegation used as a type in type annotations echo "\nSearching for Delegation used as a type in type annotations:" rg --type ts ": Delegation\b"Length of output: 15190
apps/services/auth/admin-api/src/app/v2/delegations/test/delegation-admin.spec.ts (1)
342-419
: Excellent addition of test cases for duplicate delegation prevention.These new test cases significantly enhance the robustness of the delegation creation process by covering scenarios where duplicates based on national IDs or reference IDs are attempted. They adhere well to NestJS testing practices and contribute to a more comprehensive test suite.
The additions align well with the PR objectives of implementing checks for existing delegations before insertion. These tests will help ensure that the new error handling for delegation insertion failures works as expected.
libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts (2)
32-32
: ImportingOp
fromsequelize
is appropriate for query operatorsThe addition of
Op
enables the use of Sequelize operators in queries, which is necessary for the new validation logic.
307-319
: Query logic correctly checks for existing delegationsThe implemented query uses
Op.or
to check for existing delegations based on either matchingfromNationalId
andtoNationalId
, or matchingreferenceId
. This effectively prevents duplicate delegations from being created.
libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts
Show resolved
Hide resolved
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #16420 +/- ##
==========================================
- Coverage 36.75% 36.72% -0.03%
==========================================
Files 6835 6835
Lines 141321 141330 +9
Branches 40235 40266 +31
==========================================
- Hits 51940 51904 -36
- Misses 89381 89426 +45 Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Datadog ReportAll test runs ✅ 68 Total Test Services: 0 Failed, 65 Passed Test ServicesThis report shows up to 10 services
🔻 Code Coverage Decreases vs Default Branch (3) |
There was a problem hiding this 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/src/lib/messages.ts (1)
162-169
: LGTM! Consider exporting individual messages for better tree-shaking.The new message definitions for
couldNotCreateDelegationError
andreferenceIdAlreadyExistsError
are correctly implemented and follow the existing patterns in the file. They are properly defined for internationalization and maintain consistency with other messages.To improve tree-shaking and bundling practices, consider exporting individual messages instead of the entire object. This allows consumers to import only the messages they need. Here's an example of how you could refactor this:
export const couldNotCreateDelegationError = { id: 'admin.delegationAdmin:couldNotCreateDelegationError', defaultMessage: 'Umboð var ekki hægt að skrá', }; export const referenceIdAlreadyExistsError = { id: 'admin.delegationAdmin:referenceIdAlreadyExistsError', defaultMessage: 'Númer máls í Zendesk er þegar til', }; // ... other individual message exports export const allMessages = { couldNotCreateDelegationError, referenceIdAlreadyExistsError, // ... other messages };This approach allows for more granular imports and better tree-shaking while maintaining the ability to import all messages if needed.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
- libs/portals/admin/delegation-admin/src/constants/errors.ts (1 hunks)
- libs/portals/admin/delegation-admin/src/lib/messages.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/portals/admin/delegation-admin/src/constants/errors.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/admin/delegation-admin/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."
🔇 Additional comments (1)
libs/portals/admin/delegation-admin/src/constants/errors.ts (1)
15-16
: LGTM! The new error codes enhance error handling for delegation creation.The additions to the
FORM_ERRORS
constant are well-structured and consistent with the existing pattern. They directly support the PR's objective of improving error handling when checking for existing delegations. The use of TypeScript for defining the record type aligns with the coding guidelines for files in thelibs
directory.These centralized error messages contribute to the reusability of components across different NextJS apps, which is a key guideline for code in the
libs
directory.
What
Check if delegation exists before trying to insert it to the db
Why
To return relevant error messages.
Screenshots / Gifs
Attach Screenshots / Gifs to help reviewers understand the scope of the pull request
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes