saleor-dashboard/cypress/support/api/requests/utils/index.js

37 lines
878 B
JavaScript
Raw Normal View History

// / <reference types="cypress" />
import { urlList } from "../../../../fixtures/urlList";
Cypress.Commands.add(
"sendRequestWithQuery",
(query, authorization = "auth", variables = "") => {
2022-11-28 11:36:53 +00:00
let headers;
if (authorization && authorization.length !== 30) {
headers = {
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`,
};
} else if (authorization) {
headers = { Authorization: `Bearer ${authorization}` };
} else {
2022-11-28 11:36:53 +00:00
headers = {};
}
2022-11-28 11:36:53 +00:00
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));
}
});
},
);