tests for products -change login cy command

This commit is contained in:
Karolina Rakoczy 2021-02-24 10:27:57 +01:00
parent ac7f1b19b6
commit f1c86f0a4d

View file

@ -1,5 +1,4 @@
import { LOGIN_SELECTORS } from "../../elements/account/login-selectors";
import { urlList } from "../../url/urlList";
Cypress.Commands.add("loginUser", () =>
cy
@ -12,57 +11,32 @@ Cypress.Commands.add("loginUser", () =>
);
Cypress.Commands.add("loginUserViaRequest", () => {
const logInMutationQuery = `mutation TokenAuth($email: String!, $password: String!) {
tokenCreate(email: $email, password: $password) {
cy.sendLoginRequest().then(resp => {
window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token);
});
});
Cypress.Commands.add("loginInShop", () => {
cy.sendLoginRequest("token").then(resp => {
window.sessionStorage.setItem("token", resp.body[0].data.tokenCreate.token);
});
});
Cypress.Commands.add("sendLoginRequest", (authorization = "auth") => {
const mutation = `mutation TokenAuth{
tokenCreate(email: "${Cypress.env("USER_NAME")}", password: "${Cypress.env(
"USER_PASSWORD"
)}") {
token
errors: accountErrors {
code
field
message
__typename
}
user {
id
__typename
}
__typename
}
}`;
return cy
.request({
body: {
operationName: "TokenAuth",
query: logInMutationQuery,
variables: {
email: Cypress.env("USER_NAME"),
password: Cypress.env("USER_PASSWORD")
}
},
method: "POST",
url: urlList.apiUri
})
.then(resp => {
window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token);
});
});
Cypress.Commands.add("loginInShop", () => {
cy.request({
method: "POST",
url: Cypress.env("API_URI"),
body: [
{
operationName: "TokenAuth",
variables: {
email: Cypress.env("USER_NAME"),
password: Cypress.env("USER_PASSWORD")
},
query:
"mutation TokenAuth($email: String!, $password: String!) {\n tokenCreate(email: $email, password: $password) {\n token\n errors: accountErrors {\n code\n field\n message\n __typename\n }\n user {\n id\n __typename\n }\n __typename\n }\n}\n"
}
]
}).then(resp => {
window.sessionStorage.setItem("token", resp.body[0].data.tokenCreate.token);
});
return cy.sendRequestWithQuery(mutation, authorization);
});