Skip to content
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

Add dedupe to logout requests #53143

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import * as PersistedRequests from '@libs/actions/PersistedRequests';
import {resolveDuplicationConflictAction} from '@libs/actions/RequestConflictUtils';
import * as API from '@libs/API';
import type {
AuthenticatePusherParams,
Expand Down Expand Up @@ -183,7 +184,14 @@ function signOut() {
shouldRetry: false,
};

API.write(WRITE_COMMANDS.LOG_OUT, params);
API.write(
WRITE_COMMANDS.LOG_OUT,
params,
{},
{
checkAndFixConflictingRequest: (persistedRequests) => resolveDuplicationConflictAction(persistedRequests, (request) => request.command === WRITE_COMMANDS.LOG_OUT),
},
);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/actions/SessionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PushNotification from '@libs/Notification/PushNotification';
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';
import type {Credentials, Session} from '@src/types/onyx';
import * as TestHelper from '../utils/TestHelper';
Expand Down Expand Up @@ -183,4 +184,24 @@ describe('Session', () => {

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

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

SessionUtil.signOut();
SessionUtil.signOut();
SessionUtil.signOut();
SessionUtil.signOut();
SessionUtil.signOut();

await waitForBatchedUpdates();

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

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

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