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

Service stop should not be called #233

Closed
wants to merge 15 commits into from

Conversation

denysoblohin-okta
Copy link
Contributor

@denysoblohin-okta denysoblohin-okta commented May 23, 2022

Changes:

  • Removes oktaAuth.stop() from <Security>
  • Removes oktaAuth.start() from <LoginCallback> after handleLoginRedirect - not needed
  • Fixed useEffect hook in <Security> - don't watch for restoreOriginalUri prop to perform side-effects (start, subscribe, unsubscribe) on oktaAuth
  • Updated okta-auth-js to latest

Internal ref: OKTA-492710 (including deps OKTA-482712 OKTA-482710)

@denysoblohin-okta denysoblohin-okta force-pushed the od-lifecycle-issue-OKTA-492710 branch from 9853c75 to bf4fe03 Compare May 25, 2022 21:28
@denysoblohin-okta denysoblohin-okta changed the title Service start/stop should be called outside of component hierarchy Service stop should not be called May 25, 2022
@@ -70,6 +70,8 @@ describe('<LoginCallback />', () => {
</Security>
);
expect(oktaAuth.handleLoginRedirect).toHaveBeenCalledTimes(1);
await Promise.resolve();
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this Promise.resolve?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To wait for handleLoginRedirect which is a promise

Copy link
Contributor

Choose a reason for hiding this comment

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

You can put the await in the expect call

expect(await oktaAuth.handleLoginRedirect)

or

await expect(oktaAuth.handleLoginRedirect).resolves.toHaveBeenCalled()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

handleLoginRedirect should be called inside useEffect of <LoginCallback />
Previous implementation included excess start() after promise resolves:

oktaAuth.handleLoginRedirect().then(() => {
      oktaAuth.start() // not needed
    })

In this test we need to wait for handleLoginRedirect to be called implicitly inside useEffect and resolved, then check start() was not called.

Awaiting it explicitly in test would not work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

    await act(async () => {
      mount(
        <Security {...mockProps}>
          <LoginCallback />
        </Security>
      );
    });

this works without need of await Promise.resolve();

eng-prod-CI-bot-okta pushed a commit that referenced this pull request Jun 2, 2022
OKTA-492710
<<<Jenkins Check-In of Tested SHA: a418c19 for eng_productivity_ci_bot_okta@okta.com>>>
Artifact: okta-react
Files changed count: 21
PR Link: #233
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.

3 participants