Skip to content

test(keeper): add utils.test.js for parseAsyncAPIDocumentFromFile#1959

Closed
moksha-hub wants to merge 2 commits intoasyncapi:masterfrom
moksha-hub:test/add-utils-tests-1955
Closed

test(keeper): add utils.test.js for parseAsyncAPIDocumentFromFile#1959
moksha-hub wants to merge 2 commits intoasyncapi:masterfrom
moksha-hub:test/add-utils-tests-1955

Conversation

@moksha-hub
Copy link

@moksha-hub moksha-hub commented Feb 9, 2026

Adds comprehensive test coverage for the parseAsyncAPIDocumentFromFile utility function:

  • Input validation tests for null, undefined, empty string, whitespace, number, object, and array inputs
  • Error wrapping tests to verify parser errors are properly wrapped
  • Happy path tests for successful document parsing

Closes #1955

Description

  • ...
  • ...
  • ...

Related issue(s)

Summary by CodeRabbit

  • Tests
    • Added a comprehensive test suite for AsyncAPI document parsing: validates rejection of invalid input with exact error messages, ensures parser errors are wrapped while preserving original details, and verifies successful parsing with expected document info (title, version) and presence of channels.

Adds comprehensive test coverage for the parseAsyncAPIDocumentFromFile utility function:

- Input validation tests for null, undefined, empty string, whitespace, number, object, and array inputs
- Error wrapping tests to verify parser errors are properly wrapped
- Happy path tests for successful document parsing

Closes asyncapi#1955
@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2026

⚠️ No Changeset found

Latest commit: 7c2946d

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

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.

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

@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

Adds a new test suite for parseAsyncAPIDocumentFromFile that verifies input validation for invalid asyncapiFilepath values, ensures parser errors are wrapped with a standardized message preserving original details, and asserts successful parsing of a valid AsyncAPI file.

Changes

Cohort / File(s) Summary
Test Suite for parseAsyncAPIDocumentFromFile
apps/keeper/test/utils.test.js
Adds tests validating input rejection for null/undefined/empty/whitespace/non-string asyncapiFilepath, tests that parser errors are rethrown with "Failed to parse AsyncAPI document" plus original details, and a happy-path test asserting parsed document fields (info.title, version, channels).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses Conventional Commits format (test scope) with imperative mood and clearly describes the main change: adding a test file for the parseAsyncAPIDocumentFromFile utility.
Linked Issues check ✅ Passed The PR fully addresses the two primary coding objectives from issue #1955: input validation tests for invalid asyncapiFilepath values and error wrapping behavior verification.
Out of Scope Changes check ✅ Passed All changes are scoped to adding test coverage for parseAsyncAPIDocumentFromFile as required by issue #1955; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
apps/keeper/test/utils.test.js (1)

9-49: Consider test.each to reduce repetition across input-validation cases.

All seven tests assert the same error message with different inputs. A parameterized table would consolidate them and make adding new cases trivial.

♻️ Suggested refactor
-        test('should throw error if asyncapiFilepath is null', async () => {
-            await expect(parseAsyncAPIDocumentFromFile(null)).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is undefined', async () => {
-            await expect(parseAsyncAPIDocumentFromFile(undefined)).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is empty string', async () => {
-            await expect(parseAsyncAPIDocumentFromFile('')).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is whitespace only', async () => {
-            await expect(parseAsyncAPIDocumentFromFile('   ')).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is a number', async () => {
-            await expect(parseAsyncAPIDocumentFromFile(123)).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is an object', async () => {
-            await expect(parseAsyncAPIDocumentFromFile({ path: 'test.yml' })).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is an array', async () => {
-            await expect(parseAsyncAPIDocumentFromFile(['test.yml'])).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
+        test.each([
+            ['null', null],
+            ['undefined', undefined],
+            ['empty string', ''],
+            ['whitespace only', '   '],
+            ['a number', 123],
+            ['an object', { path: 'test.yml' }],
+            ['an array', ['test.yml']],
+        ])('should throw error if asyncapiFilepath is %s', async (_label, value) => {
+            await expect(parseAsyncAPIDocumentFromFile(value)).rejects.toThrow(
+                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
+            );
+        });

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.

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 `@apps/keeper/test/utils.test.js`:
- Around line 59-66: The test "should include file-related error details in
wrapped message" uses the removed Jasmine global fail() and duplicates an
earlier assertion; either delete this redundant test or rewrite it to use Jest's
rejects pattern and assert file details: replace the try/catch + fail usage with
await
expect(parseAsyncAPIDocumentFromFile(invalidAsyncapiPath)).rejects.toThrow(expect.stringContaining('Failed
to parse AsyncAPI document')) and add an assertion that the error message
contains invalidAsyncapiPath (or other file-related details) to match the test
description; reference parseAsyncAPIDocumentFromFile and the test name when
locating the code to change.
🧹 Nitpick comments (1)
apps/keeper/test/utils.test.js (1)

8-50: Consider using test.each to reduce repetition.

All seven input validation tests share the same assertion logic. A parameterized table would be more concise and easier to extend.

♻️ Suggested refactor
-    describe('Input Validation', () => {
-        test('should throw error if asyncapiFilepath is null', async () => {
-            await expect(parseAsyncAPIDocumentFromFile(null)).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is undefined', async () => {
-            await expect(parseAsyncAPIDocumentFromFile(undefined)).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is empty string', async () => {
-            await expect(parseAsyncAPIDocumentFromFile('')).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is whitespace only', async () => {
-            await expect(parseAsyncAPIDocumentFromFile('   ')).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is a number', async () => {
-            await expect(parseAsyncAPIDocumentFromFile(123)).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is an object', async () => {
-            await expect(parseAsyncAPIDocumentFromFile({ path: 'test.yml' })).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-
-        test('should throw error if asyncapiFilepath is an array', async () => {
-            await expect(parseAsyncAPIDocumentFromFile(['test.yml'])).rejects.toThrow(
-                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
-            );
-        });
-    });
+    describe('Input Validation', () => {
+        test.each([
+            ['null', null],
+            ['undefined', undefined],
+            ['empty string', ''],
+            ['whitespace only', '   '],
+            ['a number', 123],
+            ['an object', { path: 'test.yml' }],
+            ['an array', ['test.yml']],
+        ])('should throw error if asyncapiFilepath is %s', async (_label, input) => {
+            await expect(parseAsyncAPIDocumentFromFile(input)).rejects.toThrow(
+                'Invalid "asyncapiFilepath" parameter: must be a non-empty string'
+            );
+        });
+    });

Addresses CodeRabbit review feedback:
- Removed fail() which is not available in Jest 27+
- Replaced with rejects.toThrow pattern using expect.objectContaining
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 9, 2026

@SHUBHANSHU602
Copy link
Contributor

hey @moksha-hub , here in this repo we wait for maintainer to approve the issue first , also I have shown interest in solving the issue so please close you PR and read the contribution guidelines. Thanks!

@moksha-hub
Copy link
Author

@SHUBHANSHU602 Thanks for information, I was misunderstood earlier about the guidelines and for now as I opened it and worked on raising the PR I wish not to close, and wait for decision takers or assigners to take any further actions.
Thank you.

@Adi-204
Copy link
Member

Adi-204 commented Feb 11, 2026

Thanks for the contribution. I’m closing this PR because, while there is an existing issue, it was not approved or opened for contribution before the pull request was submitted.

Please make sure to follow the contribution guidelines, which explain when issues are considered ready for implementation and when pull requests are appropriate

@Adi-204 Adi-204 closed this Feb 11, 2026
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.

[test]:Add missing tests for input validation and error wrapping in utilis.js

4 participants