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

chore: Add transmission content values test #1200

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

oskogstad
Copy link
Collaborator

@oskogstad oskogstad commented Sep 26, 2024

Description

Adding test for required content on transmissions

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)

Summary by CodeRabbit

  • New Features

    • Added support for generating fake dialog transmissions with new parameters in dialog generation methods.
  • Bug Fixes

    • Introduced validation tests to ensure that dialog transmissions cannot be created without required content values.
  • Tests

    • Added new test cases to validate the creation of dialog transmissions under specific conditions.

@oskogstad oskogstad requested a review from a team as a code owner September 26, 2024 10:42
Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces modifications to the DialogGenerator class by adding a new optional parameter for transmission data to several methods related to generating fake dialogs. Additionally, it updates the Program.cs file to streamline method calls for consistency. New test cases are added to validate the creation of dialog transmissions under specific conditions, ensuring proper error handling for invalid input.

Changes

File Change Summary
src/Digdir.Tool.Dialogporten.GenerateFakeData/DialogGenerator.cs Added List<CreateDialogDialogTransmissionDto>? transmissions parameter to GenerateFakeDialog, GenerateFakeDialogs, and GenerateSimpleFakeDialog methods. Updated method signatures accordingly.
src/Digdir.Tool.Dialogporten.GenerateFakeData/Program.cs Modified RunAsync and ProduceDialogs methods to consolidate parameters for calls to GenerateFakeDialogs.
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs Added three test methods to validate dialog transmission creation, ensuring proper error handling for invalid input.

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

🧹 Outside diff range comments (2)
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs (1)

Line range hint 1-253: Overall assessment: Changes meet PR objectives and improve test coverage.

The added test cases effectively address the PR objective of introducing tests for required content on transmissions. They cover important scenarios:

  1. Attempting to create a transmission without content values.
  2. Attempting to create a transmission with empty localization values.

These tests enhance the project's ability to validate transmission content, which is crucial for ensuring data integrity and proper functionality.

To further strengthen the testing suite, consider adding the following test cases in the future:

  1. A test for mixed valid and invalid content (e.g., valid summary but empty title).
  2. A test for content with valid structure but invalid data (e.g., excessively long strings).
  3. A test for content with multiple localizations, including both valid and invalid entries.

These additional tests would provide more comprehensive coverage of potential edge cases in transmission content validation.

src/Digdir.Tool.Dialogporten.GenerateFakeData/DialogGenerator.cs (1)

Line range hint 246-265: LGTM: New method GenerateFakeDialogTransmissions added

The new GenerateFakeDialogTransmissions method is well-implemented and provides a good way to generate fake transmission data. It covers all necessary fields and allows for customization through optional parameters.

A minor suggestion for improvement:

Consider adding a constant or configuration value for the maximum number of transmissions instead of hardcoding 4 in the Generate call. This would make it easier to adjust the maximum count in the future if needed.

- .Generate(count ?? new Randomizer().Number(1, 4));
+ private const int MaxTransmissions = 4;
+ // ...
+ .Generate(count ?? new Randomizer().Number(1, MaxTransmissions));
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 8e570b4 and 3024c45.

📒 Files selected for processing (3)
  • src/Digdir.Tool.Dialogporten.GenerateFakeData/DialogGenerator.cs (5 hunks)
  • src/Digdir.Tool.Dialogporten.GenerateFakeData/Program.cs (2 hunks)
  • tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs (2 hunks)
🔇 Additional comments (7)
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs (1)

1-1: LGTM: New using directives are appropriate.

The added using directives for localization and transmission entities are necessary for the new test methods and are correctly placed at the beginning of the file.

Also applies to: 4-4

src/Digdir.Tool.Dialogporten.GenerateFakeData/Program.cs (3)

38-38: LGTM: Improved parameter ordering for better readability.

The consolidation of parameters in the DialogGenerator.GenerateFakeDialogs method call enhances code readability. Moving serviceResourceGenerator and partyGenerator to follow the count parameter creates a more logical flow and consistent style.


119-119: LGTM: Consistent parameter ordering, but clarification needed on .Take(dialogsToGenerate).

The parameter ordering in this DialogGenerator.GenerateFakeDialogs call is consistent with the change made in the RunAsync method, which is good for maintaining code style consistency throughout the file.

However, I noticed the addition of .Take(dialogsToGenerate) at the end of the method call. Can you clarify the purpose of this? It seems redundant since we're already specifying the count in the GenerateFakeDialogs method. Is there a scenario where the method might return more dialogs than requested?


Line range hint 1-265: Summary: Code improvements align with PR objectives, but verification needed for new tests.

The changes in this file improve code readability and consistency, which indirectly supports the PR objective of adding transmission content values test by enhancing the code that generates fake dialogs. However, I didn't see any new tests specifically for transmission content values as mentioned in the PR objectives.

Can you please verify if there are any new tests added in other files that specifically address the transmission content values? If not, consider adding such tests to fully meet the PR objectives.

src/Digdir.Tool.Dialogporten.GenerateFakeData/DialogGenerator.cs (3)

39-40: LGTM: Transmission support added to GenerateFakeDialog

The addition of the transmissions parameter to GenerateFakeDialog and its propagation to GenerateFakeDialogs is correct and consistent with the method's purpose. This change allows for optional transmission data to be included when generating a single fake dialog.

Also applies to: 64-65


90-91: LGTM: Transmission support added to GenerateFakeDialogs

The addition of the transmissions parameter to GenerateFakeDialogs and the new rule for generating fake dialog transmissions are correct and consistent with the method's purpose. This change allows for optional transmission data to be included when generating multiple fake dialogs, and it correctly uses the provided transmissions or generates new ones if not provided.

Also applies to: 113-113


127-128: LGTM: Transmission support added to GenerateSimpleFakeDialog

The addition of an empty transmissions list to GenerateSimpleFakeDialog is correct and consistent with the method's purpose of generating a simple fake dialog. This ensures that the method remains compatible with the updated GenerateFakeDialog signature while maintaining its simplicity.

Copy link

sonarcloud bot commented Sep 26, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
4.9% Duplication on New Code (required ≤ 3%)
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 3024c45 and 011c677.

📒 Files selected for processing (1)
  • tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs (2 hunks)
🔇 Additional comments (3)
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs (3)

230-251: LGTM: Well-implemented test for transmission without content values.

The test case correctly verifies that a transmission cannot be created with empty content values for summary and title, aligning with the PR objective. The implementation follows best practices and provides clear assertions.

As suggested in the previous review, consider adding a comment explaining why we expect exactly 2 validation errors. This would improve the test's readability and maintainability. For example:

// We expect 2 validation errors: one for empty summary and one for empty title
validationError.Errors
    .Count(e => e.PropertyName.Contains(nameof(createDialogCommand.Content)))
    .Should()
    .Be(2);

253-274: LGTM: Well-implemented test for transmission with empty content localization values.

The test case correctly verifies that a transmission cannot be created with empty localization values for summary and title, aligning with the PR objective. The implementation follows best practices and provides clear assertions.

As suggested in the previous review, consider adding a comment explaining why we expect exactly 2 validation errors. This would improve the test's readability and maintainability. For example:

// We expect 2 validation errors: one for empty summary localization and one for empty title localization
validationError.Errors
    .Count(e => e.PropertyName.Contains(nameof(createDialogCommand.Content)))
    .Should()
    .Be(2);

Line range hint 1-274: Overall, excellent addition of test cases for transmission content validation.

The new test methods effectively cover various scenarios for transmission content validation, aligning well with the PR objectives. They enhance the testing framework by ensuring that the necessary content values are validated during the transmission process.

To further improve the test suite:

  1. Consider adding tests for edge cases, such as partially filled content or content with only whitespace characters.
  2. Ensure that these tests are part of a comprehensive test strategy that covers all aspects of transmission content validation.

@oskogstad oskogstad merged commit d5729de into main Sep 26, 2024
21 of 22 checks passed
@oskogstad oskogstad deleted the chore/add-test-for-transmission-content branch September 26, 2024 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants