Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Feb 8, 2025
1 parent 405981a commit 9bad6a2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
72 changes: 36 additions & 36 deletions tests/actions/SessionTest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {beforeEach, jest, test} from '@jest/globals';
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import * as App from '@libs/actions/App';
import {confirmReadyToOpenApp, openApp, reconnectApp} from '@libs/actions/App';
import OnyxUpdateManager from '@libs/actions/OnyxUpdateManager';
import {getAll as getAllPersistedRequests} from '@libs/actions/PersistedRequests';
import {WRITE_COMMANDS} from '@libs/API/types';
import HttpUtils from '@libs/HttpUtils';
import PushNotification from '@libs/Notification/PushNotification';
// This lib needs to be imported, but it has nothing to export since all it contains is an Onyx connection
import '@libs/Notification/PushNotification/subscribePushNotification';
import * as PersistedRequests from '@userActions/PersistedRequests';
import CONST from '@src/CONST';
import * as SessionUtil from '@src/libs/actions/Session';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -88,8 +88,8 @@ describe('Session', () => {
);

// When we attempt to fetch the initial app data via the API
App.confirmReadyToOpenApp();
App.openApp();
confirmReadyToOpenApp();
openApp();
await waitForBatchedUpdates();

// Then it should fail and reauthenticate the user adding the new authToken to the session
Expand All @@ -114,97 +114,97 @@ describe('Session', () => {
await Onyx.set(ONYXKEYS.HAS_LOADED_APP, true);
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true});

App.confirmReadyToOpenApp();
App.reconnectApp();
confirmReadyToOpenApp();
reconnectApp();

await waitForBatchedUpdates();

expect(PersistedRequests.getAll().length).toBe(1);
expect(PersistedRequests.getAll().at(0)?.command).toBe(WRITE_COMMANDS.RECONNECT_APP);
expect(getAllPersistedRequests().length).toBe(1);
expect(getAllPersistedRequests().at(0)?.command).toBe(WRITE_COMMANDS.RECONNECT_APP);

await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});

await waitForBatchedUpdates();

expect(PersistedRequests.getAll().length).toBe(0);
expect(getAllPersistedRequests().length).toBe(0);
});

test('ReconnectApp should open if app is not loaded', async () => {
await TestHelper.signInWithTestUser();
await Onyx.set(ONYXKEYS.HAS_LOADED_APP, false);
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true});

App.confirmReadyToOpenApp();
App.reconnectApp();
confirmReadyToOpenApp();
reconnectApp();

await waitForBatchedUpdates();

expect(PersistedRequests.getAll().length).toBe(1);
expect(PersistedRequests.getAll().at(0)?.command).toBe(WRITE_COMMANDS.OPEN_APP);
expect(getAllPersistedRequests().length).toBe(1);
expect(getAllPersistedRequests().at(0)?.command).toBe(WRITE_COMMANDS.OPEN_APP);

await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});

await waitForBatchedUpdates();

expect(PersistedRequests.getAll().length).toBe(0);
expect(getAllPersistedRequests().length).toBe(0);
});

test('ReconnectApp should replace same requests from the queue', async () => {
await TestHelper.signInWithTestUser();
await Onyx.set(ONYXKEYS.HAS_LOADED_APP, true);
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true});

App.confirmReadyToOpenApp();
App.reconnectApp();
App.reconnectApp();
App.reconnectApp();
App.reconnectApp();
confirmReadyToOpenApp();
reconnectApp();
reconnectApp();
reconnectApp();
reconnectApp();

await waitForBatchedUpdates();

expect(PersistedRequests.getAll().length).toBe(1);
expect(PersistedRequests.getAll().at(0)?.command).toBe(WRITE_COMMANDS.RECONNECT_APP);
expect(getAllPersistedRequests().length).toBe(1);
expect(getAllPersistedRequests().at(0)?.command).toBe(WRITE_COMMANDS.RECONNECT_APP);

await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});

expect(PersistedRequests.getAll().length).toBe(0);
expect(getAllPersistedRequests().length).toBe(0);
});

test('OpenApp should push request to the queue', async () => {
await TestHelper.signInWithTestUser();
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true});

App.openApp();
openApp();

await waitForBatchedUpdates();

expect(PersistedRequests.getAll().length).toBe(1);
expect(PersistedRequests.getAll().at(0)?.command).toBe(WRITE_COMMANDS.OPEN_APP);
expect(getAllPersistedRequests().length).toBe(1);
expect(getAllPersistedRequests().at(0)?.command).toBe(WRITE_COMMANDS.OPEN_APP);

await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});

await waitForBatchedUpdates();

expect(PersistedRequests.getAll().length).toBe(0);
expect(getAllPersistedRequests().length).toBe(0);
});

test('OpenApp should replace same requests from the queue', async () => {
await TestHelper.signInWithTestUser();
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true});

App.openApp();
App.openApp();
App.openApp();
App.openApp();
openApp();
openApp();
openApp();
openApp();

await waitForBatchedUpdates();

expect(PersistedRequests.getAll().length).toBe(1);
expect(PersistedRequests.getAll().at(0)?.command).toBe(WRITE_COMMANDS.OPEN_APP);
expect(getAllPersistedRequests().length).toBe(1);
expect(getAllPersistedRequests().at(0)?.command).toBe(WRITE_COMMANDS.OPEN_APP);

await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});

expect(PersistedRequests.getAll().length).toBe(0);
expect(getAllPersistedRequests().length).toBe(0);
});

test('LogOut should replace same requests from the queue instead of adding new one', async () => {
Expand All @@ -219,11 +219,11 @@ describe('Session', () => {

await waitForBatchedUpdates();

expect(PersistedRequests.getAll().length).toBe(1);
expect(PersistedRequests.getAll().at(0)?.command).toBe(WRITE_COMMANDS.LOG_OUT);
expect(getAllPersistedRequests().length).toBe(1);
expect(getAllPersistedRequests().at(0)?.command).toBe(WRITE_COMMANDS.LOG_OUT);

await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});

expect(PersistedRequests.getAll().length).toBe(0);
expect(getAllPersistedRequests().length).toBe(0);
});
});
10 changes: 5 additions & 5 deletions tests/unit/NetworkTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {Mock} from 'jest-mock';
import type {OnyxEntry} from 'react-native-onyx';
import MockedOnyx from 'react-native-onyx';
import TestToolMenu from '@components/TestToolMenu';
import * as App from '@libs/actions/App';
import {confirmReadyToOpenApp, reconnectApp} from '@libs/actions/App';
import {resetReauthentication} from '@libs/Middleware/Reauthentication';
import CONST from '@src/CONST';
import * as NetworkActions from '@src/libs/actions/Network';
Expand Down Expand Up @@ -166,8 +166,8 @@ describe('NetworkTests', () => {
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});

// Trigger reconnect which will fail due to expired token
App.confirmReadyToOpenApp();
App.reconnectApp();
confirmReadyToOpenApp();
reconnectApp();
await waitForBatchedUpdates();

// 4. First API Call Verification - Check ReconnectApp
Expand All @@ -184,8 +184,8 @@ describe('NetworkTests', () => {
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});

// 7.Trigger another reconnect due to network change
App.confirmReadyToOpenApp();
App.reconnectApp();
confirmReadyToOpenApp();
reconnectApp();

// 8. Now fail the pending authentication request
resolveAuthRequest(Promise.reject(new Error('Network request failed')));
Expand Down

0 comments on commit 9bad6a2

Please sign in to comment.