-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Make OpenApp a write command #37062
Make OpenApp a write command #37062
Changes from all commits
0a926b4
456cc9f
80312e1
1869a6b
53feadb
e22fa7d
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
import CONST from '../../src/CONST'; | ||
import * as App from '../../src/libs/actions/App'; | ||
import OnyxUpdateManager from '../../src/libs/actions/OnyxUpdateManager'; | ||
import * as PersistedRequests from '../../src/libs/actions/PersistedRequests'; | ||
import * as PersonalDetails from '../../src/libs/actions/PersonalDetails'; | ||
import * as Session from '../../src/libs/actions/Session'; | ||
import HttpUtils from '../../src/libs/HttpUtils'; | ||
import Log from '../../src/libs/Log'; | ||
|
@@ -101,8 +101,7 @@ describe('NetworkTests', () => { | |
); | ||
|
||
// This should first trigger re-authentication and then a Failed to fetch | ||
App.confirmReadyToOpenApp(); | ||
App.openApp(); | ||
PersonalDetails.openPersonalDetails(); | ||
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. Ah I see we just picked a flow arbitrarily to confirm the re-auth behavior? Looks good! |
||
return waitForBatchedUpdates() | ||
.then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false})) | ||
.then(() => { | ||
|
@@ -113,11 +112,11 @@ describe('NetworkTests', () => { | |
return waitForBatchedUpdates(); | ||
}) | ||
.then(() => { | ||
// Then we will eventually have 3 calls to chatList and 2 calls to Authenticate | ||
const callsToOpenApp = _.filter(HttpUtils.xhr.mock.calls, ([command]) => command === 'OpenApp'); | ||
// Then we will eventually have 1 call to OpenPersonalDetailsPage and 1 calls to Authenticate | ||
const callsToOpenPersonalDetails = _.filter(HttpUtils.xhr.mock.calls, ([command]) => command === 'OpenPersonalDetailsPage'); | ||
const callsToAuthenticate = _.filter(HttpUtils.xhr.mock.calls, ([command]) => command === 'Authenticate'); | ||
|
||
expect(callsToOpenApp.length).toBe(1); | ||
expect(callsToOpenPersonalDetails.length).toBe(1); | ||
expect(callsToAuthenticate.length).toBe(1); | ||
}); | ||
}); | ||
|
@@ -137,7 +136,7 @@ describe('NetworkTests', () => { | |
HttpUtils.xhr = jest.fn(); | ||
HttpUtils.xhr | ||
|
||
// And mock the first call to OpenApp return with an expired session code | ||
// And mock the first call to openPersonalDetails return with an expired session code | ||
.mockImplementationOnce(() => | ||
Promise.resolve({ | ||
jsonCode: CONST.JSON_CODE.NOT_AUTHENTICATED, | ||
|
@@ -165,20 +164,20 @@ describe('NetworkTests', () => { | |
}), | ||
); | ||
|
||
// And then make 3 API requests in quick succession with an expired authToken and handle the response | ||
// And then make 3 API READ requests in quick succession with an expired authToken and handle the response | ||
// It doesn't matter which requests these are really as all the response is mocked we just want to see | ||
// that we get re-authenticated | ||
App.openApp(); | ||
App.openApp(); | ||
App.openApp(); | ||
PersonalDetails.openPersonalDetails(); | ||
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. I had to use a READ command here to make the test pass. It seems like this behaves differently when we call a write command. 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. I tested this scenario though of a write command with an expired authToken and I was re-authenticated properly. 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. Could you please update the comment above here that says "make 3 API requests" to specifically say that they are READ requests? 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. On it. |
||
PersonalDetails.openPersonalDetails(); | ||
PersonalDetails.openPersonalDetails(); | ||
return waitForBatchedUpdates(); | ||
}) | ||
.then(() => { | ||
// We should expect to see the three calls to OpenApp, but only one call to Authenticate. | ||
// And we should also see the reconnection callbacks triggered. | ||
const callsToOpenApp = _.filter(HttpUtils.xhr.mock.calls, ([command]) => command === 'OpenApp'); | ||
const callsToOpenPersonalDetails = _.filter(HttpUtils.xhr.mock.calls, ([command]) => command === 'OpenPersonalDetailsPage'); | ||
const callsToAuthenticate = _.filter(HttpUtils.xhr.mock.calls, ([command]) => command === 'Authenticate'); | ||
expect(callsToOpenApp.length).toBe(3); | ||
expect(callsToOpenPersonalDetails.length).toBe(3); | ||
expect(callsToAuthenticate.length).toBe(1); | ||
expect(reconnectionCallbacksSpy.mock.calls.length).toBe(3); | ||
}); | ||
|
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.
probably unrelated, but I am completely confused about what a "skew calculation" refers to here. I see these changes, but did not have an opportunity to make sense of them yet.