Skip to content

Add unit tests for publisher Resources operationUtils - #1406

Open
Gayuth-W wants to merge 1 commit into
wso2:mainfrom
Gayuth-W:test/add-missing-test
Open

Add unit tests for publisher Resources operationUtils#1406
Gayuth-W wants to merge 1 commit into
wso2:mainfrom
Gayuth-W:test/add-missing-test

Conversation

@Gayuth-W

Copy link
Copy Markdown

Purpose

operationUtils.js is used by the Resources page to parse and group API operations, but it didn't have any unit tests.

This PR adds tests for its main helper functions, with extra coverage for the different OpenAPI versions since parameter generation differs between OpenAPI 3.x and Swagger 2.0.

Changes

Adds source/Tests/Unit/operationUtils.test.js with 20 tests:

Function Covered
extractPathParameters OpenAPI 3.0 / 3.1 nested schema shape, Swagger 2.0 inline type shape, no parameter targets, unrecognised versions
getOperationScopes default security scheme, x-scope fallback, no scopes, unrecognised versions
mapAPIOperations target/verb keying, merging multiple verbs on one target
isSelectAll fully selected, partially selected, unselected path
getTaggedOperations tag grouping, Default bucket, silent skip for absent operations, API product delegation
getAPIProductTaggedOperations grouping by dependent API name, silent skip for absent operations

This PR only adds unit tests. No production code has been changed.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Operation utility test coverage

Layer / File(s) Summary
Definition helper behavior
portals/publisher/src/main/webapp/source/Tests/Unit/operationUtils.test.js
Tests version-specific path parameter extraction and operation scope resolution across OpenAPI and Swagger inputs.
Operation mapping and selection
portals/publisher/src/main/webapp/source/Tests/Unit/operationUtils.test.js
Tests target-and-verb mapping, merged target entries, and complete operation selection.
Tagged operation grouping
portals/publisher/src/main/webapp/source/Tests/Unit/operationUtils.test.js
Tests tag grouping, API-product dependent API grouping, default handling, warnings, and missing-operation skipping.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: ashera96, hisanhunais, piyumaldk

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes adding unit tests for publisher Resources operationUtils.
Description check ✅ Passed The description matches the changeset and accurately summarizes the new operationUtils test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
portals/publisher/src/main/webapp/source/Tests/Unit/operationUtils.test.js (1)

168-174: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Restore warning spies even when assertions fail.

mockRestore() runs after the assertions, so a thrown error can leave console.warn mocked and affect later tests. Use automatic cleanup in afterEach or a try/finally block.

Also applies to: 208-219

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@portals/publisher/src/main/webapp/source/Tests/Unit/operationUtils.test.js`
around lines 168 - 174, Ensure the console.warn spy created in the
getTaggedOperations tests is restored even when an assertion fails. Replace the
post-assertion mockRestore calls in the affected tests with automatic afterEach
cleanup or try/finally protection, covering both the shown test and the
additional tests around lines 208–219.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@portals/publisher/src/main/webapp/source/Tests/Unit/operationUtils.test.js`:
- Around line 117-138: Add a regression test in the isSelectAll suite using
expected verbs such as get/post and a selected set with the same count but
different names, asserting false. Update isSelectAll to compare each selected
verb name against the corresponding operation names, not only verb counts, while
preserving the existing full and partial selection behavior.

---

Nitpick comments:
In `@portals/publisher/src/main/webapp/source/Tests/Unit/operationUtils.test.js`:
- Around line 168-174: Ensure the console.warn spy created in the
getTaggedOperations tests is restored even when an assertion fails. Replace the
post-assertion mockRestore calls in the affected tests with automatic afterEach
cleanup or try/finally protection, covering both the shown test and the
additional tests around lines 208–219.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c041d824-cfa2-4b8f-bef5-ebb5dfb86e3d

📥 Commits

Reviewing files that changed from the base of the PR and between e1a5b81 and 52032c2.

📒 Files selected for processing (1)
  • portals/publisher/src/main/webapp/source/Tests/Unit/operationUtils.test.js

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.

1 participant