Skip to content

Fix sharing methods failing with 404 due to double-applied query params#197

Merged
ggoranov-smar merged 2 commits into
mainlinefrom
fix/195-sharing-query-params
Jul 21, 2026
Merged

Fix sharing methods failing with 404 due to double-applied query params#197
ggoranov-smar merged 2 commits into
mainlinefrom
fix/195-sharing-query-params

Conversation

@ggoranov-smar

@ggoranov-smar ggoranov-smar commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #195. All sharing.* methods failed with 404 Not Found (errorCode 1006) against the real API because each method baked assetType/assetId into the request URL string and passed queryParameters through to the generic HTTP requestor, which re-applied them via axios params. The result was a duplicated, malformed query string (and a leading double-slash from baseUrl = '/shares'), which the API could not route.

  • Reworked all five methods (listAssetShares, getAssetShare, shareAsset, updateAssetShare, deleteAssetShare) to follow the reports module pattern: a path-only url plus queryParameters serialized once by the requestor.
  • Added a patch method to lib/utils/httpRequestor.js. updateAssetShare called requestor.patch(...), which did not exist — the method threw at runtime regardless of the query-param bug.
  • Added mock API tests for all five sharing endpoints under test/mock-api/sharing/.

Proof of fix

Capturing the exact wire URL the SDK emits, before vs. after:

Before (buggy):

POST   https://api.smartsheet.com/2.0//shares?assetType=workspace&assetId=123&assetType=workspace&assetId=123

After (fixed):

POST   https://api.smartsheet.com/2.0/shares?assetType=workspace&assetId=123

The fixed URL matches the known-working curl from the issue exactly.

Test plan

  • npm run build succeeds
  • npx jest test/mock-api/sharing — 24 tests pass across 5 suites (requires WireMock on :8082)
  • Full suite green — 2084 tests pass, no regressions from the shared httpRequestor.js change
  • npx eslint — 0 errors on changed files

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Resolved 404 Not Found errors caused by Sharing API query parameters being applied twice.
    • Fixed runtime failures when updating asset shares.
  • Tests
    • Expanded Sharing API mock coverage (list, get, share, update, delete) with request URL/query validation, response shape checks, and 400/500 error handling.

All sharing.* methods (listAssetShares, getAssetShare, shareAsset,
updateAssetShare, deleteAssetShare) baked assetType/assetId into the
request URL and then passed queryParameters through to the HTTP layer,
which re-applied them via axios params. This produced a duplicated,
malformed query string and a leading double-slash, causing the API to
return 404 Not Found.

URL construction now follows the reports module pattern: a path-only
url plus queryParameters serialized once by the requestor. Also adds a
patch method to httpRequestor so updateAssetShare (PATCH) works, and
adds mock API tests for all five sharing endpoints.

Fixes #195

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a5226c5c-27cb-4584-ab8a-ee6736cca83a

📥 Commits

Reviewing files that changed from the base of the PR and between 0193f2a and 59fe919.

📒 Files selected for processing (6)
  • test/mock-api/sharing/common_test_constants.ts
  • test/mock-api/sharing/delete_asset_share.spec.ts
  • test/mock-api/sharing/get_asset_share.spec.ts
  • test/mock-api/sharing/list_asset_shares.spec.ts
  • test/mock-api/sharing/share_asset.spec.ts
  • test/mock-api/sharing/update_asset_share.spec.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • test/mock-api/sharing/get_asset_share.spec.ts
  • test/mock-api/sharing/common_test_constants.ts
  • test/mock-api/sharing/share_asset.spec.ts
  • test/mock-api/sharing/delete_asset_share.spec.ts
  • test/mock-api/sharing/update_asset_share.spec.ts
  • test/mock-api/sharing/list_asset_shares.spec.ts

📝 Walkthrough

Walkthrough

Sharing methods now delegate query serialization to request options, updateAssetShare uses exposed PATCH support, and mock API tests cover request formatting, payloads, responses, and error handling for all sharing endpoints.

Changes

Sharing API fixes and validation

Layer / File(s) Summary
Request paths and PATCH transport
lib/sharing/index.ts, lib/utils/httpRequestor.js, CHANGELOG.md
Sharing endpoints use path overrides instead of manually concatenated query strings; the requestor now exposes patch; release notes document both fixes.
Sharing endpoint validation
test/mock-api/sharing/*
Shared fixtures and WireMock tests validate endpoint paths, methods, query parameters, request bodies, response shapes, and 400/500 errors.

Estimated code review effort: 3 (Moderate) | ~20 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 accurately summarizes the main fix: sharing methods were failing with 404 because query parameters were applied twice.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/195-sharing-query-params

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

@coveralls

coveralls commented Jul 21, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 29838576193

Warning

No base build found for commit 290af66 on mainline.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 97.619%

Details

  • Patch coverage: 12 of 12 lines across 2 files are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 1274
Covered Lines: 1255
Line Coverage: 98.51%
Relevant Branches: 238
Covered Branches: 221
Branch Coverage: 92.86%
Branches in Coverage %: Yes
Coverage Strength: 1788.14 hits per line

💛 - Coveralls

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@test/mock-api/sharing/list_asset_shares.spec.ts`:
- Around line 51-57: Ensure each sharing request test asserts query-key
cardinality using searchParams.getAll(): add exactly one assetType and one
assetId assertion in test/mock-api/sharing/list_asset_shares.spec.ts:51-57,
test/mock-api/sharing/delete_asset_share.spec.ts:45-46,
test/mock-api/sharing/get_asset_share.spec.ts:40-41,
test/mock-api/sharing/share_asset.spec.ts:69-74, and
test/mock-api/sharing/update_asset_share.spec.ts:45-46, while retaining the
existing complete query-map assertions.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 12dc8fbf-b3e3-4650-b6e4-c81ed3218024

📥 Commits

Reviewing files that changed from the base of the PR and between 290af66 and 0193f2a.

📒 Files selected for processing (9)
  • CHANGELOG.md
  • lib/sharing/index.ts
  • lib/utils/httpRequestor.js
  • test/mock-api/sharing/common_test_constants.ts
  • test/mock-api/sharing/delete_asset_share.spec.ts
  • test/mock-api/sharing/get_asset_share.spec.ts
  • test/mock-api/sharing/list_asset_shares.spec.ts
  • test/mock-api/sharing/share_asset.spec.ts
  • test/mock-api/sharing/update_asset_share.spec.ts

Comment thread test/mock-api/sharing/list_asset_shares.spec.ts Outdated
Object.fromEntries() collapses repeated query keys, so the original
double-applied assetType/assetId bug would still satisfy the URL
assertions. Comparing parsedUrl.searchParams against an expected
URLSearchParams verifies key cardinality, making these real regression
tests for #195.

Addresses CodeRabbit review on PR #197.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ggoranov-smar
ggoranov-smar merged commit 9a17eaf into mainline Jul 21, 2026
6 checks passed
@ggoranov-smar
ggoranov-smar deleted the fix/195-sharing-query-params branch July 21, 2026 14:31
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.

sharing.shareAsset() (and other sharing.* methods) always 404 — queryParameters double-applied to URL

3 participants