Skip to content

fix(axios): map options.form to URL-encoded body in httpRequest (#196)#199

Open
SAY-5 wants to merge 3 commits into
node-strava:mainfrom
SAY-5:say5-axios-form-encoding
Open

fix(axios): map options.form to URL-encoded body in httpRequest (#196)#199
SAY-5 wants to merge 3 commits into
node-strava:mainfrom
SAY-5:say5-axios-form-encoding

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 11, 2026

Closes #196.

The requestaxios migration translated options.body to config.data but lost the options.form path. pushSubscriptions.create (and any other call site that hands the payload to the HTTP client as form) therefore POSTed an empty body, Strava's push_subscriptions endpoint silently rejected the request as missing required fields.

Restore the request-promise semantics: when options.form is present and options.body is not, build a URLSearchParams and set Content-Type: application/x-www-form-urlencoded. Existing body-based callers continue to use config.data unchanged.

Regression test should POST URL-encoded fields, not an empty body captures the POST body via nock and asserts each form field round-trips, fails on main with actual undefined, passes after the fix. Existing 8 pushSubscriptions tests + eslint also green.

Summary by CodeRabbit

  • Bug Fixes

    • Form-encoded requests now include the request body and set the correct application/x-www-form-urlencoded Content-Type header, resolving cases where form payloads were previously sent empty.
  • Tests

    • Added a regression test to confirm push subscription requests are URL-encoded and include required form fields.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 48baf083-8d4e-432e-96b5-19b83431d707

📥 Commits

Reviewing files that changed from the base of the PR and between 0620fa3 and 3750a78.

📒 Files selected for processing (2)
  • axiosUtility.js
  • test/pushSubscriptions.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • axiosUtility.js
  • test/pushSubscriptions.js

📝 Walkthrough

Walkthrough

The PR adds form data support to the axios utility by serializing options.form to URLSearchParams when options.body is undefined and setting Content-Type: application/x-www-form-urlencoded. A regression test verifies pushSubscriptions.create sends the expected URL-encoded form fields.

Changes

Form Data Support for axios Migration

Layer / File(s) Summary
Form Data Serialization
axiosUtility.js
httpRequest detects options.form with undefined options.body, converts form fields to URLSearchParams, assigns to config.data, and sets Content-Type: application/x-www-form-urlencoded.
Regression Test
test/pushSubscriptions.js
Adds a test for pushSubscriptions.create that intercepts the POST, asserts Content-Type: application/x-www-form-urlencoded, verifies the body is non-empty, and checks for callback_url, verify_token, client_id, and client_secret fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through headers, params in hand,

URLSearchParams now tidy and planned,
No more empty posts lost in the night,
A test that catches the form-data right,
Hooray — the migration now sends it polite.

🚥 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 'fix(axios): map options.form to URL-encoded body in httpRequest' accurately and specifically summarizes the primary change: restoring form-to-URL-encoded body mapping in the axios utility.
Linked Issues check ✅ Passed The code changes fully address issue #196's requirements by implementing form-to-URLSearchParams conversion with proper Content-Type headers and adding a regression test that verifies form fields round-trip correctly.
Out of Scope Changes check ✅ Passed All changes are directly scoped to restoring form handling in axiosUtility and validating it via regression test; no out-of-scope modifications detected.
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 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 and usage tips.

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.

Axios ensureSubscription regression

1 participant