Repository navigation
Fix not found page appears when enabling policy feature offline #57486
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
Changes from all commits
1489eb2
0128952
f3505cb
8f41573
632b229
69bf6d9
4623d1b
57f7496
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import * as ErrorUtils from '@libs/ErrorUtils'; | |
| import getIsNarrowLayout from '@libs/getIsNarrowLayout'; | ||
| import {getDistanceRateCustomUnit, goBackWhenEnableFeature, removePendingFieldsFromCustomUnit} from '@libs/PolicyUtils'; | ||
| import * as ReportUtils from '@libs/ReportUtils'; | ||
| import {resolveEnableFeatureConflicts} from '@userActions/RequestConflictUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Policy, Report} from '@src/types/onyx'; | ||
|
|
@@ -163,7 +164,9 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) { | |
|
|
||
| const parameters: EnablePolicyDistanceRatesParams = {policyID, enabled}; | ||
|
|
||
| API.write(WRITE_COMMANDS.ENABLE_POLICY_DISTANCE_RATES, parameters, onyxData); | ||
| API.write(WRITE_COMMANDS.ENABLE_POLICY_DISTANCE_RATES, parameters, onyxData, { | ||
| checkAndFixConflictingRequest: (persistedRequests) => resolveEnableFeatureConflicts(WRITE_COMMANDS.ENABLE_POLICY_DISTANCE_RATES, persistedRequests, parameters), | ||
| }); | ||
|
Comment on lines
+167
to
+169
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check caused inconsistencies in data updates #68739 |
||
|
|
||
| if (enabled && getIsNarrowLayout()) { | ||
| goBackWhenEnableFeature(policyID); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -581,6 +581,33 @@ describe('APITests', () => { | |
| }); | ||
| }); | ||
|
|
||
| test('All write requests are in the queue should be called even some of them are the same', () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@suneox This test fails when I use Date.now() because three APIs are called almost the same time.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you try to mockImplementation for Date.now with a manually increasing time value?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @suneox I think we can't because the implementation is executed when the mock is called, while the request is initialized when we call
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I got it. Thanks for the explanation |
||
| // Given offline state where all requests will eventualy succeed without issue | ||
| const xhr = jest.spyOn(HttpUtils, 'xhr').mockResolvedValue({jsonCode: CONST.JSON_CODE.SUCCESS}); | ||
| return Onyx.multiSet({ | ||
| [ONYXKEYS.SESSION]: {authToken: 'anyToken'}, | ||
| [ONYXKEYS.NETWORK]: {isOffline: true}, | ||
| [ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin: 'test_user', autoGeneratedPassword: 'psswd'}, | ||
| }) | ||
| .then(() => { | ||
| // When we queue 3 persistable commands and two of them are the same | ||
| API.write<WriteCommand>('MockCommand' as WriteCommand, {content: 'value1'} as ApiRequestCommandParameters[WriteCommand]); | ||
| API.write<WriteCommand>('MockCommand' as WriteCommand, {content: 'value2'} as ApiRequestCommandParameters[WriteCommand]); | ||
| API.write<WriteCommand>('MockCommand' as WriteCommand, {content: 'value1'} as ApiRequestCommandParameters[WriteCommand]); | ||
|
|
||
| return waitForBatchedUpdates(); | ||
| }) | ||
| .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false})) | ||
| .then(waitForBatchedUpdates) | ||
| .then(() => { | ||
| // Then expect all 3 calls to have been made and for the Writes to be made in the order that we made them | ||
| expect(xhr.mock.calls.length).toBe(3); | ||
| expect(xhr.mock.calls.at(0)?.[1].content).toBe('value1'); | ||
| expect(xhr.mock.calls.at(1)?.[1].content).toBe('value2'); | ||
| expect(xhr.mock.calls.at(2)?.[1].content).toBe('value1'); | ||
| }); | ||
| }); | ||
|
|
||
| test('Read request should not stuck when SequentialQueue is paused and resumed', async () => { | ||
| // Given 2 WRITE requests and 1 READ request where the first write request pauses the SequentialQueue | ||
| const xhr = jest.spyOn(HttpUtils, 'xhr').mockResolvedValueOnce({previousUpdateID: 1}); | ||
|
|
||

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.
I think we should update this to use a unique timestamp with
Date.now()for this variable