test for product without shipping option (#1154)

* test for product without shipping option

* fix broken tests
This commit is contained in:
Karolina Rakoczy 2021-07-06 12:33:04 +02:00 committed by GitHub
parent 5b3465861f
commit 75d85e66cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 165 additions and 27 deletions

View file

@ -182,6 +182,9 @@ export function addProductsToCheckout(
checkoutLinesUpdate(checkoutId:"${checkoutId}" lines:[${lines.join()}]){
checkout{
id
availableShippingMethods{
name
}
}
errors{
field

View file

@ -1,15 +1,19 @@
import { getValueWithDefault } from "./utils/Utils";
export function createShippingRate(name, shippingZone) {
export function createShippingRate({ name, shippingZoneId }) {
const mutation = `mutation{
shippingPriceCreate(input:{
name: "${name}"
shippingZone: "${shippingZone}"
shippingZone: "${shippingZoneId}"
type: PRICE
}){
shippingMethod{
id
}
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
@ -31,8 +35,8 @@ export function createShippingZone(name, country, channelId) {
name
}
errors{
message
field
message
}
}
}`;
@ -53,18 +57,24 @@ export function addChannelToShippingZone(shippingZoneId, channelId) {
}`;
return cy.sendRequestWithQuery(mutation);
}
export function addChannelToShippingMethod(shippingRateId, channelId, price) {
export function addChannelToShippingMethod(
shippingRateId,
channelId,
price,
minProductPrice = 0
) {
const mutation = `mutation{
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
addChannels: {
channelId:"${channelId}"
price: ${price}
minimumOrderPrice:${minProductPrice}
}
}){
shippingMethod{
id
}
shippingErrors{
errors{
code
message
}

View 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"
);
});
});
});

View file

@ -136,13 +136,13 @@ describe("Homepage analytics", () => {
.getOrdersReadyForCapture(defaultChannel.slug)
.as("ordersReadyForCapture");
createWaitingForCaptureOrder(
defaultChannel.slug,
randomEmail,
createdVariants,
shippingMethod.id,
addresses.plAddress
);
createWaitingForCaptureOrder({
channelSlug: defaultChannel.slug,
email: randomEmail,
variantsList: createdVariants,
shippingMethodId: shippingMethod.id,
address: addresses.plAddress
});
cy.get("@ordersReadyForCapture").then(ordersReadyForCaptureBefore => {
const allOrdersReadyForCapture = ordersReadyForCaptureBefore + 1;

View file

@ -130,13 +130,13 @@ describe("Purchase products with all products types", () => {
createProductInChannel(createProductData);
})
.then(({ variantsList }) => {
createWaitingForCaptureOrder(
defaultChannel.slug,
createWaitingForCaptureOrder({
channelSlug: defaultChannel.slug,
email,
variantsList,
shippingMethod.id,
shippingMethodId: shippingMethod.id,
address
);
});
})
.then(({ order }) => {
getOrder(order.id);

View file

@ -2,13 +2,13 @@ import * as checkoutRequest from "../apiRequests/Checkout";
import * as orderRequest from "../apiRequests/Order";
import { createProductInChannel } from "./products/productsUtils";
export function createWaitingForCaptureOrder(
export function createWaitingForCaptureOrder({
channelSlug,
email,
variantsList,
shippingMethodId,
address
) {
}) {
let checkout;
const auth = "token";
cy.loginInShop();
@ -175,12 +175,12 @@ export function createOrderWithNewProduct({
quantityInWarehouse,
trackInventory
}).then(({ variantsList }) =>
createWaitingForCaptureOrder(
channel.slug,
"email@example.com",
createWaitingForCaptureOrder({
channelSlug: channel.slug,
email: "email@example.com",
variantsList,
shippingMethodId,
address
)
})
);
}

View file

@ -1,7 +1,13 @@
import * as shippingMethodRequest from "../apiRequests/ShippingMethod";
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 shippingZone;
let warehouse;
@ -18,21 +24,22 @@ export function createShipping({ channelId, name, address, price = 1 }) {
})
.then(warehouseResp => {
warehouse = warehouseResp;
createShippingRate(name, shippingZone.id);
createShippingRate({ name, shippingZoneId: shippingZone.id });
})
.then(sippingMethodResp => {
shippingMethod = sippingMethodResp;
shippingMethodRequest.addChannelToShippingMethod(
shippingMethod.id,
channelId,
price
price,
minProductPrice
);
})
.then(() => ({ shippingMethod, shippingZone, warehouse }));
}
export function createShippingRate(name, shippingZoneId) {
export function createShippingRate({ name, shippingZoneId }) {
return shippingMethodRequest
.createShippingRate(name, shippingZoneId)
.createShippingRate({ name, shippingZoneId })
.its("body.data.shippingPriceCreate.shippingMethod");
}