I need to test a protractor test case in which a user signs up, receives an email, goes to the link provided in the email and fills up his/her details in activation signup form.
The problem is how can I get the redeem token from the email. My email has a link to the activation page which has the auth token like following:
http://127.0.0.1:3000/#/signup/redeem/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJlOTRhYzY3MC1kYTNlLTQyYTUtODVkZS02NDU4ZjVmZGMwYjAiLCJzdWIiOiJ0ZXN0QGNvZWYuY28iLCJpYXQiOjE0Mjc0OTM5MDMsImV4cCI6MTQyODA5ODcwM30.
But how do I fetch that token so that I can build the url or how can I click that button in my email so that I can complete the flow ? I am using mailcatcher to simulate email.
This is something I've solved recently. Hope the solution would also apply for your use-case.
Prerequisites:
mail-listener2
packagepromises
Step by step instructions:
Install
mail-listener2
:In your protractor config initialize Mail Listener and make it available globally:
Create a helper
getLastEmail()
function which would wait for anemail
to be retrieved:Example test case:
The solution I implemented was using mailcatcher API, if you scroll down a bit you'll find the following about the API:
So we first fetched the whole json response, parse it and fetch the latest email id:
using that email id we can get the body of the email by hitting
/messages/:id.plain
(of course there are more variants like fetching the email source code or email rendered html, we only needed the message) then we can just parse the body to fetch what we want, following is the code:And Cheers!