clear session data when needed (#2711)

This commit is contained in:
Karolina Rakoczy 2022-11-28 12:36:53 +01:00 committed by GitHub
parent 17e3c4c8f2
commit ea2cd5fe96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 37 deletions

View file

@ -43,7 +43,6 @@ describe("As an unlogged customer I want to order physical and digital products"
shippingMethod = resp.shippingMethod;
digitalVariants = resp.digitalVariants;
physicalVariants = resp.physicalVariants;
cy.clearSessionData();
});
});

View file

@ -5,42 +5,32 @@ import { urlList } from "../../../../fixtures/urlList";
Cypress.Commands.add(
"sendRequestWithQuery",
(query, authorization = "auth", variables = "") => {
if (authorization.length !== 30) {
cy.request({
body: {
variables,
query,
},
headers: {
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`,
},
method: "POST",
url: urlList.apiUri,
log: true,
}).then(response => {
const respInSting = JSON.stringify(response.body);
if (respInSting.includes(`"errors":[{`)) {
cy.log(query).log(JSON.stringify(response.body));
}
});
let headers;
if (authorization && authorization.length !== 30) {
headers = {
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`,
};
} else if (authorization) {
headers = { Authorization: `Bearer ${authorization}` };
} else {
cy.request({
body: {
variables,
query,
},
headers: {
Authorization: `Bearer ${authorization}`,
},
method: "POST",
url: urlList.apiUri,
log: true,
}).then(response => {
const respInSting = JSON.stringify(response.body);
if (respInSting.includes(`"errors":[{`)) {
cy.log(query).log(JSON.stringify(response.body));
}
});
headers = {};
}
cy.request({
body: {
variables,
query,
},
headers,
method: "POST",
url: urlList.apiUri,
log: true,
}).then(response => {
const respInSting = JSON.stringify(response.body);
if (respInSting.includes(`"errors":[{`)) {
cy.log(query).log(JSON.stringify(response.body));
}
});
},
);

View file

@ -35,7 +35,7 @@ Cypress.Commands.add(
}
}
}`;
return cy.sendRequestWithQuery(mutation, authorization).then(resp => {
return cy.sendRequestWithQuery(mutation, null).then(resp => {
window.localStorage.setItem(
"_saleorCSRFToken",
resp.body.data.tokenCreate.csrfToken,

View file

@ -27,6 +27,7 @@ cypressGrep();
Cypress.Commands.add("clearSessionData", () => {
cy.clearCookies();
cy.clearLocalStorage();
window.sessionStorage.clear();
});
Cypress.Commands.add("addAliasToGraphRequest", operationName => {