Skip to content
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

Fix 51888 cors errors are displayed for attachments #53407

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

Kalydosos
Copy link
Contributor

@Kalydosos Kalydosos commented Dec 2, 2024

Explanation of Change

Fixed Issues

$ 51888
PROPOSAL: #51888 (comment)

Tests

Test 1 steps

  1. open a chat
  2. send a text + image as comment if you dont have it already
  3. click to edit the comment
  4. copy the comment
  5. send the copy as new comment
  6. observe the preview image displayed correctly

Test 2 steps

  1. open a chat
  2. send an image
  3. open the devtools console
  4. run the following code in the console to simulate expiring the session tokens :

Onyx.merge('session', {authToken: 'pizza', encryptedAuthToken: 'pizza', creationDate: new Date().getTime() - 236001000});

  1. observe the attachment preview does not display a gray box
  2. observe the attachment preview reloads while displaying a loading spinner

Note : on native platforms, the troubleshooting test tool "Send expired session" can be used to send an expired session in the next 15 seconds when clicked.

Test 3 steps

  1. open a chat
  2. send an image
  3. click on the image to display it in the carousel
  4. open the devtools console
  5. run the following code in the console to simulate expiring the session tokens :

Onyx.merge('session', {authToken: 'pizza', encryptedAuthToken: 'pizza', creationDate: new Date().getTime() - 236001000});

  1. Observe the attachment image does not display a gray box
  2. Observe the attachment image reloads while displaying a loading spinner

Note : on native platforms, the troubleshooting test tool "Send expired session" can be used to send an expired session in the next 15 seconds when clicked.

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android_native.mp4
Android: mWeb Chrome
android_mweb.mp4
iOS: Native
ios_native.mp4
iOS: mWeb Safari
ios_mweb_safari.mp4
MacOS: Chrome / Safari
ios_web_safari.mp4
MacOS: Desktop
macos_desktop.mp4

@Kalydosos
Copy link
Contributor Author

Kalydosos commented Dec 3, 2024

@hungvu193 should we ask for Design team's help for a better spinner now ?

@hungvu193
Copy link
Contributor

Not yet, please address the linting. After the codes look good then I will request a review from Design team.

@hungvu193
Copy link
Contributor

Here's the flow:

  1. Address the lint, added the screenshots/videos
  2. I reviewed the code.
  3. I request the review from Design team.

@Kalydosos
Copy link
Contributor Author

Kalydosos commented Dec 3, 2024

@hungvu193 we need Design to make the choice of the type of image (SVG, GIF, ...) and certainly provide us the image to use based on this video https://github.com/user-attachments/assets/ccd73db5-d00a-49cd-83b2-0b3fb7388577 and the GIF file. Their help will change the code (call to updateAspectRatio, sizing, style...). After all the changes made based on their advice, they review. Thats the work experience i have with them. But as you said we can also go this way #53407 (comment)

@Kalydosos
Copy link
Contributor Author

@hungvu193 run lint was hanging on my pc. Now we are done with the lint errors, the remaining error is related to the legacy use of withOnyx not our changes. I guess that step should be skipped when deploying on staging.

@hungvu193
Copy link
Contributor

the remaining error is related to the legacy use of withOnyx not our changes. I guess that step should be skipped when deploying on staging.

Ah no. Once you changed a file that includes withOnyx, you will need to migrate it to useOnyx, otherwise we can't pass the test.
Please replace withOnyx with useOnyx

@Kalydosos
Copy link
Contributor Author

@hungvu193 sorry but that's a whole different issue with its testing and debugging. been there done, done that. We can not take that extra load as we are not even close to be done here. I had the same experience from a previous ticket and the ticket created to make such replacement was a whole issue in itself as it was necessary to avoid regressions. Let's not go that road, i will advise.

@hungvu193
Copy link
Contributor

We don't create a separate ticket if the changes to the Onyx migration are small. For example, in my previous PR, I also migrated useOnyx within the same PR

@Kalydosos
Copy link
Contributor Author

@hungvu193 i propose we reconsider that possibility once we are done with the main issue

@hungvu193
Copy link
Contributor

What's the main issue? The useOnyx migration is pretty simple for Image component btw. Please update it. I'll review PR in the meantime.

@Kalydosos
Copy link
Contributor Author

@hungvu193 dont forget that Image is a central component highly used in every screen of the code, so this "simple" change will require a lot of testing for possible regressions. Why not deal with issues one after the other ?

@Kalydosos
Copy link
Contributor Author

Kalydosos commented Dec 4, 2024

@hungvu193 Many have made changes and PRs on this file before us and faced that Lint error/warning. This "simple" component could be at high risks of regressions. I will advise in this case to not do anything instead of breaking something

src/CONST.ts Outdated
@@ -1445,6 +1445,8 @@ const CONST = {
UNKNOWN: 'unknown',
},
},
// the number of hours for an idle session to expire
SESSIONS_MAXIDLE_NB_HOURS: 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use milliseconds instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes good idea

}
return previousSessionAge.current;
}
if (Math.abs(new Date().getTime() - session.creationDate) >= CONST.SESSIONS_MAXIDLE_NB_HOURS * 3600000) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we used milliseconds for CONST.SESSIONS_MAXIDLE_NB_HOURS we can do this instead:

Suggested change
if (Math.abs(new Date().getTime() - session.creationDate) >= CONST.SESSIONS_MAXIDLE_NB_HOURS * 3600000) {
if (Math.abs(new Date().getTime() - session.creationDate) >= CONST.SESSIONS_MAXIDLE_NB_HOURS) {

/**
* trying to figure out if the current session is expired or fresh from a necessary reauthentication
*/
const previousSessionAge = useRef<number | undefined>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a hook called usePrevious, let use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i'll check that

Comment on lines 60 to 83
useEffect(() => {
previousSessionAge.current = validSessionAge;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After using usePrevious we can remove this block:

Suggested change
useEffect(() => {
previousSessionAge.current = validSessionAge;
});

[CONST.CHAT_ATTACHMENT_TOKEN_KEY]: authToken,
},
};
if (!!session?.creationDate && new Date().getTime() - session.creationDate < CONST.SESSIONS_MAXIDLE_NB_HOURS * 3600000) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a function called isValidSessionCreationDate to reuse this logic?
ie:

function isValidSessionCreationDate() {
 return !!session?.creationDate && (new Date().getTime() - session.creationDate) > CONST.SESSIONS_MAXIDLE_NB_HOURS
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll see how can isolate that logic in a function with a relevant name, good idea

Comment on lines 48 to 68
if (Math.abs(previousSessionAge.current - session.creationDate) < 60000) {
return session.creationDate;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why we have this condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we expect a reauthenticate to happen in less than 60s if the current session was expired. I have made the tests. so the new valid session will be newer than 60s after

}
}
return propsSource;
// The session prop is not required, as it causes the image to reload whenever the session changes. For more information, please refer to issue #26034.
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [propsSource, isAuthTokenRequired]);
}, [propsSource, isAuthTokenRequired, validSessionAge]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the comment right above to explain why we should add validSessionAge in dependencies array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -72,6 +102,7 @@ function Image({source: propsSource, isAuthTokenRequired = false, session, onLoa
{...forwardedProps}
onLoad={handleLoad}
style={[style, shouldSetAspectRatioInStyle && aspectRatio ? {aspectRatio, height: 'auto'} : {}, shouldOpacityBeZero && {opacity: 0}]}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment to explain why we disable eslint here

@hungvu193
Copy link
Contributor

@hungvu193 Many have made changes and PRs on this file before us and faced that Lint error/warning. This "simple" component could be at high risks of regressions. I will advise in this case to not do anything instead of breaking something

We still need to do it anyway. PR can't be merged if all the tests aren't passed. That's mandatory.

@Kalydosos
Copy link
Contributor Author

We still need to do it anyway. PR can't be merged if all the tests aren't passed. That's mandatory.

How did previous PRs end up in main then ? I really think we should avoid this as we can never do enough testing for regressions imho

@hungvu193
Copy link
Contributor

We still need to do it anyway. PR can't be merged if all the tests aren't passed. That's mandatory.

How did previous PRs end up in main then ? I really think we should avoid this as we can never do enough testing for regressions imho

Changes from previous PRs were added when we didn't deprecate withOnyx HOC.

@Kalydosos
Copy link
Contributor Author

@hungvu193 lets change it after we are done with the main issue, if you insist on it. I can't put my focus on that right now as i must start testing for regressions right away once we change it.

@Kalydosos
Copy link
Contributor Author

Kalydosos commented Dec 4, 2024

@hungvu193 i will upload the web test video as you can see the sizing of the image cause the attachments not to render properly (we cant just use any gif from the web). So the code will be adjusted once we have the definitive image from Design. I think we can have Design team's help based on the web test and the other envs are not necessary as they will be reviewed anyway once we have the definitive image

demo_with_2H_expired_token.mp4

@hungvu193
Copy link
Contributor

The fact that we display image based on its size. I'm thinking about the way we should keep image loading until it has valid session. Wdyt?

@hungvu193
Copy link
Contributor

So There's no image/gif placeholder needed. Instead we improve the loading conditions of image

@Kalydosos
Copy link
Contributor Author

So There's no image/gif placeholder needed. Instead we improve the loading conditions of image

the problem is the final source of the image is not known yet at that step, it will be recalculated once we have a valid session, so we cannot anticipate the loading unless you're thinking of some other way for it

@Kalydosos
Copy link
Contributor Author

@hungvu193 i did some updates based on your review but it didnt use the useprevious hook yet (i will test it some more).

@hungvu193
Copy link
Contributor

hungvu193 commented Dec 5, 2024

I think for now that's fine to keep image resize like that. Let's complete the author checklist and mark this PR as ready for review.

I took a few tests, everything seems working fine. Let's finish the PR phrase so I'll request a review from Design team 😄

@hungvu193
Copy link
Contributor

So I abandoned my tab for hours and when I'm back I got this issue.

Screen.Recording.2024-12-05.at.15.40.06.mov

@hungvu193
Copy link
Contributor

As I checked the log, ReAuthenticate seems to never get called during that time, so session was invalid and the loading was showed forever

@Kalydosos
Copy link
Contributor Author

As I checked the log, ReAuthenticate seems to never get called during that time, so session was invalid and the loading was showed forever

yes we need to fix it in the caroussel also. I'll work on it.

@Kalydosos
Copy link
Contributor Author

@hungvu193 we will be using a reauthenticator which will be a singleton object called when the spinner is returned as source for the image. The current session will be send as parameter. It will listen to network and session onyx keys so it wont do anything if offline and will deactivate once it receive a session from Onyx. Once activated (only once) it will expect a session from Onyx in the next 10s (preferred) or 15s and if it doesnt receive a new session it will ask for reauthentication (only once with no retry). Wdyt ? i'll implement it

@Kalydosos
Copy link
Contributor Author

Kalydosos commented Dec 5, 2024

@hungvu193 but normally the notification pusher triggers reauthentifications (if necessary every 5 seconds) and we shouldnt need a reauthenticator

https://github.com/Kalydosos/App/blob/6fc2b615a449caac1acd3ba8ca956674e4d344bf/src/libs/actions/Session/index.ts#L848-L860

triggers

https://github.com/Kalydosos/App/blob/6fc2b615a449caac1acd3ba8ca956674e4d344bf/src/libs/Authentication.ts#L93

edit*
but reauthentication is triggered only when the pusher cannot send push due to invalid tokens, so it cannot be rely on finally

@Kalydosos
Copy link
Contributor Author

I will do some testings about the caroussel display

@Kalydosos
Copy link
Contributor Author

Kalydosos commented Dec 6, 2024

@hungvu193 i have implemented the reauthenticator (still i dont know what you think of the idea) https://github.com/Kalydosos/App/blob/fix-51888-cors-errors-are-displayed-for-attachments/src/libs/actions/Session/Reauthenticator.ts . I let the comments in the code to help you test it out. I set the session expiration time to 5mn for testing. You can then see how it works for the image in the chat

reauthenticate_for_thread_images.mp4

and then for the carousel

reauthenticator_demo.mp4

the point is now to make sure it is used when it is really necessary and maybe we could shorten the wait time to 7s or 8s

@hungvu193
Copy link
Contributor

Yes

@Kalydosos
Copy link
Contributor Author

Kalydosos commented Dec 20, 2024

ok. So their tests will not be based on or copy my tests then, right ?

@hungvu193
Copy link
Contributor

#I'm not sure what you mean by their tests

@Kalydosos
Copy link
Contributor Author

Kalydosos commented Dec 20, 2024

#I'm not sure what you mean by their tests

they were supposed to follow our tests steps on every platform. If we use a trick that they cannot use, how can they validate the test steps for sure ? I really thnik we should ask

@hungvu193
Copy link
Contributor

they were supposed to follow our tests steps on every platform. If we use a trick that they cannot use, how can they validate the test steps for sure ? I really thnik we should ask

I just remember we can test this by using Invalid Authentication status on Dev tools menu. If so they (QA) can use it, you can use it as well.
You can open the Dev tool menu from your native platform and choose Open Test Preferences, then there's option to invalid authentication status:

Screenshot 2024-12-21 at 00 12 21

@hungvu193
Copy link
Contributor

Checkout TestToolMenu component for more informations.

@Kalydosos
Copy link
Contributor Author

@hungvu193 that's the tool i was talking about here #53407 (comment). The problem is 1. we curently do not setted creationDate for the function used by that tool and 2.even if we do, the troubleshooting panel covers the chat and the images could not be seen reloading (i tried that earlier). I will think of a way also.

@hungvu193
Copy link
Contributor

if we do, the troubleshooting panel covers the chat and the images could not be seen reloading

But we still can test the case when user press on that image right?

@Kalydosos
Copy link
Contributor Author

But we still can test the case when user press on that image right?

No we will still need to interact with Onyx after clicking on the image (you are speaking of the carousel test right ?)

A possible solution will be to set interval (a form of useEffect in the function of the test tool) that will give the time to go back in the chat or the carousel to observe the effect of expiring the session. But that will be a definitive change in the code not a temporary modification. Thus we need to know what was the usage and the intention by those who use the tool to make sure we are still consistent with the prior usage.

@Kalydosos
Copy link
Contributor Author

but i still think we should do all these efforts when it worth it, meaning when we agree with the tests team that this will do as a solution

@hungvu193
Copy link
Contributor

@hungvu193 that's the tool i was talking about here #53407 (comment). The problem is 1. we curently do not setted creationDate for the function used by that tool and 2.even if we do, the troubleshooting panel covers the chat and the images could not be seen reloading (i tried that earlier). I will think of a way also.

Why not? I can still use it to record the video.

Screen.Recording.2024-12-21.at.22.57.55.mov

@Kalydosos
Copy link
Contributor Author

@hungvu193 videos of all platforms are up. I think we should deliver the version with modified testool now, right ?

@hungvu193
Copy link
Contributor

@hungvu193 videos of all platforms are up. I think we should deliver the version with modified testool now, right ?

Yeah

@@ -765,7 +777,7 @@ function invalidateCredentials() {

function invalidateAuthToken() {
NetworkStore.setAuthToken('pizza');
Onyx.merge(ONYXKEYS.SESSION, {authToken: 'pizza'});
Onyx.merge(ONYXKEYS.SESSION, {authToken: 'pizza', encryptedAuthToken: 'pizza'});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include the creationTime as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i pushed the version now

Copy link
Contributor Author

@Kalydosos Kalydosos Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a 50s lapse of time before the session is expired when clicked on the test tool. That will be enough for every tester to do the tests on native platforms comfortably. I think you should redo your tests videos with the current version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, why don't you add creationTime here? If so, if we use this tool, the session won't invalid.

Copy link
Contributor Author

@Kalydosos Kalydosos Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as i mentionned here #53407 (comment) the point of this tool is to invalidate the session token (thus the name of the function invalidateAuthToken) in the BE and see how interactions go. No putting any creationDate maintains the same experience with this tool before and after our changes, we are not impacting that tool

@hungvu193
Copy link
Contributor

hungvu193 commented Dec 23, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
Screen.Recording.2024-12-23.at.11.21.29.mov
iOS: Native
Screen.Recording.2024-12-24.at.16.23.34.mov
iOS: mWeb Safari
Screen.Recording.2024-12-23.at.10.58.30.mov
MacOS: Chrome / Safari
Screen.Recording.2024-12-23.at.10.44.45.mov
MacOS: Desktop
Screen.Recording.2024-12-23.at.10.45.05.mov

NetworkStore.setAuthToken('pizza');
Onyx.merge(ONYXKEYS.SESSION, {authToken: 'pizza'});
// expires the session after 50s
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why timeout here? I dont think we need it

Copy link
Contributor Author

@Kalydosos Kalydosos Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's necessary, otherwise we barely can observe the reload of images in the tests (like in your own Android:mweb video btw). Not everybody is as quick in clicking as you are 😄 I mentionned it in the checklist tests steps and in some previous comments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove timeout, I can still test without timeout, it doesn't make sense when you need to wait for 30s to invalid the session

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i cannot do the tests without setting the timeout and i'm sure many couldnt. You are doing test2 only in your android mweb video, you cannot do test3 if there is no timeout. Please include all 3 tests in your videos and you could see that timeout is necessary. We could maybe reduce the lapse time from 50s to 30s.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. We don't need timeout, we have a shortcut to open TestTool menu (command + D on web and 4 finger gesture on native).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by Send expired session?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rlinoz we litteraly send an expired session to the FE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We create a new tool called Invalidate session delayed not Send expired session. Can you update please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hungvu193 "Invalidate session delayed" is a suggession by @rlinoz but "send expired session" is a more accurate title for what we do in fact. We dont really "invalidate" the session we expires it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hungvu193 should we ask for the translations ?

Comment on lines 779 to 782
setTimeout(() => {
NetworkStore.setAuthToken('pizza');
Onyx.merge(ONYXKEYS.SESSION, {authToken: 'pizza', encryptedAuthToken: 'pizza', creationDate: new Date().getTime() - CONST.SESSION_EXPIRATION_TIME_MS});
}, 50000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setTimeout(() => {
NetworkStore.setAuthToken('pizza');
Onyx.merge(ONYXKEYS.SESSION, {authToken: 'pizza', encryptedAuthToken: 'pizza', creationDate: new Date().getTime() - CONST.SESSION_EXPIRATION_TIME_MS});
}, 50000);
NetworkStore.setAuthToken('pizza');
Onyx.merge(ONYXKEYS.SESSION, {authToken: 'pizza', encryptedAuthToken: 'pizza', creationDate: 1});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have suggested that we use the testool "invalidate session" to do the test of expiring the session on native platforms because we could not use the devtools console in those platforms to do so. The test in the devtools console is to set the session creation date to 2hours before. If we do otherwise it's inconsistent with our web test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the creationDate only need to be an invalid (expired) value, what's the matter?

Copy link
Contributor Author

@Kalydosos Kalydosos Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it need to be a realistic test. In the real life situation that this PR is fixing the session expires when its creation time is more than 2h ago. Please let's do things the way it should reflect the real usage of the app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA can access that test tool menu on "real life" app. No need to worry about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm speaking of what expiring a session means in real life usage of the app. It means its creation time is 2h ago. Any other value of that creation date is not a test of our PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is test tool, who cares about real life usage? A Testtool should do what it should. We need invalid session, that's all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no @hungvu193 we need to expire the session. We can invalidate just by only sending "pizza" as token but expiring the session has to do with the value of its creation date.

@hungvu193
Copy link
Contributor

hungvu193 commented Dec 24, 2024

Can use mention the correct issue here in your checklist? It should be link to the issue not number.

Screenshot 2024-12-24 at 09 37 17

@Kalydosos
Copy link
Contributor Author

Kalydosos commented Dec 26, 2024

@hungvu193 it's all good now except the translations #53407 (comment) . I redo all the videos (for the nth time 😃 ), hope it's all setted !

@hungvu193
Copy link
Contributor

Let's wait for confirmation from Internal Engineer in our ongoing discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants