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: added id to attachments, ApiActions and GuiActions in DialogCreate #1670

Merged
merged 4 commits into from
Jan 13, 2025

Conversation

Fargekritt
Copy link
Contributor

Description

Added Id to Attachment, ApiActions and GuiActions in DialogCreate

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • Documentation is updated (either in docs-directory, Altinnpedia or a separate linked PR in altinn-studio-docs., if applicable)

@Fargekritt Fargekritt requested a review from a team as a code owner January 9, 2025 08:09
Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

📝 Walkthrough

Walkthrough

The pull request introduces comprehensive changes to the Dialogporten system, focusing on adding UUIDv7 identifier support across various components. The modifications span schema definitions, application logic, data transfer objects, and test scenarios. The primary objective is to enhance entity identification by implementing a consistent method for generating and validating unique identifiers, particularly for dialog-related entities such as attachments, API actions, and GUI actions. These changes improve the system's ability to handle idempotent operations and provide more robust data management.

Changes

File Path Change Summary
docs/schema/V1/swagger.verified.json Added id properties (UUIDv7) to multiple schemas for dialogs, actions, attachments, and transmissions
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs Added checks for existing IDs in new entity types like DialogAttachment, DialogGuiAction, and DialogApiAction
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs Added validation rules for Id properties, ensuring they are valid UUIDv7 with timestamps in the past
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs Added optional Guid? Id properties to ApiActionDto, GuiActionDto, and AttachmentDto
tests/k6/tests/enduser/all-tests.js Imported and added enduserSearchWithThresholds module to test execution
tests/k6/tests/serviceowner/all-tests.js Added imports for createDialogWithThresholds and serviceOwnerSearchWithThresholds
tests/k6/tests/serviceowner/dialogCreatePatchDelete.js Introduced new test cases for dialog creation with attachment IDs and added dialog ID tracking
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogDto.cs Updated comments for Id properties to clarify idempotent addition support
src/Digdir.Tool.Dialogporten.GenerateFakeData/DialogGenerator.cs Added ID generation rules for fake dialog API actions, GUI actions, and attachments

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a3f9fe9 and fbe5941.

📒 Files selected for processing (1)
  • docs/schema/V1/swagger.verified.json (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/schema/V1/swagger.verified.json
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Dry run deploy apps / Deploy job sync-resource-policy-information-job to test
  • GitHub Check: Dry run deploy apps / Deploy job sync-subject-resource-mappings-job to test
  • GitHub Check: build / build-and-test

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

sonarqubecloud bot commented Jan 9, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
16.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
tests/k6/tests/serviceowner/all-tests.js (1)

Line range hint 17-32: Consider adding threshold tests for ID-related operations.

Given that this PR adds ID attributes to Attachments, ApiActions, and GuiActions, consider:

  1. Adding specific threshold tests for concurrent operations with user-defined IDs
  2. Validating performance impact of ID validation and uniqueness checks

Would you like me to help create additional test scenarios for these cases?

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs (1)

149-165: Consider optimizing database queries for ID existence checks.

The implementation correctly validates the uniqueness of IDs for Attachments, GuiActions, and ApiActions. However, consider combining these database queries into a single operation to reduce the number of database roundtrips.

-        var existingAttachmentIds = await _db.GetExistingIds(dialog.Attachments, cancellationToken);
-        if (existingAttachmentIds.Count != 0)
-        {
-            _domainContext.AddError(DomainFailure.EntityExists<DialogAttachment>(existingAttachmentIds));
-        }
-
-        var existingGuiActionIds = await _db.GetExistingIds(dialog.GuiActions, cancellationToken);
-        if (existingGuiActionIds.Count != 0)
-        {
-            _domainContext.AddError(DomainFailure.EntityExists<DialogGuiAction>(existingGuiActionIds));
-        }
-
-        var existingApiActionIds = await _db.GetExistingIds(dialog.ApiActions, cancellationToken);
-        if (existingApiActionIds.Count != 0)
-        {
-            _domainContext.AddError(DomainFailure.EntityExists<DialogApiAction>(existingApiActionIds));
-        }
+        var (attachmentIds, guiActionIds, apiActionIds) = await Task.WhenAll(
+            _db.GetExistingIds(dialog.Attachments, cancellationToken),
+            _db.GetExistingIds(dialog.GuiActions, cancellationToken),
+            _db.GetExistingIds(dialog.ApiActions, cancellationToken)
+        );
+        
+        if (attachmentIds.Count != 0)
+            _domainContext.AddError(DomainFailure.EntityExists<DialogAttachment>(attachmentIds));
+        if (guiActionIds.Count != 0)
+            _domainContext.AddError(DomainFailure.EntityExists<DialogGuiAction>(guiActionIds));
+        if (apiActionIds.Count != 0)
+            _domainContext.AddError(DomainFailure.EntityExists<DialogApiAction>(apiActionIds));
tests/k6/tests/serviceowner/dialogCreatePatchDelete.js (1)

34-54: Consider adding test cases for GuiActions and ApiActions.

The test cases thoroughly cover attachment ID scenarios. However, since the PR objective includes adding IDs to GuiActions and ApiActions, consider adding similar test cases for these entities:

  • Dialog creation with specified GuiAction ID
  • Dialog creation with specified ApiAction ID
  • Error handling for duplicate GuiAction and ApiAction IDs
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a4a1a62 and a3759db.

📒 Files selected for processing (8)
  • docs/schema/V1/swagger.verified.json (4 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs (3 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs (3 hunks)
  • tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Queries/GetDialogTests.cs (1 hunks)
  • tests/k6/tests/enduser/all-tests.js (1 hunks)
  • tests/k6/tests/serviceowner/all-tests.js (3 hunks)
  • tests/k6/tests/serviceowner/dialogCreatePatchDelete.js (3 hunks)
🧰 Additional context used
📓 Learnings (2)
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Queries/GetDialogTests.cs (1)
Learnt from: elsand
PR: digdir/dialogporten#1529
File: tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs:29-32
Timestamp: 2024-11-25T18:06:11.188Z
Learning: The end-to-end tests cover the `serviceprovider.admin-scope` scenario for dialog creation, so additional unit tests are not necessary.
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs (1)
Learnt from: elsand
PR: digdir/dialogporten#1529
File: tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs:29-32
Timestamp: 2024-11-25T18:06:11.188Z
Learning: The end-to-end tests cover the `serviceprovider.admin-scope` scenario for dialog creation, so additional unit tests are not necessary.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Dry run deploy apps / Deploy service to test
  • GitHub Check: build / build-and-test
🔇 Additional comments (16)
tests/k6/tests/serviceowner/all-tests.js (2)

5-5: Verify the new test modules exist and follow conventions.

The new imports follow the established pattern, but let's verify that the modules exist and maintain consistent testing patterns.

Also applies to: 15-15

✅ Verification successful

Imports and test structure verified successfully

The new test modules follow the established k6 testing patterns with proper configuration, thresholds, and implementation separation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and structure of the new test modules

# Check if the new test files exist
fd "createDialogWithThresholds.js|serviceOwnerSearchWithThresholds.js" tests/k6/tests/serviceowner/

# Verify consistent testing patterns across modules
rg -l "export default function" tests/k6/tests/serviceowner/ | \
  xargs rg "import \{ check \}|import http from 'k6/http'" 

Length of output: 351


Script:

#!/bin/bash
# Description: Check the content of new test files for k6 patterns

# Display the content of both files to verify k6 imports and structure
echo "=== createDialogWithThresholds.js ==="
cat tests/k6/tests/serviceowner/createDialogWithThresholds.js

echo -e "\n=== serviceOwnerSearchWithThresholds.js ==="
cat tests/k6/tests/serviceowner/serviceOwnerSearchWithThresholds.js

Length of output: 1769


21-21: Consider test execution order and dependencies.

The new threshold tests are positioned at different points in the execution sequence. Please verify:

  1. Whether createDialogWithThresholds needs to run before other dialog-related tests
  2. If serviceOwnerSearchWithThresholds has any dependencies on previous test results

Also applies to: 31-31

✅ Verification successful

Tests are properly isolated, execution order is not critical

After analyzing the test implementations:

  1. Each test is self-contained with its own configuration and implementation
  2. No shared state or dependencies between createDialogWithThresholds and serviceOwnerSearchWithThresholds
  3. Tests can run independently in any order
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential dependencies between tests

# Look for shared resources or state between tests
rg -A 5 "export const dialogId|export const searchId" tests/k6/tests/serviceowner/

Length of output: 84


Script:

#!/bin/bash
# Get the content of the test file
cat tests/k6/tests/serviceowner/all-tests.js

# Also search for test group declarations and test functions
rg "group\(|export function" tests/k6/tests/serviceowner/all-tests.js

Length of output: 1759


Script:

#!/bin/bash
# Check the content of the threshold-related test files
cat tests/k6/tests/serviceowner/createDialogWithThresholds.js
cat tests/k6/tests/serviceowner/serviceOwnerSearchWithThresholds.js

Length of output: 1581

tests/k6/tests/enduser/all-tests.js (1)

5-5: LGTM!

The addition of the enduserSearchWithThresholds test module follows the established pattern of importing and invoking test modules.

Also applies to: 12-12

tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Queries/GetDialogTests.cs (1)

52-58: LGTM!

The test assertions have been correctly updated to exclude ID properties from comparison for Attachments, ApiActions, and GuiActions. This aligns with the PR objective of adding ID attributes to these entities.

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs (1)

12-12: LGTM!

The addition of the Actions namespace is necessary for the new entity types.

tests/k6/tests/serviceowner/dialogCreatePatchDelete.js (2)

18-20: LGTM!

The addition of variables to track dialog IDs and attachment ID is well-structured and necessary for the new test cases.


217-222: LGTM!

The cleanup section ensures proper test data management by purging all created dialogs.

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs (3)

272-274: LGTM! Proper validation for attachment Id.

The validation rules correctly ensure that the attachment Id is a valid UUIDv7 with a timestamp in the past, which is essential for idempotent operations.


342-344: LGTM! Proper validation for GUI action Id.

The validation rules correctly ensure that the GUI action Id is a valid UUIDv7 with a timestamp in the past, which is essential for idempotent operations.


374-376: LGTM! Proper validation for API action Id.

The validation rules correctly ensure that the API action Id is a valid UUIDv7 with a timestamp in the past, which is essential for idempotent operations.

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs (3)

318-322: LGTM! Well-documented Id property for API actions.

The Id property is properly defined as nullable with clear documentation explaining its purpose for merging existing data, including handling of unknown IDs.


402-406: LGTM! Well-documented Id property for GUI actions.

The Id property is properly defined as nullable with clear documentation explaining its purpose for merging existing data, including handling of unknown IDs.


470-473: LGTM! Well-documented Id property for attachments.

The Id property is properly defined as nullable with clear documentation explaining its purpose as a unique identifier in UUIDv7 format.

docs/schema/V1/swagger.verified.json (3)

2097-2103: LGTM! Proper schema definition for API action Id.

The schema correctly defines the Id property as a nullable GUID with appropriate description and example, matching the DTO definition.


2171-2176: LGTM! Proper schema definition for attachment Id.

The schema correctly defines the Id property as a nullable GUID with appropriate description and example, matching the DTO definition.


2448-2454: LGTM! Proper schema definition for GUI action Id.

The schema correctly defines the Id property as a nullable GUID with appropriate description and example, matching the DTO definition.

@Fargekritt Fargekritt changed the title Feat: added id to attachments, ApiActions and GuiActions in DialogCreate feat: added id to attachments, ApiActions and GuiActions in DialogCreate Jan 9, 2025
…achments.

Updated Doc comments on CreateDialogDto and UpdateDialogDto
@Fargekritt Fargekritt requested a review from a team as a code owner January 13, 2025 08:39
@Fargekritt Fargekritt merged commit 470e5a9 into main Jan 13, 2025
23 checks passed
@Fargekritt Fargekritt deleted the feat/add-id-to-attachments-actions branch January 13, 2025 13:00
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