saleor-dashboard/cypress/support/api/utils/shippingUtils.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

59 lines
1.6 KiB
JavaScript

import * as shippingMethodRequest from "../requests/ShippingMethod";
import * as warehouseRequest from "../requests/Warehouse";
export function createShipping({
channelId,
name,
address,
price = 1,
minProductPrice = 0
}) {
let shippingMethod;
let shippingZone;
let warehouse;
return shippingMethodRequest
.createShippingZone(name, address.country, channelId)
.then(shippingZoneResp => {
shippingZone = shippingZoneResp;
warehouseRequest.createWarehouse({
name,
shippingZone: shippingZone.id,
address
});
})
.then(warehouseResp => {
warehouse = warehouseResp;
shippingMethodRequest.createShippingRate({
name,
shippingZone: shippingZone.id
});
})
.then(({ shippingMethod: sippingMethodResp }) => {
shippingMethod = sippingMethodResp;
shippingMethodRequest.addChannelToShippingMethod(
shippingMethod.id,
channelId,
price,
minProductPrice
);
})
.then(() => ({ shippingMethod, shippingZone, warehouse }));
}
export function createShippingRate({ name, shippingZoneId }) {
return shippingMethodRequest
.createShippingRate({ name, shippingZoneId })
.its("body.data.shippingPriceCreate.shippingMethod");
}
export function deleteShippingStartsWith(startsWith) {
cy.deleteElementsStartsWith(
shippingMethodRequest.deleteShippingZone,
shippingMethodRequest.getShippingZones,
startsWith
).deleteElementsStartsWith(
warehouseRequest.deleteWarehouse,
warehouseRequest.getWarehouses,
startsWith
);
}