saleor-dashboard/cypress/support/customCommands/user/index.js
Karolina Rakoczy 2c64a966cc
Saleor 4437 refactor tests (#1389)
* reference type cypress working

* refactor

* remove screenshots

* add reference

* add slash marker

* run tests based on shop version

* fix run tests based on shop version

* fix run tests based on shop version

* change base url to localhost

* fix plugins

* fix plugins

* fix plugins

* fix plugins

* fix plugins

* fix plugins

* fix yml

* fix yml

* chage file names

* fix files names

* fix broken imports add checking for errors in grpah responses

* fix broken imports add checking for errors in grpah responses

* update jest

* fix snapshot
2021-09-27 12:04:21 +02:00

41 lines
1 KiB
JavaScript

import { LOGIN_SELECTORS } from "../../../elements/account/login-selectors";
import { TEST_ADMIN_USER } from "../../../fixtures/users";
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()
);
Cypress.Commands.add("loginInShop", () => {
cy.loginUserViaRequest("token");
});
Cypress.Commands.add(
"loginUserViaRequest",
(authorization = "auth", user = TEST_ADMIN_USER) => {
const mutation = `mutation TokenAuth{
tokenCreate(email: "${user.email}", password: "${user.password}") {
token
errors: accountErrors {
code
field
message
}
user {
id
}
}
}`;
return cy.sendRequestWithQuery(mutation, authorization).then(resp => {
window.sessionStorage.setItem(
authorization,
resp.body.data.tokenCreate.token
);
});
}
);