saleor-dashboard/cypress/support/api/utils/shippingUtils.js

85 lines
2.1 KiB
JavaScript
Raw Normal View History

import * as shippingMethodRequest from "../requests/ShippingMethod";
import * as warehouseRequest from "../requests/Warehouse";
import { getDefaultChannel } from "./channelsUtils";
export function createShipping({
channelId,
name,
address,
price = 1,
minProductPrice = 0
}) {
let shippingMethod;
let shippingZone;
let warehouse;
2021-02-16 14:19:46 +00:00
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
2021-02-16 20:48:37 +00:00
);
})
.then(() => ({ shippingMethod, shippingZone, warehouse }));
}
export function createShippingWithDefaultChannelAndAddress(name) {
let defaultChannel;
return getDefaultChannel()
.then(channel => {
defaultChannel = channel;
cy.fixture("addresses");
})
.then(fixtureAddresses =>
createShipping({
channelId: defaultChannel.id,
name,
address: fixtureAddresses.plAddress
})
)
.then(({ shippingMethod, shippingZone, warehouse }) => ({
shippingMethod,
shippingZone,
warehouse,
defaultChannel
}));
}
export function createShippingRate({ name, shippingZoneId }) {
return shippingMethodRequest
2022-01-14 10:08:25 +00:00
.createShippingRate({ name, shippingZone: shippingZoneId })
.its("body.data.shippingPriceCreate.shippingMethod");
}
export function deleteShippingStartsWith(startsWith) {
cy.deleteElementsStartsWith(
shippingMethodRequest.deleteShippingZone,
shippingMethodRequest.getShippingZones,
startsWith
).deleteElementsStartsWith(
warehouseRequest.deleteWarehouse,
warehouseRequest.getWarehouses,
startsWith
);
}