-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Payment due @sobitneupane] Account for null values in prepareRequestPayload #87259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8753a42
exclude values when null
NikkiWines b845b82
add test file for prepareRequestPayload
NikkiWines aec962e
clean up tests
NikkiWines cc00f8a
use waitForBatchedUpdates
NikkiWines 6c61b42
try useRealTimers
NikkiWines b59748d
fix test
NikkiWines 03f18b5
Merge branch 'main' of github.com:Expensify/App into nikki-null-values
NikkiWines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import prepareRequestPayload from '@libs/prepareRequestPayload'; | ||
|
|
||
| describe('prepareRequestPayload', () => { | ||
| it('should append string values to FormData', async () => { | ||
| const formData = await prepareRequestPayload('TestCommand', {authToken: 'abc123', email: 'test@example.com'}, false); | ||
|
|
||
| expect(formData.get('authToken')).toBe('abc123'); | ||
| expect(formData.get('email')).toBe('test@example.com'); | ||
| }); | ||
|
|
||
| it('should omit null values from FormData instead of coercing them to the string "null"', async () => { | ||
| const formData = await prepareRequestPayload('TestCommand', {authToken: null, email: null, referer: 'ecash'}, false); | ||
|
|
||
| expect(formData.has('authToken')).toBe(false); | ||
| expect(formData.has('email')).toBe(false); | ||
| expect(formData.get('referer')).toBe('ecash'); | ||
| }); | ||
|
|
||
| it('should omit undefined values from FormData', async () => { | ||
| const formData = await prepareRequestPayload('TestCommand', {authToken: undefined, platform: 'web'}, false); | ||
|
|
||
| expect(formData.has('authToken')).toBe(false); | ||
| expect(formData.get('platform')).toBe('web'); | ||
| }); | ||
|
|
||
| it('should include falsy non-null/undefined values (0, false, empty string)', async () => { | ||
| const formData = await prepareRequestPayload('TestCommand', {count: 0, flag: false, label: ''}, false); | ||
|
|
||
| expect(formData.get('count')).toBe('0'); | ||
| expect(formData.get('flag')).toBe('false'); | ||
| expect(formData.get('label')).toBe(''); | ||
| }); | ||
|
|
||
| it('should return an empty FormData for an empty data object', async () => { | ||
| const formData = await prepareRequestPayload('TestCommand', {}, false); | ||
| const entries = Array.from(formData.entries()); | ||
|
|
||
| expect(entries).toHaveLength(0); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new
value === nullfilter drops explicit nulls from all requests, but some commands rely on sending a nullable field to clear server-side state. For example,SET_POLICY_TAG_APPROVERintentionally sendsapprover: nullwhen unselecting an approver (src/libs/actions/Policy/Tag.ts:1283-1289), and the param is defined as required-but-nullable (src/libs/API/parameters/SetPolicyTagApproverParams.ts:1-5). After this change, that key is omitted entirely, so the backend cannot distinguish “clear this value” from “no update,” which can leave stale data.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I'm pretty sure this behavior is broken for that flow (and others) then, since we're not passing null but rather the stringified version of it
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the web code, we'd just end up throwing an error here the value doesn't match the expected format 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, actually, with this fix the backend will check
Request::getString('approver')which will return''and thencreateOrUpdateApprovalRulereceives'', which will return false instrlenand give us the behavior we actually want - so this fixes that bug too :D