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

🛜 ci: OpenID Strategy Test Async Handling #5613

Merged
merged 2 commits into from
Feb 3, 2025

Conversation

rubentalstra
Copy link
Collaborator

Summary

This pull request updates the OpenID strategy implementation and its tests. The changes ensure that the asynchronous verify callback in the OpenID strategy is properly handled by promisifying the callback, which resolves timing issues in tests. Additionally, the tests have been updated to mock external dependencies correctly, including user methods, image downloads, and JWT decoding. These updates improve the robustness of the authentication flow and facilitate easier maintenance and debugging.

Related Issue:
Fixes issues with asynchronous handling in the OpenID strategy tests that were causing flaky test results and improper user data handling.


Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

  • Test Process:

    • The tests were executed using Jest with a MongoDB Memory Server to simulate the database interactions.
    • The verify callback in the OpenID strategy has been wrapped in a Promise to ensure asynchronous operations are correctly awaited.
    • Mocks for external modules (e.g., node-fetch, openid-client, jsonwebtoken/decode, and user methods) have been implemented to isolate and simulate external behavior.
    • Multiple test cases have been added to cover different scenarios such as user creation, user updates, username fallback logic, and avatar handling.
  • Test Configuration:

    • Environment variables required by the OpenID strategy (e.g., OPENID_ISSUER, OPENID_CLIENT_ID, OPENID_CLIENT_SECRET, etc.) are set up within the test suite.
    • The test suite can be run via the project's standard test command (e.g., npm test or yarn test).

To reproduce the tests, clone the repository, install dependencies, set the necessary environment variables as shown in the test file, and run the test command.


Checklist

  • My code adheres to this project's style guidelines.
  • I have performed a self-review of my own code.
  • I have commented in any complex areas of my code.
  • I have made pertinent documentation changes.
  • My changes do not introduce new warnings.
  • I have written tests demonstrating that my changes are effective or that my feature works.
  • Local unit tests pass with my changes.
  • Any changes dependent on mine have been merged and published in downstream modules.

@danny-avila danny-avila changed the title 🛠 fix: openid strategy test and fix async handling 🛜 ci: openid strategy test async handling Feb 3, 2025
@danny-avila danny-avila changed the title 🛜 ci: openid strategy test async handling 🛜 ci: OpenID Strategy Test Async Handling Feb 3, 2025
@danny-avila danny-avila merged commit 93f5713 into danny-avila:main Feb 3, 2025
1 check passed
@rubentalstra rubentalstra deleted the fix/OpenIDStrategy-test branch February 3, 2025 15:57
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.

2 participants