saleor-dashboard/cypress/utils/shippingUtils.js

78 lines
2 KiB
JavaScript
Raw Normal View History

import ShippingMethod from "../apiRequests/ShippingMethod";
import Warehouse from "../apiRequests/Warehouse";
class ShippingUtils {
2021-02-16 14:19:46 +00:00
shippingMethodRequest = new ShippingMethod();
warehouseRequest = new Warehouse();
2021-02-16 14:19:46 +00:00
shippingMethod;
shippingZone;
warehouse;
2021-02-23 12:09:58 +00:00
createShipping({ channelId, name, address, price = 1 }) {
2021-02-16 20:48:37 +00:00
return this.createShippingZone(name, address.country)
.then(() => this.createWarehouse(name, this.shippingZone.id, address))
.then(() => this.createShippingRate(name, this.shippingZone.id))
.then(() =>
this.shippingMethodRequest.addChannelToShippingMethod(
this.shippingMethod.id,
channelId,
price
)
);
2021-02-16 14:19:46 +00:00
}
2021-02-16 20:48:37 +00:00
createShippingZone(name, country) {
return this.shippingMethodRequest
.createShippingZone(name, country)
.then(resp => {
this.shippingZone = resp.body.data.shippingZoneCreate.shippingZone;
});
2021-02-16 14:19:46 +00:00
}
2021-02-16 20:48:37 +00:00
createWarehouse(name, shippingZoneId, address) {
return this.warehouseRequest
.createWarehouse(name, shippingZoneId, address)
.then(resp => {
this.warehouse = resp.body.data.createWarehouse.warehouse;
});
2021-02-16 14:19:46 +00:00
}
2021-02-16 20:48:37 +00:00
createShippingRate(name, shippingZoneId) {
return this.shippingMethodRequest
.createShippingRate(name, shippingZoneId)
.then(
resp =>
(this.shippingMethod =
resp.body.data.shippingPriceCreate.shippingMethod)
);
}
2021-02-16 14:19:46 +00:00
getShippingMethod() {
return this.shippingMethod;
}
2021-02-16 14:19:46 +00:00
getShippingZone() {
return this.shippingZone;
}
2021-02-16 14:19:46 +00:00
getWarehouse() {
return this.warehouse;
}
deleteShipping(startsWith) {
const shippingMethod = new ShippingMethod();
const warehouse = new Warehouse();
2021-02-16 14:19:46 +00:00
cy.deleteProperElements(
shippingMethod.deleteShippingZone,
shippingMethod.getShippingZones,
startsWith,
"shippingZONE"
);
cy.deleteProperElements(
warehouse.deleteWarehouse,
warehouse.getWarehouses,
startsWith,
"Warehouse"
);
}
}
export default ShippingUtils;