2021-04-28 13:10:47 +00:00
|
|
|
import { getDefaultAddress, getVariantsLines } from "./utils/Utils";
|
|
|
|
|
2021-03-23 10:15:39 +00:00
|
|
|
export function createCheckout({
|
2021-03-12 12:14:18 +00:00
|
|
|
channelSlug,
|
|
|
|
email,
|
2021-03-23 10:15:39 +00:00
|
|
|
productQuantity = 1,
|
|
|
|
variantsList,
|
|
|
|
address,
|
2021-04-28 13:10:47 +00:00
|
|
|
billingAddress,
|
2021-03-23 10:15:39 +00:00
|
|
|
auth = "auth"
|
|
|
|
}) {
|
2021-04-28 13:10:47 +00:00
|
|
|
const lines = getVariantsLines(variantsList, productQuantity);
|
2021-03-23 10:15:39 +00:00
|
|
|
const shippingAddress = getDefaultAddress(address, "shippingAddress");
|
2021-04-28 13:10:47 +00:00
|
|
|
const billingAddressLines = getDefaultAddress(
|
|
|
|
billingAddress,
|
|
|
|
"billingAddress"
|
|
|
|
);
|
2021-03-23 10:15:39 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
const mutation = `mutation{
|
2021-03-12 14:57:02 +00:00
|
|
|
checkoutCreate(input:{
|
|
|
|
channel:"${channelSlug}"
|
|
|
|
email:"${email}"
|
|
|
|
lines: [${lines.join()}]
|
2021-03-23 10:15:39 +00:00
|
|
|
${shippingAddress}
|
2021-04-28 13:10:47 +00:00
|
|
|
${billingAddressLines}
|
2021-03-12 14:57:02 +00:00
|
|
|
}){
|
|
|
|
checkoutErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
created
|
|
|
|
checkout{
|
|
|
|
id
|
2021-04-02 11:01:38 +00:00
|
|
|
availableShippingMethods{
|
|
|
|
name
|
|
|
|
}
|
2021-03-12 14:57:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-04-28 13:10:47 +00:00
|
|
|
return cy
|
|
|
|
.sendRequestWithQuery(mutation, auth)
|
|
|
|
.its("body.data.checkoutCreate.checkout");
|
2021-03-12 12:14:18 +00:00
|
|
|
}
|
|
|
|
export function addShippingMethod(checkoutId, shippingMethodId) {
|
|
|
|
const mutation = `mutation{
|
2021-03-12 14:57:02 +00:00
|
|
|
checkoutShippingMethodUpdate(checkoutId:"${checkoutId}",
|
|
|
|
shippingMethodId:"${shippingMethodId}"){
|
|
|
|
checkoutErrors{
|
|
|
|
message
|
|
|
|
field
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-03-12 12:14:18 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
2021-04-28 13:10:47 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
export function addPayment(checkoutId, gateway, token) {
|
|
|
|
const mutation = `mutation{
|
2021-03-12 14:57:02 +00:00
|
|
|
checkoutPaymentCreate(checkoutId:"${checkoutId}",
|
|
|
|
input:{
|
|
|
|
gateway: "${gateway}"
|
|
|
|
token:"${token}"
|
|
|
|
}){
|
|
|
|
paymentErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-04-28 13:10:47 +00:00
|
|
|
return cy
|
|
|
|
.sendRequestWithQuery(mutation)
|
|
|
|
.its("body.data.checkoutPaymentCreate");
|
2021-03-12 12:14:18 +00:00
|
|
|
}
|
2021-04-28 13:10:47 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
export function completeCheckout(checkoutId) {
|
|
|
|
const mutation = `mutation{
|
2021-03-12 14:57:02 +00:00
|
|
|
checkoutComplete(checkoutId:"${checkoutId}"){
|
|
|
|
order{
|
|
|
|
id
|
|
|
|
}
|
|
|
|
confirmationNeeded
|
|
|
|
confirmationData
|
|
|
|
checkoutErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-04-28 13:10:47 +00:00
|
|
|
return cy
|
|
|
|
.sendRequestWithQuery(mutation)
|
|
|
|
.its("body.data.checkoutComplete.order");
|
2021-02-02 11:34:10 +00:00
|
|
|
}
|
2021-03-23 10:15:39 +00:00
|
|
|
|
|
|
|
export function addVoucher(checkoutId, voucherCode) {
|
|
|
|
const mutation = `mutation addVoucher{
|
|
|
|
checkoutAddPromoCode(checkoutId:"${checkoutId}",
|
|
|
|
promoCode:"${voucherCode}"
|
|
|
|
){
|
|
|
|
checkoutErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
checkout{
|
|
|
|
totalPrice{
|
|
|
|
gross{
|
|
|
|
amount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
2021-04-28 13:10:47 +00:00
|
|
|
|
|
|
|
export function checkoutVariantsUpdate(checkoutId, variantsList) {
|
|
|
|
const lines = getVariantsLines(variantsList, 1);
|
|
|
|
const mutation = `mutation{
|
|
|
|
checkoutLinesUpdate(checkoutId:"${checkoutId}",
|
|
|
|
lines: [${lines.join()}]){
|
|
|
|
checkoutErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function checkoutShippingMethodUpdate(checkoutId, shippingMethodId) {
|
|
|
|
const mutation = `mutation{
|
|
|
|
checkoutShippingMethodUpdate(checkoutId:"${checkoutId}" shippingMethodId:"${shippingMethodId}"){
|
|
|
|
checkoutErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy
|
|
|
|
.sendRequestWithQuery(mutation)
|
|
|
|
.its("body.data.checkoutShippingMethodUpdate");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function checkoutShippingAddressUpdate(checkoutId, address) {
|
|
|
|
const shippingAddress = getDefaultAddress(address, "shippingAddress");
|
|
|
|
const mutation = `mutation{
|
|
|
|
checkoutShippingAddressUpdate(checkoutId:"${checkoutId}",
|
|
|
|
${shippingAddress}
|
|
|
|
){
|
|
|
|
checkoutErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|