Skip to content

Instantly share code, notes, and snippets.

@adamTrz
Created October 21, 2017 13:42
Show Gist options
  • Select an option

  • Save adamTrz/15e63f95f5a180eb7a21ff47a685b3f9 to your computer and use it in GitHub Desktop.

Select an option

Save adamTrz/15e63f95f5a180eb7a21ff47a685b3f9 to your computer and use it in GitHub Desktop.
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