test for product without shipping option (#1154)
* test for product without shipping option * fix broken tests
This commit is contained in:
parent
5b3465861f
commit
75d85e66cb
7 changed files with 165 additions and 27 deletions
|
@ -182,6 +182,9 @@ export function addProductsToCheckout(
|
||||||
checkoutLinesUpdate(checkoutId:"${checkoutId}" lines:[${lines.join()}]){
|
checkoutLinesUpdate(checkoutId:"${checkoutId}" lines:[${lines.join()}]){
|
||||||
checkout{
|
checkout{
|
||||||
id
|
id
|
||||||
|
availableShippingMethods{
|
||||||
|
name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
errors{
|
errors{
|
||||||
field
|
field
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
import { getValueWithDefault } from "./utils/Utils";
|
import { getValueWithDefault } from "./utils/Utils";
|
||||||
|
|
||||||
export function createShippingRate(name, shippingZone) {
|
export function createShippingRate({ name, shippingZoneId }) {
|
||||||
const mutation = `mutation{
|
const mutation = `mutation{
|
||||||
shippingPriceCreate(input:{
|
shippingPriceCreate(input:{
|
||||||
name: "${name}"
|
name: "${name}"
|
||||||
shippingZone: "${shippingZone}"
|
shippingZone: "${shippingZoneId}"
|
||||||
type: PRICE
|
type: PRICE
|
||||||
}){
|
}){
|
||||||
shippingMethod{
|
shippingMethod{
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
errors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
@ -31,8 +35,8 @@ export function createShippingZone(name, country, channelId) {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
errors{
|
errors{
|
||||||
message
|
|
||||||
field
|
field
|
||||||
|
message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
@ -53,18 +57,24 @@ export function addChannelToShippingZone(shippingZoneId, channelId) {
|
||||||
}`;
|
}`;
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
export function addChannelToShippingMethod(shippingRateId, channelId, price) {
|
export function addChannelToShippingMethod(
|
||||||
|
shippingRateId,
|
||||||
|
channelId,
|
||||||
|
price,
|
||||||
|
minProductPrice = 0
|
||||||
|
) {
|
||||||
const mutation = `mutation{
|
const mutation = `mutation{
|
||||||
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
|
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
|
||||||
addChannels: {
|
addChannels: {
|
||||||
channelId:"${channelId}"
|
channelId:"${channelId}"
|
||||||
price: ${price}
|
price: ${price}
|
||||||
|
minimumOrderPrice:${minProductPrice}
|
||||||
}
|
}
|
||||||
}){
|
}){
|
||||||
shippingMethod{
|
shippingMethod{
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
shippingErrors{
|
errors{
|
||||||
code
|
code
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
|
|
118
cypress/integration/allEnv/checkout/productWithoutShipping.js
Normal file
118
cypress/integration/allEnv/checkout/productWithoutShipping.js
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
// <reference types="cypress" />
|
||||||
|
|
||||||
|
import faker from "faker";
|
||||||
|
|
||||||
|
import { createChannel } from "../../../apiRequests/Channels";
|
||||||
|
import {
|
||||||
|
addProductsToCheckout,
|
||||||
|
addShippingMethod,
|
||||||
|
createCheckout
|
||||||
|
} from "../../../apiRequests/Checkout";
|
||||||
|
import {
|
||||||
|
createProductInChannel,
|
||||||
|
createTypeAttributeAndCategoryForProduct,
|
||||||
|
deleteProductsStartsWith
|
||||||
|
} from "../../../utils/products/productsUtils";
|
||||||
|
import {
|
||||||
|
createShipping,
|
||||||
|
deleteShippingStartsWith
|
||||||
|
} from "../../../utils/shippingUtils";
|
||||||
|
|
||||||
|
describe("Products without shipment option", () => {
|
||||||
|
const startsWith = "WithoutShipmentCheckout-";
|
||||||
|
const name = `${startsWith}${faker.datatype.number()}`;
|
||||||
|
const nameProdWithoutShipping = `${startsWith}${faker.datatype.number()}`;
|
||||||
|
|
||||||
|
let channel;
|
||||||
|
let address;
|
||||||
|
let warehouse;
|
||||||
|
let shippingMethod;
|
||||||
|
let productWithShipping;
|
||||||
|
let productWithoutShipping;
|
||||||
|
|
||||||
|
before(() => {
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
|
||||||
|
deleteProductsStartsWith(startsWith);
|
||||||
|
deleteShippingStartsWith(startsWith);
|
||||||
|
|
||||||
|
createChannel({
|
||||||
|
name
|
||||||
|
})
|
||||||
|
.then(channelResp => {
|
||||||
|
channel = channelResp;
|
||||||
|
cy.fixture("addresses");
|
||||||
|
})
|
||||||
|
.then(({ usAddress }) => {
|
||||||
|
address = usAddress;
|
||||||
|
createShipping({
|
||||||
|
channelId: channel.id,
|
||||||
|
name,
|
||||||
|
address,
|
||||||
|
minProductPrice: 100
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(
|
||||||
|
({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => {
|
||||||
|
warehouse = warehouseResp;
|
||||||
|
shippingMethod = shippingMethodResp;
|
||||||
|
createTypeAttributeAndCategoryForProduct(name);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(
|
||||||
|
({
|
||||||
|
attribute: attributeResp,
|
||||||
|
productType: productTypeResp,
|
||||||
|
category: categoryResp
|
||||||
|
}) => {
|
||||||
|
createProductInChannel({
|
||||||
|
attributeId: attributeResp.id,
|
||||||
|
categoryId: categoryResp.id,
|
||||||
|
channelId: channel.id,
|
||||||
|
name,
|
||||||
|
productTypeId: productTypeResp.id,
|
||||||
|
warehouseId: warehouse.id
|
||||||
|
}).then(({ variantsList }) => (productWithShipping = variantsList));
|
||||||
|
createProductInChannel({
|
||||||
|
attributeId: attributeResp.id,
|
||||||
|
categoryId: categoryResp.id,
|
||||||
|
channelId: channel.id,
|
||||||
|
name: nameProdWithoutShipping,
|
||||||
|
productTypeId: productTypeResp.id,
|
||||||
|
warehouseId: warehouse.id
|
||||||
|
}).then(
|
||||||
|
({ variantsList }) => (productWithoutShipping = variantsList)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be not possible to buy product without shipping option", () => {
|
||||||
|
createCheckout({
|
||||||
|
channelSlug: channel.slug,
|
||||||
|
email: "example@example.com",
|
||||||
|
variantsList: productWithoutShipping,
|
||||||
|
address,
|
||||||
|
auth: "token"
|
||||||
|
})
|
||||||
|
.then(({ checkout }) => {
|
||||||
|
expect(
|
||||||
|
checkout.availableShippingMethods,
|
||||||
|
"expect no available shipping"
|
||||||
|
).to.have.length(0);
|
||||||
|
addProductsToCheckout(checkout.id, productWithShipping, 1);
|
||||||
|
})
|
||||||
|
.then(({ checkout }) => {
|
||||||
|
expect(
|
||||||
|
checkout.availableShippingMethods,
|
||||||
|
"expect no available shipping"
|
||||||
|
).to.have.length(0);
|
||||||
|
addShippingMethod(checkout.id, shippingMethod.id);
|
||||||
|
})
|
||||||
|
.then(({ errors }) => {
|
||||||
|
expect(errors[0].field, "expect error in shipping method").to.be.eq(
|
||||||
|
"shippingMethod"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -136,13 +136,13 @@ describe("Homepage analytics", () => {
|
||||||
.getOrdersReadyForCapture(defaultChannel.slug)
|
.getOrdersReadyForCapture(defaultChannel.slug)
|
||||||
.as("ordersReadyForCapture");
|
.as("ordersReadyForCapture");
|
||||||
|
|
||||||
createWaitingForCaptureOrder(
|
createWaitingForCaptureOrder({
|
||||||
defaultChannel.slug,
|
channelSlug: defaultChannel.slug,
|
||||||
randomEmail,
|
email: randomEmail,
|
||||||
createdVariants,
|
variantsList: createdVariants,
|
||||||
shippingMethod.id,
|
shippingMethodId: shippingMethod.id,
|
||||||
addresses.plAddress
|
address: addresses.plAddress
|
||||||
);
|
});
|
||||||
|
|
||||||
cy.get("@ordersReadyForCapture").then(ordersReadyForCaptureBefore => {
|
cy.get("@ordersReadyForCapture").then(ordersReadyForCaptureBefore => {
|
||||||
const allOrdersReadyForCapture = ordersReadyForCaptureBefore + 1;
|
const allOrdersReadyForCapture = ordersReadyForCaptureBefore + 1;
|
||||||
|
|
|
@ -130,13 +130,13 @@ describe("Purchase products with all products types", () => {
|
||||||
createProductInChannel(createProductData);
|
createProductInChannel(createProductData);
|
||||||
})
|
})
|
||||||
.then(({ variantsList }) => {
|
.then(({ variantsList }) => {
|
||||||
createWaitingForCaptureOrder(
|
createWaitingForCaptureOrder({
|
||||||
defaultChannel.slug,
|
channelSlug: defaultChannel.slug,
|
||||||
email,
|
email,
|
||||||
variantsList,
|
variantsList,
|
||||||
shippingMethod.id,
|
shippingMethodId: shippingMethod.id,
|
||||||
address
|
address
|
||||||
);
|
});
|
||||||
})
|
})
|
||||||
.then(({ order }) => {
|
.then(({ order }) => {
|
||||||
getOrder(order.id);
|
getOrder(order.id);
|
||||||
|
|
|
@ -2,13 +2,13 @@ import * as checkoutRequest from "../apiRequests/Checkout";
|
||||||
import * as orderRequest from "../apiRequests/Order";
|
import * as orderRequest from "../apiRequests/Order";
|
||||||
import { createProductInChannel } from "./products/productsUtils";
|
import { createProductInChannel } from "./products/productsUtils";
|
||||||
|
|
||||||
export function createWaitingForCaptureOrder(
|
export function createWaitingForCaptureOrder({
|
||||||
channelSlug,
|
channelSlug,
|
||||||
email,
|
email,
|
||||||
variantsList,
|
variantsList,
|
||||||
shippingMethodId,
|
shippingMethodId,
|
||||||
address
|
address
|
||||||
) {
|
}) {
|
||||||
let checkout;
|
let checkout;
|
||||||
const auth = "token";
|
const auth = "token";
|
||||||
cy.loginInShop();
|
cy.loginInShop();
|
||||||
|
@ -175,12 +175,12 @@ export function createOrderWithNewProduct({
|
||||||
quantityInWarehouse,
|
quantityInWarehouse,
|
||||||
trackInventory
|
trackInventory
|
||||||
}).then(({ variantsList }) =>
|
}).then(({ variantsList }) =>
|
||||||
createWaitingForCaptureOrder(
|
createWaitingForCaptureOrder({
|
||||||
channel.slug,
|
channelSlug: channel.slug,
|
||||||
"email@example.com",
|
email: "email@example.com",
|
||||||
variantsList,
|
variantsList,
|
||||||
shippingMethodId,
|
shippingMethodId,
|
||||||
address
|
address
|
||||||
)
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
import * as shippingMethodRequest from "../apiRequests/ShippingMethod";
|
import * as shippingMethodRequest from "../apiRequests/ShippingMethod";
|
||||||
import * as warehouseRequest from "../apiRequests/Warehouse";
|
import * as warehouseRequest from "../apiRequests/Warehouse";
|
||||||
|
|
||||||
export function createShipping({ channelId, name, address, price = 1 }) {
|
export function createShipping({
|
||||||
|
channelId,
|
||||||
|
name,
|
||||||
|
address,
|
||||||
|
price = 1,
|
||||||
|
minProductPrice = 0
|
||||||
|
}) {
|
||||||
let shippingMethod;
|
let shippingMethod;
|
||||||
let shippingZone;
|
let shippingZone;
|
||||||
let warehouse;
|
let warehouse;
|
||||||
|
@ -18,21 +24,22 @@ export function createShipping({ channelId, name, address, price = 1 }) {
|
||||||
})
|
})
|
||||||
.then(warehouseResp => {
|
.then(warehouseResp => {
|
||||||
warehouse = warehouseResp;
|
warehouse = warehouseResp;
|
||||||
createShippingRate(name, shippingZone.id);
|
createShippingRate({ name, shippingZoneId: shippingZone.id });
|
||||||
})
|
})
|
||||||
.then(sippingMethodResp => {
|
.then(sippingMethodResp => {
|
||||||
shippingMethod = sippingMethodResp;
|
shippingMethod = sippingMethodResp;
|
||||||
shippingMethodRequest.addChannelToShippingMethod(
|
shippingMethodRequest.addChannelToShippingMethod(
|
||||||
shippingMethod.id,
|
shippingMethod.id,
|
||||||
channelId,
|
channelId,
|
||||||
price
|
price,
|
||||||
|
minProductPrice
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then(() => ({ shippingMethod, shippingZone, warehouse }));
|
.then(() => ({ shippingMethod, shippingZone, warehouse }));
|
||||||
}
|
}
|
||||||
export function createShippingRate(name, shippingZoneId) {
|
export function createShippingRate({ name, shippingZoneId }) {
|
||||||
return shippingMethodRequest
|
return shippingMethodRequest
|
||||||
.createShippingRate(name, shippingZoneId)
|
.createShippingRate({ name, shippingZoneId })
|
||||||
.its("body.data.shippingPriceCreate.shippingMethod");
|
.its("body.data.shippingPriceCreate.shippingMethod");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue