fix login commands

This commit is contained in:
Karolina Rakoczy 2021-02-24 12:19:17 +01:00
parent f1c86f0a4d
commit 3a90d9bdc2

View file

@ -10,19 +10,17 @@ Cypress.Commands.add("loginUser", () =>
.click() .click()
); );
Cypress.Commands.add("loginUserViaRequest", () => { // Cypress.Commands.add("loginUserViaRequest", () => {
cy.sendLoginRequest().then(resp => { // cy.sendLoginRequest().then(resp => {
window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token); // window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token);
}); // });
}); // });
Cypress.Commands.add("loginInShop", () => { Cypress.Commands.add("loginInShop", () => {
cy.sendLoginRequest("token").then(resp => { cy.loginUserViaRequest("token");
window.sessionStorage.setItem("token", resp.body[0].data.tokenCreate.token);
});
}); });
Cypress.Commands.add("sendLoginRequest", (authorization = "auth") => { Cypress.Commands.add("loginUserViaRequest", (authorization = "auth") => {
const mutation = `mutation TokenAuth{ const mutation = `mutation TokenAuth{
tokenCreate(email: "${Cypress.env("USER_NAME")}", password: "${Cypress.env( tokenCreate(email: "${Cypress.env("USER_NAME")}", password: "${Cypress.env(
"USER_PASSWORD" "USER_PASSWORD"
@ -38,5 +36,10 @@ Cypress.Commands.add("sendLoginRequest", (authorization = "auth") => {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation, authorization); return cy.sendRequestWithQuery(mutation, authorization).then(resp => {
window.sessionStorage.setItem(
authorization,
resp.body.data.tokenCreate.token
);
});
}); });