2021-09-27 10:04:21 +00:00
|
|
|
import { LOGIN_SELECTORS } from "../../../elements/account/login-selectors";
|
|
|
|
import { TEST_ADMIN_USER } from "../../../fixtures/users";
|
2020-08-20 13:36:00 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add("loginUser", () =>
|
|
|
|
cy
|
|
|
|
.get(LOGIN_SELECTORS.emailAddressInput)
|
|
|
|
.type(Cypress.env("USER_NAME"))
|
|
|
|
.get(LOGIN_SELECTORS.emailPasswordInput)
|
|
|
|
.type(Cypress.env("USER_PASSWORD"), { log: false })
|
|
|
|
.get(LOGIN_SELECTORS.signInButton)
|
|
|
|
.click()
|
|
|
|
);
|
2020-08-25 14:15:39 +00:00
|
|
|
|
2021-02-24 09:27:57 +00:00
|
|
|
Cypress.Commands.add("loginInShop", () => {
|
2021-02-24 11:19:17 +00:00
|
|
|
cy.loginUserViaRequest("token");
|
2021-02-24 09:27:57 +00:00
|
|
|
});
|
|
|
|
|
2021-03-23 10:14:18 +00:00
|
|
|
Cypress.Commands.add(
|
|
|
|
"loginUserViaRequest",
|
|
|
|
(authorization = "auth", user = TEST_ADMIN_USER) => {
|
|
|
|
const mutation = `mutation TokenAuth{
|
|
|
|
tokenCreate(email: "${user.email}", password: "${user.password}") {
|
2020-08-27 07:03:10 +00:00
|
|
|
token
|
2021-12-17 13:27:13 +00:00
|
|
|
csrfToken
|
|
|
|
refreshToken
|
2022-06-06 08:47:39 +00:00
|
|
|
errors: errors {
|
2020-08-27 07:03:10 +00:00
|
|
|
code
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
user {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-03-23 10:14:18 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation, authorization).then(resp => {
|
2021-12-17 13:27:13 +00:00
|
|
|
window.localStorage.setItem(
|
|
|
|
"_saleorCSRFToken",
|
|
|
|
resp.body.data.tokenCreate.csrfToken
|
|
|
|
);
|
2021-03-23 10:14:18 +00:00
|
|
|
window.sessionStorage.setItem(
|
|
|
|
authorization,
|
|
|
|
resp.body.data.tokenCreate.token
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|