saleor-dashboard/cypress/utils/shippingUtils.js

78 lines
2.3 KiB
JavaScript
Raw Normal View History

import ShippingMethod from "../apiRequests/ShippingMethod";
import Warehouse from "../apiRequests/Warehouse";
2021-02-16 14:19:46 +00:00
import Promises from "../support/promises/promises.js";
class ShippingUtils {
2021-02-16 14:19:46 +00:00
promises = new Promises();
shippingMethodRequest = new ShippingMethod();
warehouseRequest = new Warehouse();
2021-02-16 14:19:46 +00:00
shippingMethod;
shippingZone;
warehouse;
async createShipping(channelId, name, address, price) {
await this.createShippingZone(name, address.country);
await this.createWarehouse(name, this.shippingZone.id, address);
await this.createShippingRate(name, this.shippingZone.id);
this.addChannelToShippingMethod(this.shippingMethod.id, channelId, price);
}
async createShippingZone(name, country) {
const respProm = await this.promises.createPromise(
this.shippingMethodRequest.createShippingZone(name, country)
);
this.shippingZone = respProm.shippingZoneCreate.shippingZone;
}
async createWarehouse(name, shippingZoneId, address) {
const respProm = await this.promises.createPromise(
this.warehouseRequest.createWarehouse(name, shippingZoneId, address)
);
this.warehouse = respProm.createWarehouse.warehouse;
}
async createShippingRate(name, shippingZoneId) {
const respProm = await this.promises.createPromise(
this.shippingMethodRequest.createShippingRate(name, shippingZoneId)
);
this.shippingMethod = respProm.shippingPriceCreate.shippingMethod;
}
async addChannelToShippingMethod(shippingMethodId, channelId, price) {
await this.promises.createPromise(
this.shippingMethodRequest.addChannelToShippingMethod(
shippingMethodId,
channelId,
price
)
);
}
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;