Normalize authorized boolean to 1/0 in orders.all() (fixes dead normalizeBoolean)#483
Open
vku2018 wants to merge 1 commit into
Open
Normalize authorized boolean to 1/0 in orders.all() (fixes dead normalizeBoolean)#483vku2018 wants to merge 1 commit into
authorized boolean to 1/0 in orders.all() (fixes dead normalizeBoolean)#483vku2018 wants to merge 1 commit into
Conversation
`orders.all()` accepts `authorized` typed as `boolean | 1 | 0`, and the
Razorpay Orders API expects `1`/`0`. The method had a no-op self-assignment
`authorized = authorized` where the `normalizeBoolean` conversion was
clearly intended — as a result `normalizeBoolean` was exported but never
called anywhere in the library, and passing `authorized: true` sent the raw
boolean to the API instead of `1`.
The existing test only exercised `authorized: 1` (already binary), so its
own assertion message ("authorized to binary") passed by accident and the
bug went undetected.
Fix: use `authorized = normalizeBoolean(authorized)` (imported into
orders.js). `normalizeBoolean(undefined)` returns `undefined`, so callers
omitting the flag are unaffected; `1`/`0` pass through unchanged — backward
compatible.
Added tests exercising `authorized: true` -> 1 and `authorized: false` -> 0.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
orders.all()acceptsauthorized(typed asboolean | 1 | 0), and the Orders API expects1/0. The method contained a no-op self-assignment:where the
normalizeBooleanconversion was clearly intended. As a side effect,normalizeBooleanis exported fromrazorpay-utilsbut never called anywhere in the library. So passingauthorized: truesent the raw boolean to the API instead of1.The existing test only exercised
authorized: 1(already binary), so its own assertion message — "authorized to binary" — passed by accident and the bug slipped through.Fix
(imported into
orders.js).normalizeBoolean(undefined)returnsundefined, so callers that omit the flag are unaffected, and1/0pass through unchanged — backward compatible.Tests
Added tests exercising
authorized: true→1andauthorized: false→0. Verified they fail without the fix and pass with it. Full suite:386 passing.