tests for products -change login cy command
This commit is contained in:
parent
ac7f1b19b6
commit
f1c86f0a4d
1 changed files with 17 additions and 43 deletions
|
@ -1,5 +1,4 @@
|
||||||
import { LOGIN_SELECTORS } from "../../elements/account/login-selectors";
|
import { LOGIN_SELECTORS } from "../../elements/account/login-selectors";
|
||||||
import { urlList } from "../../url/urlList";
|
|
||||||
|
|
||||||
Cypress.Commands.add("loginUser", () =>
|
Cypress.Commands.add("loginUser", () =>
|
||||||
cy
|
cy
|
||||||
|
@ -12,57 +11,32 @@ Cypress.Commands.add("loginUser", () =>
|
||||||
);
|
);
|
||||||
|
|
||||||
Cypress.Commands.add("loginUserViaRequest", () => {
|
Cypress.Commands.add("loginUserViaRequest", () => {
|
||||||
const logInMutationQuery = `mutation TokenAuth($email: String!, $password: String!) {
|
cy.sendLoginRequest().then(resp => {
|
||||||
tokenCreate(email: $email, password: $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);
|
window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Cypress.Commands.add("loginInShop", () => {
|
Cypress.Commands.add("loginInShop", () => {
|
||||||
cy.request({
|
cy.sendLoginRequest("token").then(resp => {
|
||||||
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);
|
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
|
||||||
|
}
|
||||||
|
user {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation, authorization);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue