Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
youssef-lr committed Feb 25, 2024
1 parent 80312e1 commit 1869a6b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/unit/NetworkTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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';
Expand Down Expand Up @@ -137,7 +138,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,
Expand Down Expand Up @@ -168,17 +169,17 @@ describe('NetworkTests', () => {
// And then make 3 API 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();
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 callsToAReadCommand = _.filter(HttpUtils.xhr.mock.calls, ([command]) => command === 'OpenPersonalDetailsPage');
const callsToAuthenticate = _.filter(HttpUtils.xhr.mock.calls, ([command]) => command === 'Authenticate');
expect(callsToOpenApp.length).toBe(3);
expect(callsToAReadCommand.length).toBe(3);
expect(callsToAuthenticate.length).toBe(1);
expect(reconnectionCallbacksSpy.mock.calls.length).toBe(3);
});
Expand Down

0 comments on commit 1869a6b

Please sign in to comment.