saleor-dashboard/cypress/utils/ordersUtils.js

61 lines
1.7 KiB
JavaScript
Raw Normal View History

import Checkout from "../apiRequests/Checkout";
import Order from "../apiRequests/Order";
class OrdersUtils {
2021-02-16 14:19:46 +00:00
checkoutRequest = new Checkout();
orderRequest = new Order();
checkout;
order;
2021-02-16 20:48:37 +00:00
createWaitingForCaptureOrder(
channelSlug,
email,
variantsList,
shippingMethodId
) {
2021-02-16 20:48:37 +00:00
return this.createCheckout(channelSlug, email, variantsList)
.then(() =>
this.checkoutRequest.addShippingMethod(
this.checkout.id,
shippingMethodId
)
)
.then(() => this.addPayment(this.checkout.id))
.then(() => this.checkoutRequest.completeCheckout(this.checkout.id));
2021-02-16 14:19:46 +00:00
}
2021-02-16 20:48:37 +00:00
createReadyToFulfillOrder(
customerId,
shippingMethodId,
channelId,
variantsList
) {
2021-02-16 20:48:37 +00:00
return this.createDraftOrder(customerId, shippingMethodId, channelId)
.then(() => {
variantsList.forEach(variantElement => {
this.orderRequest.addProductToOrder(this.order.id, variantElement.id);
});
})
.then(() => this.orderRequest.markOrderAsPaid(this.order.id))
.then(() => this.orderRequest.completeOrder(this.order.id));
}
createDraftOrder(customerId, shippingMethodId, channelId) {
return this.orderRequest
.createDraftOrder(customerId, shippingMethodId, channelId)
.then(resp => (this.order = resp.body.data.draftOrderCreate.order));
}
createCheckout(channelSlug, email, variantsList) {
return this.checkoutRequest
.createCheckout(channelSlug, email, 1, variantsList)
.then(resp => (this.checkout = resp.body.data.checkoutCreate.checkout));
}
addPayment(checkoutId) {
return this.checkoutRequest.addPayment(
checkoutId,
"mirumee.payments.dummy",
"not-charged"
2021-02-16 14:19:46 +00:00
);
}
}
export default OrdersUtils;