Created
October 21, 2017 13:42
-
-
Save adamTrz/15e63f95f5a180eb7a21ff47a685b3f9 to your computer and use it in GitHub Desktop.
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
| Cypress.Commands.add('login', (email, password) => { | |
| // Make a POST request to our backend | |
| // We are using GraphQL, so as a body we are passing mutation: | |
| cy | |
| .request({ | |
| url: 'http://localhost:4000/graphql', | |
| method: 'POST', | |
| body: { | |
| query: | |
| 'mutation login($email: String!, $password: String!) {loginUser(email: $email, password: $password)}', | |
| variables: { email, password }, | |
| }, | |
| }) | |
| .then(resp => { | |
| // assert response from server | |
| expect(resp.status).to.eq(200); | |
| expect(resp.body).to.have.property('data'); | |
| // all our private routes check for auth token stored in redux store, so let's pass it there | |
| window.localStorage.setItem( | |
| 'reduxPersist:user', | |
| JSON.stringify({ refreshToken: resp.body.data.loginUser }) | |
| ); | |
| // go to Dashboard | |
| cy.visit('/c'); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment