-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fix company cards page not loading for domain-based card accounts #87686
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
Open
carlosmiceli
wants to merge
9
commits into
main
Choose a base branch
from
cm-company-cards-page-not-loading-for-domain-based-accounts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−44
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6819c06
remove workspace account id 0 check
carlosmiceli 031eb26
skip loading state writes when workspace id 0
carlosmiceli 629cbdc
fix company cards page not showing feeds for domain-based card account
carlosmiceli 678a667
prettier
carlosmiceli f70d8f7
Merge remote-tracking branch 'origin/main' into cm-company-cards-page…
carlosmiceli 0cdbf40
comments
carlosmiceli 2d0c6d2
add tests
carlosmiceli 0dd4a86
spellcheck fix
carlosmiceli acfbdd9
add feed length check
carlosmiceli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||
| import {renderHook, waitFor} from '@testing-library/react-native'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import useCardFeeds from '@hooks/useCardFeeds'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; | ||
|
|
||
| const policyID = 'TEST_POLICY_123'; | ||
| const domainID = 12345678; | ||
|
|
||
| // Real feed names that are already in the spell-check dictionary | ||
| const oldStyleFeed = CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX_FILE_DOWNLOAD; | ||
| const oauthFeed = CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX_DIRECT; | ||
|
|
||
| describe('useCardFeeds', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({keys: ONYXKEYS}); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await Onyx.clear(); | ||
| await waitForBatchedUpdates(); | ||
| }); | ||
|
|
||
| describe('effectiveWorkspaceAccountID fallback for domain-based card accounts', () => { | ||
| it('returns feeds from the linked domain when workspaceAccountID is 0 and a feed has preferredPolicy matching the policy', async () => { | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {workspaceAccountID: 0}); | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${domainID}`, { | ||
| settings: { | ||
| companyCards: { | ||
| // Old-style feed linking the domain to this policy — no cards, will be filtered by the gray zone rule | ||
| [oldStyleFeed]: {preferredPolicy: policyID, liabilityType: 'corporate'}, | ||
| // Active OAuth feed with no preferredPolicy — should appear because domainID matches effectiveWorkspaceAccountID | ||
| [oauthFeed]: {preferredPolicy: '', liabilityType: 'corporate'}, | ||
| }, | ||
| oAuthAccountDetails: { | ||
| [oauthFeed]: {credentials: 'xxxx', expiration: 9999999999, accountList: ['Card 1']}, | ||
| }, | ||
| }, | ||
| }); | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${domainID}_${oauthFeed}`, { | ||
| '123': {cardID: 123, cardName: 'Card 1'}, | ||
| }); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| const {result} = renderHook(() => useCardFeeds(policyID)); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| await waitFor(() => { | ||
| const [workspaceFeeds] = result.current; | ||
| const feedKeys = Object.keys(workspaceFeeds ?? {}); | ||
| expect(feedKeys.some((key) => key.includes(oauthFeed))).toBe(true); | ||
| expect(Object.values(workspaceFeeds ?? {}).every((feed) => feed.domainID === domainID)).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| it('returns no feeds when workspaceAccountID is 0 and no domain has a feed linked to the policy', async () => { | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {workspaceAccountID: 0}); | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${domainID}`, { | ||
| settings: { | ||
| companyCards: { | ||
| [oauthFeed]: {preferredPolicy: '', liabilityType: 'corporate'}, | ||
| }, | ||
| oAuthAccountDetails: { | ||
| [oauthFeed]: {credentials: 'xxxx', expiration: 9999999999, accountList: ['Card 1']}, | ||
| }, | ||
| }, | ||
| }); | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${domainID}_${oauthFeed}`, { | ||
| '123': {cardID: 123, cardName: 'Card 1'}, | ||
| }); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| const {result} = renderHook(() => useCardFeeds(policyID)); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| await waitFor(() => { | ||
| const [workspaceFeeds] = result.current; | ||
| expect(Object.keys(workspaceFeeds ?? {}).length).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| it('does not use the fallback when workspaceAccountID is non-zero', async () => { | ||
| const workspaceAccountID = 99999999; | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {workspaceAccountID}); | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${domainID}`, { | ||
| settings: { | ||
| companyCards: { | ||
| [oauthFeed]: {preferredPolicy: '', liabilityType: 'corporate'}, | ||
| }, | ||
| oAuthAccountDetails: { | ||
| [oauthFeed]: {credentials: 'xxxx', expiration: 9999999999, accountList: ['Card 1']}, | ||
| }, | ||
| }, | ||
| }); | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${domainID}_${oauthFeed}`, { | ||
| '123': {cardID: 123, cardName: 'Card 1'}, | ||
| }); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| const {result} = renderHook(() => useCardFeeds(policyID)); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| await waitFor(() => { | ||
| const [workspaceFeeds] = result.current; | ||
| const feedKeys = Object.keys(workspaceFeeds ?? {}); | ||
| expect(feedKeys.some((key) => key.includes(oauthFeed))).toBe(false); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.