Skip to content
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
2 changes: 1 addition & 1 deletion src/libs/actions/OnyxUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function apply<TKey extends OnyxKey>({lastUpdateID, type, request, response, upd
return applyHTTPSOnyxUpdates(request, responseWithoutOnyxData, Number(lastUpdateID));
}

return Promise.resolve();
return Promise.resolve(response);
}
if (lastUpdateID && (lastUpdateIDAppliedToClient === undefined || Number(lastUpdateID) > lastUpdateIDAppliedToClient)) {
Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, Number(lastUpdateID));
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/MiddlewareTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ beforeEach(async () => {
});

describe('Middleware', () => {
describe('SaveResponseInOnyx', () => {
test('preserves the response for side-effect requests when the update is already applied', async () => {
// Given the client already has a lastUpdateID applied
await Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, 100);
await waitForBatchedUpdates();

Request.addMiddleware(SaveResponseInOnyx, 'SaveResponseInOnyx');

const mockResponse = {
jsonCode: 200,
lastUpdateID: 100,
previousUpdateID: 99,
transactionsPending3DSReview: {
txn123: {amount: 500, currency: 'USD', created: '2026-02-23', expires: '2026-02-24', lastFourPAN: 1234, merchant: 'TestMerchant'},
},
};
jest.spyOn(HttpUtils, 'xhr').mockResolvedValueOnce(mockResponse);

// When we process a side-effect request with no successData/failureData/finallyData
const result = await Request.processWithMiddleware({
command: 'GetTransactionsPending3DSReview',
data: {apiRequestType: 'makeRequestWithSideEffects'},
});

// Then the response should not be undefined — the caller may need the raw response for side effects
expect(result).toBeDefined();
expect(result?.jsonCode).toBe(200);
});
});

describe('HandleUnusedOptimisticID', () => {
test('Normal request', async () => {
Request.addMiddleware(handleUnusedOptimisticID, CONST.TELEMETRY.MIDDLEWARE_HANDLE_UNUSED_OPTIMISTIC_ID);
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/OnyxUpdatesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,38 @@ describe('OnyxUpdatesTest', () => {
});
});

it('preserves the response object when HTTPS update is old and request has no successData/failureData/finallyData', async () => {
// Given the client already has a lastUpdateID applied
const currentUpdateID = 100;
await Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, currentUpdateID);
await waitForBatchedUpdates();

const mockResponse = {
jsonCode: 200,
transactionsPending3DSReview: {
txn123: {amount: 1000, currency: 'USD', created: '2026-02-23', expires: '2026-02-24', lastFourPAN: 1234, merchant: 'TestMerchant'},
},
onyxData: [],
};

// When we apply an HTTPS update where lastUpdateID is already applied (i.e. "old"),
// and the request has no successData/failureData/finallyData
const result = await OnyxUpdates.apply({
type: CONST.ONYX_UPDATE_TYPES.HTTPS,
lastUpdateID: currentUpdateID,
previousUpdateID: currentUpdateID - 1,
request: {
command: 'GetTransactionsPending3DSReview',
data: {},
},
response: mockResponse,
});

// Then the response should still be returned to the caller, not undefined
expect(result).toBeDefined();
expect(result?.jsonCode).toBe(200);
});

it('applies full ReconnectApp Onyx updates even if they appear old', async () => {
// Given the current lastUpdateIDAppliedToClient is merged
const currentUpdateID = 100;
Expand Down
Loading