Skip to content

Commit ac27fed

Browse files
committed
Use exact combined feed key in linkedPolicyIDs predicate tests
Addresses Copilot review comment on PR #88359 (#88359 (comment)): the four new tests previously matched feeds via key.includes(oauthFeed) and gated on result.current[1].status === 'loaded' (an Onyx implementation detail). Now compute the exact combined feed key with getCardFeedWithDomainID and put toHaveProperty([combinedFeedKey]) inside waitFor for the three positive cases, so the wait resolves on the actual expectation. The negative case keeps the loaded-status gate before asserting absence to avoid a vacuous pass while Onyx is still hydrating. Verified locally: - All 7 tests pass on main. - Reverting the predicate to its pre-#88136 form still fails the two linkedPolicyIDs: [''] / [] regression tests. Made-with: Cursor
1 parent b2cec79 commit ac27fed

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

tests/unit/hooks/useCardFeeds.test.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import {renderHook, waitFor} from '@testing-library/react-native';
33
import Onyx from 'react-native-onyx';
44
import useCardFeeds from '@hooks/useCardFeeds';
5+
import {getCardFeedWithDomainID} from '@libs/CardUtils';
56
import CONST from '@src/CONST';
67
import ONYXKEYS from '@src/ONYXKEYS';
78
import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates';
@@ -111,6 +112,8 @@ describe('useCardFeeds', () => {
111112
});
112113

113114
describe('linkedPolicyIDs predicate filtering', () => {
115+
const combinedFeedKey = getCardFeedWithDomainID(oauthFeed, domainID);
116+
114117
const setupDomainFeed = async (companyCardSettings: {preferredPolicy: string; linkedPolicyIDs?: string[]}) => {
115118
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {workspaceAccountID: 0});
116119
await Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${domainID}`, {
@@ -135,10 +138,9 @@ describe('useCardFeeds', () => {
135138
const {result} = renderHook(() => useCardFeeds(policyID));
136139
await waitForBatchedUpdates();
137140

138-
await waitFor(() => expect(result.current[1].status).toBe('loaded'));
139-
140-
const feedKeys = Object.keys(result.current[0] ?? {});
141-
expect(feedKeys.some((key) => key.includes(oauthFeed))).toBe(true);
141+
// The combined feed key contains '.', so wrap it in an array to disable
142+
// jest's nested-path interpretation in toHaveProperty.
143+
await waitFor(() => expect(result.current[0]).toHaveProperty([combinedFeedKey]));
142144
});
143145

144146
it('includes domain feeds when linkedPolicyIDs is an empty array and preferredPolicy matches', async () => {
@@ -147,10 +149,7 @@ describe('useCardFeeds', () => {
147149
const {result} = renderHook(() => useCardFeeds(policyID));
148150
await waitForBatchedUpdates();
149151

150-
await waitFor(() => expect(result.current[1].status).toBe('loaded'));
151-
152-
const feedKeys = Object.keys(result.current[0] ?? {});
153-
expect(feedKeys.some((key) => key.includes(oauthFeed))).toBe(true);
152+
await waitFor(() => expect(result.current[0]).toHaveProperty([combinedFeedKey]));
154153
});
155154

156155
it('excludes feeds when linkedPolicyIDs explicitly lists other policies and preferredPolicy does not match', async () => {
@@ -159,10 +158,10 @@ describe('useCardFeeds', () => {
159158
const {result} = renderHook(() => useCardFeeds(policyID));
160159
await waitForBatchedUpdates();
161160

161+
// Wait for the hook to finish loading before asserting absence, so the negative
162+
// assertion can't pass vacuously while Onyx is still hydrating.
162163
await waitFor(() => expect(result.current[1].status).toBe('loaded'));
163-
164-
const feedKeys = Object.keys(result.current[0] ?? {});
165-
expect(feedKeys.some((key) => key.includes(oauthFeed))).toBe(false);
164+
expect(result.current[0]).not.toHaveProperty([combinedFeedKey]);
166165
});
167166

168167
it('includes feeds when policyID is one of multiple meaningful entries in linkedPolicyIDs', async () => {
@@ -171,10 +170,7 @@ describe('useCardFeeds', () => {
171170
const {result} = renderHook(() => useCardFeeds(policyID));
172171
await waitForBatchedUpdates();
173172

174-
await waitFor(() => expect(result.current[1].status).toBe('loaded'));
175-
176-
const feedKeys = Object.keys(result.current[0] ?? {});
177-
expect(feedKeys.some((key) => key.includes(oauthFeed))).toBe(true);
173+
await waitFor(() => expect(result.current[0]).toHaveProperty([combinedFeedKey]));
178174
});
179175
});
180176
});

0 commit comments

Comments
 (0)