Skip to main content

WhatsAppOTP

Overview

This test suite covers the functionality of the WhatsAppOTP component, which is responsible for verifying OTP (One-Time Password) entered by users during the authentication process.

Test Cases

Test: Initial Render

  • Description: Verifies that the component renders without displaying any error messages initially.
  • Setup: The WhatsAppOTP component is rendered with a mock phone number.
  • Expectation: There should be no error message displayed on the screen.
    • Assertion: Checks if the error message element is null (queryByTestId('error-message')).

Test: Enter Pin Code Success

  • Description: Validates the behavior when a valid OTP is entered successfully.
  • Setup: The useWhatsAppOTPVerifyMutation hook is mocked to simulate a successful verification.
  • Expectation: Upon entering a valid OTP, the component should verify it and update the authentication status accordingly.
    • Assertion 1: Verifies that the OTP verification mutation is called with the correct parameters.
    • Assertion 2: Checks if the authentication token and user data are stored in the local storage.
    • Assertion 3: Ensures that any open modals are closed to maintain a clean UI.
    • Assertion 4: Verifies that the authentication data in the query client is updated correctly.

Test: Enter Pin Code Fail

  • Description: Examines the response of the component when an invalid OTP is entered.
  • Setup: The useWhatsAppOTPVerifyMutation hook is mocked to simulate a failed verification with an error message.
  • Expectation: After entering an invalid OTP, the component should display an appropriate error message indicating the reason for the failure.
    • Assertion 1: Verifies that the OTP verification mutation is called with the correct parameters.
    • Assertion 2: Checks if the displayed error message matches the expected message for an invalid OTP.