In the previous parts of this blog series, we meticulously designed an email verification system using Firebase and Flutter. We covered the system setup and UI changes, SMTP mailer configuration, Firebase Cloud Functions setup, and implemented a snapshot listener to monitor email verification status in real-time. Now, in the final part of our series, we will focus on testing the complete flow of our email verification process to ensure everything works as intended.
Purpose of End-to-End Testing of Email Verification Process
End-to-end (E2E) testing is crucial in verifying that the entire workflow of an application functions correctly from start to finish. In our case, we need to confirm that:
- Users can successfully enter their email and initiate the verification process.
- The system sends a verification email with a valid link.
- Clicking the verification link correctly updates the user’s status in the database.
- The application accurately reflects the updated status and allows the user to log in.
Steps for End-to-End Testing
1. Initiate the Email Verification Process
To start, we must ensure that the email verification process can be triggered properly from the UI:
- Open the login page of the application.
- Enter a valid email address and click the “Login” button.
- Observe the change in the button message to “Tap link in email,” indicating that the verification email has been sent.
- Note the inactivity period of 120 seconds during which the button should remain disabled.
2. Verify Email Sending Mechanism
Next, we need to check if the SMTP mailer correctly sends the verification email:
- Check the console logs for messages indicating that the email was sent.
- Open the email inbox associated with the test account.
- Look for the verification email and ensure it contains a link to verify the email address.
3. Test the Verification Link
Once the email is received, click the verification link to test the Firebase Cloud Function:
- Confirm that the link navigates to the specified Cloud Function endpoint.
- Ensure that the function receives the required parameters (userId and Time) correctly.
- Validate that the function processes the request and updates the user’s emailRequestStatus in Firestore to “verificationSuccess” if the link is valid.
4. Monitor Changes with Snapshot Listener
After clicking the verification link, the snapshot listener should detect changes in the user’s status:
- Open the application and ensure the user is still on the login page.
- Check that the application automatically recognizes the updated emailRequestStatus and proceeds to log in the user.
- Confirm that the application updates the local status to ‘verificationSuccess’.
5. Complete the Login Process
Finally, we need to validate that the user can log in seamlessly after verification:
- Ensure that upon successful email verification, the user is logged in automatically without needing to enter their credentials again.
- Confirm that any additional user data or device details are properly inserted or updated in the database as needed.
- Test the app’s functionality post-login to ensure that the user can access all features as expected.
Additional Testing Scenarios
While the primary flow is essential, consider testing additional scenarios to ensure robustness:
- Invalid Email Addresses: Attempt to log in with an unregistered email and verify that the application handles this gracefully without crashing.
- Expired Links: Simulate clicking an expired verification link (i.e., one older than 5 minutes) to ensure that the application responds with an appropriate error message.
- Network Issues: Test how the application behaves with unstable network conditions, ensuring it handles errors without affecting user experience.
Conclusion
In this final part of our blog series, we conducted comprehensive end-to-end testing of our email verification system. By meticulously following the outlined steps, we verified that each component of our implementation works seamlessly together to provide a smooth user experience.
With all parts of our email verification flow successfully tested, we can be confident that our system is robust and ready for production. Thank you for following along with this series, and we hope it has provided valuable insights into implementing an effective email verification process using Firebase and Flutter!