Skip to content

test: add unit tests for modelspresets.js #1950

Merged
asyncapi-bot merged 8 commits intoasyncapi:masterfrom
Ishita-190:ishi
Feb 11, 2026
Merged

test: add unit tests for modelspresets.js #1950
asyncapi-bot merged 8 commits intoasyncapi:masterfrom
Ishita-190:ishi

Conversation

@Ishita-190
Copy link
Contributor

@Ishita-190 Ishita-190 commented Feb 8, 2026

Fixes: #1905

Description
Added comprehensive unit tests for the ModelsPresets.js component in the helpers package.

  • Created test/ModelsPresets.test.js with 12 test cases
image

Summary by CodeRabbit

  • Tests
    • Added comprehensive tests for model presets covering class, enum, and union handling, verifying package/import augmentation, import deduplication, and behavior for models with no properties or empty content.
  • Bug Fixes
    • Improved handling of models with missing properties to prevent runtime errors and ensure correct import collection.

@changeset-bot
Copy link

changeset-bot bot commented Feb 8, 2026

⚠️ No Changeset found

Latest commit: 280b8c0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@asyncapi-bot
Copy link
Contributor

What reviewer looks at during PR review

The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.

  1. PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means spoken or written as if giving a command or instruction, like "add new helper for listing operations")

    Note - In Generator, prepend feat: or fix: in PR title only when PATCH/MINOR release must be triggered.

  2. PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.

    Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes Resolves #<issue-number> or Fixes #<issue-number> this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow.

  3. Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.

  4. Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.

  5. DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.

  6. Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.

  7. Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.

  8. Template Design Principles Alignment: While reviewing template-related changes in the packages/ directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project.

  9. Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.

  10. Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@coderabbitai
Copy link

coderabbitai bot commented Feb 8, 2026

📝 Walkthrough

Walkthrough

Adds a new unit test suite for JavaModelsPresets and a small runtime guard in ModelsPresets to avoid iterating undefined model properties.

Changes

Cohort / File(s) Summary
Test Suite
packages/helpers/test/ModelsPresets.test.js
Adds a new test file (~+131 lines) asserting JavaModelsPresets exports an array of length 2; verifies first element contains JAVA_COMMON_PRESET with equal, hashCode, classToString true and marshalling false; exercises second element (websocketJavaPreset) for class.self, enum.self, and union.self covering package/import injection, Map<String, Object> import deduplication, models with no properties, and empty-content cases.
Runtime guard in source
packages/helpers/src/ModelsPresets.js
Small code change: iterate `Object.values(model.properties

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR fully addresses linked issue #1905 by adding comprehensive unit tests for ModelsPresets.js with 100% code coverage and testing all conditional branches.
Out of Scope Changes check ✅ Passed All changes are directly related to test coverage for ModelsPresets.js. The one-line fix in ModelsPresets.js (handling undefined properties) is necessary for test execution.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title follows Conventional Commits format with 'test:' prefix in imperative mood, clearly summarizing the addition of unit tests for modelspresets.js.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

We've launched Issue Planner and it is currently in beta. Please try it out and share your feedback on Discord!


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Adi-204 Adi-204 self-assigned this Feb 8, 2026
@Adi-204 Adi-204 moved this to In Progress in Maintainers work Feb 8, 2026
Copy link
Member

@Adi-204 Adi-204 left a comment

Choose a reason for hiding this comment

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

@Ishita-190 the testing are failing because of linting issue. The linting error is from SonarJS, which is complaining about duplicate string literals. I think it should be solve by defining constants at the top for all repeated strings. you can run npm run lint locally to see whether it is fix or not after changes it should pass. I hope it helps feel free to ask questions!

@Ishita-190
Copy link
Contributor Author

@Adi-204 thanks for pointing this out! I've made the changes, and ran all the tests again and everything seems to be running well. Let me know if any other changes need to be made.

Copy link

@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

🤖 Fix all issues with AI agents
In `@packages/helpers/test/ModelsPresets.test.js`:
- Around line 85-93: The test exposes that calling
Object.values(model.properties).forEach in the class preset will throw when
model.properties is undefined; to fix, update the source where that loop runs to
guard against null/undefined (e.g., replace
Object.values(model.properties).forEach(...) with Object.values(model.properties
|| {}).forEach(...)) and then adjust the test using websocketPreset.class.self
to expect no throw (keep the test asserting PACKAGE_DECLARATION, IMPORT_OBJECTS
and the class content); alternatively, if you prefer the error, change the test
to expect a TypeError via expect(() =>
websocketPreset.class.self(...)).toThrow(TypeError).
🧹 Nitpick comments (1)
packages/helpers/test/ModelsPresets.test.js (1)

39-39: Nit: websocketPreset is declared identically in three describe blocks.

You could hoist it to the top-level describe('ModelsPresets', ...) scope to reduce repetition. That said, keeping it local to each block is also a valid readability choice.

Also applies to: 97-97, 115-115

Copy link
Member

@Adi-204 Adi-204 left a comment

Choose a reason for hiding this comment

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

lgtm! @Ishita-190 can you please update PR description and add screenshot of test coverage
something like ss attach in PR #1952

@Ishita-190
Copy link
Contributor Author

@Adi-204 All done, please check!

@Ishita-190 Ishita-190 changed the title test: add unit tests for modelspresets.js (helpers package) test: add unit tests for modelspresets.js Feb 10, 2026
@sonarqubecloud
Copy link

@Adi-204
Copy link
Member

Adi-204 commented Feb 11, 2026

/rtm

@asyncapi-bot asyncapi-bot merged commit 6ae960e into asyncapi:master Feb 11, 2026
15 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Maintainers work Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants