-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: keep public room in LHN for anonymous users #93054
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
yusufdeveloper2903
wants to merge
7
commits into
Expensify:main
Choose a base branch
from
yusufdeveloper2903:fix/92672-public-room-anon-visibility
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.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5456961
fix: keep public room in LHN for anonymous users
yusufdeveloper2903 c54e7e2
fix: keep public room in LHN for anonymous users on cold start
yusufdeveloper2903 17b02bc
test: add unit tests for anonymous public room LHN visibility and dee…
yusufdeveloper2903 89e00a6
fix spellcheck and typecheck CI failures in public room tests
yusufdeveloper2903 aba48a9
Extract pending public room helper and clear ref after refetch
yusufdeveloper2903 e43c5ad
Format DeepLinkHandlerTest with oxfmt
yusufdeveloper2903 f3c97dc
Merge remote-tracking branch 'upstream/main' into fix/92672-public-ro…
yusufdeveloper2903 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1050,6 +1050,7 @@ | |
| "Prefetcher", | ||
| "knip", | ||
| "lottiefiles", | ||
| "Refetched", | ||
| "macrotask", | ||
| "Macrotask" | ||
| ], | ||
|
|
||
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,121 @@ | ||
| import {act, render} from '@testing-library/react-native'; | ||
|
|
||
| import type * as Link from '@libs/actions/Link'; | ||
| import * as Report from '@libs/actions/Report'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import DeepLinkHandler from '@src/DeepLinkHandler'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| import {Linking} from 'react-native'; | ||
| import Onyx from 'react-native-onyx'; | ||
|
|
||
| import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; | ||
|
|
||
| jest.mock('@libs/actions/Link', () => ({ | ||
| ...jest.requireActual<typeof Link>('@libs/actions/Link'), | ||
| openReportFromDeepLink: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('@libs/actions/Report', () => ({ | ||
| ...jest.requireActual<typeof Report>('@libs/actions/Report'), | ||
| openReport: jest.fn(), | ||
| doneCheckingPublicRoom: jest.fn(), | ||
| })); | ||
|
|
||
| const PUBLIC_ROOM_ID = '987654321'; | ||
| const DEFAULT_URL = 'https://new.expensify.com/'; | ||
|
|
||
| describe('DeepLinkHandler', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({keys: ONYXKEYS}); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await act(async () => { | ||
| await Onyx.clear(); | ||
| }); | ||
| jest.clearAllMocks(); | ||
| Linking.setInitialURL(DEFAULT_URL); | ||
| }); | ||
|
|
||
| it('re-fetches a public room that is missing from Onyx after OpenApp settles for an anonymous user (#92672)', async () => { | ||
| // An anonymous session has no authToken, so hasAuthToken() is false and isAnonymousUser() is true. | ||
| await act(async () => { | ||
| await Onyx.multiSet({ | ||
| [ONYXKEYS.SESSION]: {authTokenType: CONST.AUTH_TOKEN_TYPES.ANONYMOUS}, | ||
| [ONYXKEYS.IS_LOADING_APP]: true, | ||
| [ONYXKEYS.CONCIERGE_REPORT_ID]: '', | ||
| [ONYXKEYS.NVP_INTRO_SELECTED]: {}, | ||
| [ONYXKEYS.BETAS]: [], | ||
| }); | ||
| }); | ||
|
|
||
| // Cold deep link straight into the public room. | ||
| Linking.setInitialURL(`new-expensify://r/${PUBLIC_ROOM_ID}`); | ||
|
|
||
| render(<DeepLinkHandler onInitialUrl={jest.fn()} />); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| // While OpenApp is still loading, we should not refetch yet. | ||
| expect(Report.openReport).not.toHaveBeenCalled(); | ||
|
|
||
| // OpenApp settles but the public room is still absent from Onyx -> refetch it so it reaches the LHN. | ||
| await act(async () => { | ||
| await Onyx.merge(ONYXKEYS.IS_LOADING_APP, false); | ||
| }); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(Report.openReport).toHaveBeenCalledWith(expect.objectContaining({reportID: PUBLIC_ROOM_ID})); | ||
| }); | ||
|
|
||
| it('does not refetch when the public room is already present in Onyx', async () => { | ||
| await act(async () => { | ||
| await Onyx.multiSet({ | ||
| [ONYXKEYS.SESSION]: {authTokenType: CONST.AUTH_TOKEN_TYPES.ANONYMOUS}, | ||
| [ONYXKEYS.IS_LOADING_APP]: true, | ||
| [ONYXKEYS.CONCIERGE_REPORT_ID]: '', | ||
| [ONYXKEYS.NVP_INTRO_SELECTED]: {}, | ||
| [ONYXKEYS.BETAS]: [], | ||
| [`${ONYXKEYS.COLLECTION.REPORT}${PUBLIC_ROOM_ID}` as const]: {reportID: PUBLIC_ROOM_ID}, | ||
| }); | ||
| }); | ||
|
|
||
| Linking.setInitialURL(`new-expensify://r/${PUBLIC_ROOM_ID}`); | ||
|
|
||
| render(<DeepLinkHandler onInitialUrl={jest.fn()} />); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| await act(async () => { | ||
| await Onyx.merge(ONYXKEYS.IS_LOADING_APP, false); | ||
| }); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(Report.openReport).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('does not refetch for an authenticated user', async () => { | ||
| await act(async () => { | ||
| await Onyx.multiSet({ | ||
| // An authToken means hasAuthToken() is true, so the deep link is not tracked as a pending public room. | ||
| [ONYXKEYS.SESSION]: {authToken: 'token', accountID: 1}, | ||
| [ONYXKEYS.IS_LOADING_APP]: true, | ||
| [ONYXKEYS.CONCIERGE_REPORT_ID]: '', | ||
| [ONYXKEYS.NVP_INTRO_SELECTED]: {}, | ||
| [ONYXKEYS.BETAS]: [], | ||
| }); | ||
| }); | ||
|
|
||
| Linking.setInitialURL(`new-expensify://r/${PUBLIC_ROOM_ID}`); | ||
|
|
||
| render(<DeepLinkHandler onInitialUrl={jest.fn()} />); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| await act(async () => { | ||
| await Onyx.merge(ONYXKEYS.IS_LOADING_APP, false); | ||
| }); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(Report.openReport).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
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
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.