Last active
August 11, 2022 10:48
-
-
Save filiphric/e92d064df5cff422b4331dbb2741d402 to your computer and use it in GitHub Desktop.
Cypress request to mailosaur API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const userEmail = 'email.abcdefg@mailosaur.io' | |
| describe('Reset password flow', () => { | |
| it('Should receive an email and use reset password link', () => { | |
| // trigger reset password for user | |
| // this command is equal to clicking „I forgot my password“ link and entering user email | |
| cy | |
| .userPasswordReset(userEmail) | |
| cy | |
| .request({ | |
| method: 'POST', | |
| url: 'https://mailosaur.com/api/messages/await?server=abcdefg', // abcdefg is server name | |
| headers: { | |
| authorization: Cypress.env('mailosaurAuth') | |
| }, | |
| body: { | |
| 'sentTo': userEmail, | |
| 'subject': 'Password reset' | |
| } | |
| }).then( response => { | |
| // continue with test, open link | |
| cy | |
| .visit(response.body.text.links[1]) | |
| // fill in and confirm new password | |
| cy | |
| .get('#password') | |
| .type(newPassword); | |
| cy | |
| .get('#passwordConfirm') | |
| .type(newPassword); | |
| cy | |
| .get('#reset-change-password-btn') | |
| .should('be.visible') | |
| .should('be.enabled') | |
| .click(); | |
| // land on desired page after confirming password reset | |
| cy | |
| .location('href') | |
| .should('contains', '/login'); | |
| // login with my new password | |
| // ... | |
| }) | |
| }); | |
| }); |
Author
Hey Irana, I’m pretty sure this way of checking the emails is deprecated. I suggest you take a look at the official mailosaur plugin: https://mailosaur.com/docs/frameworks-and-tools/cypress/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now i get 401 error code. It is better than 405 =D But still does not work:(
cy.request() failed on:
https://mailosaur.com/api/messages?server=*****
The response we received from your web server was:
The request we sent was:
Method: POST
URL: https://mailosaur.com/api/messages?server=*****
Headers: {
"Connection": "keep-alive",
"authorization": "",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
"accept": "/",
"accept-encoding": "gzip, deflate",
"content-type": "application/json",
"content-length": 80
}
Body: {"sentTo":"@****.mailosaur.net","subject":"Passwort zurücksetzen"}
The response we got was:
Status: 401 - Unauthorized
Headers: {
"content-length": "0",
"date": "Sun, 07 Aug 2022 21:23:12 GMT",
"server": "Kestrel",
"cache-control": "no-store, must-revalidate, no-cache",
"expires": "-1",
"www-authenticate": "Bearer",
"x-frame-options": "SAMEORIGIN",
"x-xss-protection": "1; mode=block",
"x-content-type-options": "nosniff",
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
"via": "1.1 google",
"alt-svc": "h3=":443"; ma=2592000,h3-29=":443"; ma=2592000"