Skip to content

Commit

Permalink
fix: actions/OnyxUpdateManagerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispader committed Jan 7, 2025
1 parent 8b8d0d1 commit 3114a02
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/libs/actions/OnyxUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@ function doesClientNeedToBeUpdated({previousUpdateID, clientLastUpdateID}: DoesC
}

// eslint-disable-next-line import/prefer-default-export
export {apply, doesClientNeedToBeUpdated, saveUpdateInformation};
export {apply, doesClientNeedToBeUpdated, saveUpdateInformation, applyHTTPSOnyxUpdates as INTERNAL_DO_NOT_USE_applyHTTPSOnyxUpdates};
export type {DoesClientNeedToBeUpdatedParams as ManualOnyxUpdateCheckIds};
10 changes: 7 additions & 3 deletions src/libs/actions/__mocks__/OnyxUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {OnyxUpdatesFromServer, Response} from '@src/types/onyx';
jest.mock('@libs/actions/OnyxUpdateManager/utils/applyUpdates');

const OnyxUpdatesImplementation = jest.requireActual<typeof OnyxUpdatesImport>('@libs/actions/OnyxUpdates');
const {doesClientNeedToBeUpdated, saveUpdateInformation} = OnyxUpdatesImplementation;
const {doesClientNeedToBeUpdated, saveUpdateInformation, INTERNAL_DO_NOT_USE_applyHTTPSOnyxUpdates: applyHTTPSOnyxUpdates} = OnyxUpdatesImplementation;

type OnyxUpdatesMock = typeof OnyxUpdatesImport & {
apply: jest.Mock<Promise<Response | void>, [OnyxUpdatesFromServer]>;
Expand All @@ -18,9 +18,13 @@ Onyx.connect({
callback: (val) => (lastUpdateIDAppliedToClient = val),
});

const apply = jest.fn(({lastUpdateID}: OnyxUpdatesFromServer): Promise<void | Response> | undefined => {
const apply = jest.fn(({lastUpdateID, request, response}: OnyxUpdatesFromServer): Promise<void | Response> | undefined => {
if (lastUpdateID && (lastUpdateIDAppliedToClient === undefined || Number(lastUpdateID) > lastUpdateIDAppliedToClient)) {
Onyx.set(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, Number(lastUpdateID));
Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, Number(lastUpdateID));
}

if (request && response) {
return applyHTTPSOnyxUpdates(request, response).then(() => undefined);
}

return Promise.resolve();
Expand Down
9 changes: 5 additions & 4 deletions tests/actions/OnyxUpdateManagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
import OnyxUpdateMockUtils from '../utils/OnyxUpdateMockUtils';

jest.mock('@libs/actions/App');
jest.mock('@libs/actions/OnyxUpdateManager/utils');
jest.mock('@libs/actions/OnyxUpdateManager/utils/applyUpdates', () => {
const ApplyUpdatesImplementation = jest.requireActual<typeof ApplyUpdatesImport>('@libs/actions/OnyxUpdateManager/utils/applyUpdates');
jest.mock('@userActions/OnyxUpdates');
jest.mock('@userActions/App');
jest.mock('@userActions/OnyxUpdateManager/utils');
jest.mock('@userActions/OnyxUpdateManager/utils/applyUpdates', () => {
const ApplyUpdatesImplementation = jest.requireActual<typeof ApplyUpdatesImport>('@userActions/OnyxUpdateManager/utils/applyUpdates');

return {
applyUpdates: jest.fn((updates: DeferredUpdatesDictionary) => ApplyUpdatesImplementation.applyUpdates(updates)),
Expand Down

0 comments on commit 3114a02

Please sign in to comment.