Repository navigation
fix: Code does not arrive when adding contact method with new user #99909
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
Merged
Merged
Changes from all commits
Commits
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
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,103 @@ | ||
| import {render} from '@testing-library/react-native'; | ||
|
|
||
| import ComposeProviders from '@components/ComposeProviders'; | ||
| import {LocaleContextProvider} from '@components/LocaleContextProvider'; | ||
| import ValidateCodeActionContent from '@components/ValidateCodeActionModal/ValidateCodeActionContent'; | ||
|
|
||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| import type {ValueOf} from 'type-fest'; | ||
|
|
||
| import {CONST as COMMON_CONST} from 'expensify-common'; | ||
| import Onyx from 'react-native-onyx'; | ||
|
|
||
| import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
|
|
||
| jest.mock('@components/ValidateCodeActionModal/ValidateCodeForm', () => 'ValidateCodeForm'); | ||
|
|
||
| const defaultProps = { | ||
| title: 'Validate', | ||
| descriptionPrimary: 'Enter the code', | ||
| validateCodeActionErrorField: 'addedLogin', | ||
| handleSubmitForm: () => {}, | ||
| clearError: () => {}, | ||
| }; | ||
|
|
||
| function renderValidateCodeActionContent(sendValidateCode: jest.Mock, validateCodeReasonCode?: ValueOf<typeof COMMON_CONST.VALIDATE_CODE_REASONS>) { | ||
| return render( | ||
| <ComposeProviders components={[LocaleContextProvider]}> | ||
| <ValidateCodeActionContent | ||
| {...defaultProps} | ||
| sendValidateCode={sendValidateCode} | ||
| validateCodeReasonCode={validateCodeReasonCode} | ||
| /> | ||
| </ComposeProviders>, | ||
| ); | ||
| } | ||
|
|
||
| describe('ValidateCodeActionContent', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({ | ||
| keys: ONYXKEYS, | ||
| }); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| return Onyx.clear().then(waitForBatchedUpdates); | ||
| }); | ||
|
|
||
| it('sends a code when a recent request was for a different reason', async () => { | ||
| const sendValidateCode = jest.fn(); | ||
|
|
||
| await Onyx.merge(ONYXKEYS.VALIDATE_ACTION_CODE, { | ||
| lastValidateCodeRequestedAt: Date.now(), | ||
| lastValidateCodeReason: COMMON_CONST.VALIDATE_CODE_REASONS.VALIDATE_ACCOUNT, | ||
| }); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| renderValidateCodeActionContent(sendValidateCode, COMMON_CONST.VALIDATE_CODE_REASONS.ADD_CONTACT_METHOD); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| expect(sendValidateCode).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('does not resend when a recent request was for the same reason', async () => { | ||
| const sendValidateCode = jest.fn(); | ||
|
|
||
| await Onyx.merge(ONYXKEYS.VALIDATE_ACTION_CODE, { | ||
| lastValidateCodeRequestedAt: Date.now(), | ||
| lastValidateCodeReason: COMMON_CONST.VALIDATE_CODE_REASONS.ADD_CONTACT_METHOD, | ||
| }); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| renderValidateCodeActionContent(sendValidateCode, COMMON_CONST.VALIDATE_CODE_REASONS.ADD_CONTACT_METHOD); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| expect(sendValidateCode).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('sends a code when nothing was requested recently', async () => { | ||
| const sendValidateCode = jest.fn(); | ||
|
|
||
| renderValidateCodeActionContent(sendValidateCode, COMMON_CONST.VALIDATE_CODE_REASONS.ADD_CONTACT_METHOD); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| expect(sendValidateCode).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('does not resend when no reason is declared and a code was requested recently', async () => { | ||
| const sendValidateCode = jest.fn(); | ||
|
|
||
| await Onyx.merge(ONYXKEYS.VALIDATE_ACTION_CODE, { | ||
| lastValidateCodeRequestedAt: Date.now(), | ||
| lastValidateCodeReason: COMMON_CONST.VALIDATE_CODE_REASONS.VALIDATE_ACCOUNT, | ||
| }); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| renderValidateCodeActionContent(sendValidateCode); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| expect(sendValidateCode).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
validateSecondaryLogin()is invoked fromDynamicContactMethodDetailsPage, the code being validated was sent byrequestContactMethodValidateCode()and is tracked on the login, not byVALIDATE_ACTION_CODE. Unconditionally clearing this global stamp therefore erases any unrelated recent account-level code request; returning to that account-code flow within the resend window makesValidateCodeActionContentsend another email instead of deduplicating it. Restrict this cleanup to theVerifyAccountPageBaseuse case, such as through a caller-controlled flag.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The impact is small and it would make the code more complicated, so I think it's fine to leave as is