2021-11-03 11:15:39 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../../support"/>
|
|
|
|
|
|
|
|
import faker from "faker";
|
|
|
|
|
|
|
|
import { WAREHOUSES_DETAILS } from "../../elements/warehouses/warehouse-details";
|
|
|
|
import {
|
|
|
|
completeCheckout,
|
|
|
|
createCheckout,
|
2022-06-27 16:49:35 +00:00
|
|
|
deliveryMethodUpdate,
|
2021-11-03 11:15:39 +00:00
|
|
|
} from "../../support/api/requests/Checkout";
|
|
|
|
import { getOrder } from "../../support/api/requests/Order";
|
|
|
|
import { updateWarehouse } from "../../support/api/requests/Warehouse";
|
|
|
|
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
|
|
|
|
import { addPayment } from "../../support/api/utils/ordersUtils";
|
|
|
|
import {
|
|
|
|
createProductInChannel,
|
|
|
|
createTypeAttributeAndCategoryForProduct,
|
2022-06-27 16:49:35 +00:00
|
|
|
deleteProductsStartsWith,
|
2021-11-03 11:15:39 +00:00
|
|
|
} from "../../support/api/utils/products/productsUtils";
|
|
|
|
import {
|
|
|
|
createShipping,
|
2022-06-27 16:49:35 +00:00
|
|
|
deleteShippingStartsWith,
|
2021-11-03 11:15:39 +00:00
|
|
|
} from "../../support/api/utils/shippingUtils";
|
|
|
|
import {
|
|
|
|
createWarehouse,
|
|
|
|
pickupOptions,
|
|
|
|
visitAndEnablePickup,
|
2022-06-27 16:49:35 +00:00
|
|
|
visitSetPublicStockAndEnablePickup,
|
2021-11-03 11:15:39 +00:00
|
|
|
} from "../../support/pages/warehousePage";
|
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
describe("Warehouses in checkout", () => {
|
|
|
|
const startsWith = `CyWarehouseCheckout`;
|
|
|
|
let defaultChannel;
|
|
|
|
let usAddress;
|
|
|
|
let secondUsAddress;
|
|
|
|
let plAddress;
|
|
|
|
let productData;
|
|
|
|
let checkoutData;
|
|
|
|
let variantsInOtherWarehouse;
|
2021-11-03 11:15:39 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
before(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
deleteShippingStartsWith(startsWith);
|
|
|
|
deleteProductsStartsWith(startsWith);
|
|
|
|
cy.fixture("addresses")
|
|
|
|
.then(addresses => {
|
|
|
|
usAddress = addresses.usAddress;
|
|
|
|
secondUsAddress = addresses.secondUsAddress;
|
|
|
|
plAddress = addresses.plAddress;
|
|
|
|
getDefaultChannel();
|
|
|
|
})
|
|
|
|
.then(channelResp => {
|
|
|
|
defaultChannel = channelResp;
|
|
|
|
createTypeAttributeAndCategoryForProduct({ name: startsWith });
|
|
|
|
})
|
|
|
|
.then(({ attribute, productType, category }) => {
|
|
|
|
productData = {
|
|
|
|
attributeId: attribute.id,
|
|
|
|
categoryId: category.id,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
productTypeId: productType.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
quantityInWarehouse: 100,
|
2022-06-27 09:30:51 +00:00
|
|
|
};
|
|
|
|
checkoutData = {
|
|
|
|
returnAvailableCollectionPoints: true,
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
email: "example@example.com",
|
2022-06-27 16:49:35 +00:00
|
|
|
address: secondUsAddress,
|
2022-07-11 09:14:23 +00:00
|
|
|
billingAddress: usAddress,
|
2022-06-27 09:30:51 +00:00
|
|
|
};
|
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name: startsWith,
|
2022-06-27 16:49:35 +00:00
|
|
|
address: secondUsAddress,
|
2021-11-03 11:15:39 +00:00
|
|
|
});
|
2022-06-27 09:30:51 +00:00
|
|
|
})
|
|
|
|
.then(({ warehouse: warehouseResp }) => {
|
|
|
|
productData.name = startsWith;
|
|
|
|
productData.warehouseId = warehouseResp.id;
|
|
|
|
updateWarehouse({ id: productData.warehouseId, isPrivate: false });
|
|
|
|
createProductInChannel(productData);
|
|
|
|
})
|
|
|
|
.then(({ variantsList }) => {
|
|
|
|
variantsInOtherWarehouse = variantsList;
|
|
|
|
});
|
|
|
|
});
|
2021-11-03 11:15:39 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
});
|
2021-11-03 11:15:39 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
xit(
|
|
|
|
"should create warehouse with all warehouses pickup and private stock",
|
|
|
|
{ tags: ["@checkout", "@allEnv"] },
|
|
|
|
() => {
|
2021-11-03 11:15:39 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let warehouse;
|
|
|
|
|
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name,
|
2022-06-27 16:49:35 +00:00
|
|
|
address: secondUsAddress,
|
2021-11-03 11:15:39 +00:00
|
|
|
})
|
|
|
|
.then(({ warehouse: warehouseResp }) => {
|
|
|
|
warehouse = warehouseResp;
|
|
|
|
visitAndEnablePickup(warehouse.id);
|
|
|
|
productData.name = name;
|
|
|
|
productData.warehouseId = warehouse.id;
|
|
|
|
createProductInChannel(productData);
|
|
|
|
})
|
|
|
|
.then(({ variantsList }) => {
|
|
|
|
checkoutData.variantsList = variantsList.concat(
|
2022-06-27 16:49:35 +00:00
|
|
|
variantsInOtherWarehouse,
|
2021-11-03 11:15:39 +00:00
|
|
|
);
|
|
|
|
createCheckout(checkoutData);
|
|
|
|
})
|
|
|
|
.then(({ checkout }) => {
|
|
|
|
const clickAndCollectOption = checkout.availableCollectionPoints.find(
|
2022-06-27 16:49:35 +00:00
|
|
|
element => element.id === warehouse.id,
|
2021-11-03 11:15:39 +00:00
|
|
|
);
|
|
|
|
expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL");
|
|
|
|
expect(clickAndCollectOption.id).to.eq(warehouse.id);
|
|
|
|
expect(clickAndCollectOption.isPrivate).to.eq(true);
|
|
|
|
expect(clickAndCollectOption.name).to.eq(warehouse.name);
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-11-03 11:15:39 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
xit(
|
|
|
|
"should create warehouse with all warehouses pickup and public stock",
|
|
|
|
{ tags: ["@checkout", "@allEnv"] },
|
|
|
|
() => {
|
2021-11-03 11:15:39 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let warehouse;
|
|
|
|
|
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name,
|
2022-06-27 16:49:35 +00:00
|
|
|
address: secondUsAddress,
|
2021-11-03 11:15:39 +00:00
|
|
|
})
|
|
|
|
.then(({ warehouse: warehouseResp }) => {
|
|
|
|
warehouse = warehouseResp;
|
|
|
|
visitSetPublicStockAndEnablePickup(warehouse.id);
|
|
|
|
productData.name = name;
|
|
|
|
productData.warehouseId = warehouse.id;
|
|
|
|
createProductInChannel(productData);
|
|
|
|
})
|
|
|
|
.then(({ variantsList }) => {
|
|
|
|
checkoutData.variantsList = variantsList.concat(
|
2022-06-27 16:49:35 +00:00
|
|
|
variantsInOtherWarehouse,
|
2021-11-03 11:15:39 +00:00
|
|
|
);
|
|
|
|
createCheckout(checkoutData);
|
|
|
|
})
|
|
|
|
.then(({ checkout }) => {
|
|
|
|
const clickAndCollectOption = checkout.availableCollectionPoints.find(
|
2022-06-27 16:49:35 +00:00
|
|
|
element => element.id === warehouse.id,
|
2021-11-03 11:15:39 +00:00
|
|
|
);
|
|
|
|
expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL");
|
|
|
|
expect(clickAndCollectOption.id).to.eq(warehouse.id);
|
|
|
|
expect(clickAndCollectOption.isPrivate).to.eq(false);
|
|
|
|
expect(clickAndCollectOption.name).to.eq(warehouse.name);
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-11-03 11:15:39 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
xit(
|
|
|
|
"should create warehouse with local stock only pickup and public stock",
|
|
|
|
{ tags: ["@checkout", "@allEnv"] },
|
|
|
|
() => {
|
2021-11-03 11:15:39 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let warehouse;
|
|
|
|
let variantsInLocalStock;
|
|
|
|
|
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name,
|
2022-06-27 16:49:35 +00:00
|
|
|
address: secondUsAddress,
|
2021-11-03 11:15:39 +00:00
|
|
|
})
|
|
|
|
.then(({ warehouse: warehouseResp }) => {
|
|
|
|
warehouse = warehouseResp;
|
|
|
|
visitSetPublicStockAndEnablePickup(warehouse.id, pickupOptions.local);
|
|
|
|
productData.name = name;
|
|
|
|
productData.warehouseId = warehouse.id;
|
|
|
|
createProductInChannel(productData);
|
|
|
|
})
|
|
|
|
.then(({ variantsList }) => {
|
|
|
|
variantsInLocalStock = variantsList;
|
|
|
|
checkoutData.variantsList = variantsInLocalStock.concat(
|
2022-06-27 16:49:35 +00:00
|
|
|
variantsInOtherWarehouse,
|
2021-11-03 11:15:39 +00:00
|
|
|
);
|
|
|
|
createCheckout(checkoutData);
|
|
|
|
})
|
|
|
|
.then(({ checkout }) => {
|
|
|
|
expect(checkout.availableCollectionPoints).to.have.length(
|
|
|
|
1,
|
2022-06-27 16:49:35 +00:00
|
|
|
"there should be no available collection point for local stock",
|
2021-11-03 11:15:39 +00:00
|
|
|
);
|
|
|
|
checkoutData.variantsList = variantsInLocalStock;
|
|
|
|
createCheckout(checkoutData);
|
|
|
|
})
|
|
|
|
.then(({ checkout }) => {
|
|
|
|
const clickAndCollectOption = checkout.availableCollectionPoints[0];
|
|
|
|
expect(clickAndCollectOption.clickAndCollectOption).to.eq("LOCAL");
|
|
|
|
expect(clickAndCollectOption.id).to.eq(warehouse.id);
|
|
|
|
expect(clickAndCollectOption.isPrivate).to.eq(false);
|
|
|
|
expect(clickAndCollectOption.name).to.eq(warehouse.name);
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-11-03 11:15:39 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
xit(
|
|
|
|
"should not be possible to set local pickup when private stock",
|
|
|
|
{ tags: ["@checkout", "@allEnv"] },
|
|
|
|
() => {
|
2021-11-03 11:15:39 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
createWarehouse({ name, address: usAddress });
|
|
|
|
cy.get(WAREHOUSES_DETAILS.clickAndCollectLocalStockRadioButton).should(
|
2022-06-27 16:49:35 +00:00
|
|
|
"not.exist",
|
2021-11-03 11:15:39 +00:00
|
|
|
);
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-11-03 11:15:39 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should create order with warehouse address",
|
|
|
|
{ tags: ["@checkout", "@allEnv"] },
|
|
|
|
() => {
|
2021-11-03 11:15:39 +00:00
|
|
|
let checkout;
|
|
|
|
checkoutData.variantsList = variantsInOtherWarehouse;
|
|
|
|
createCheckout(checkoutData)
|
|
|
|
.then(({ checkout: checkoutResp }) => {
|
|
|
|
checkout = checkoutResp;
|
|
|
|
const clickAndCollectOption = checkout.availableCollectionPoints[0];
|
|
|
|
deliveryMethodUpdate(clickAndCollectOption.id, checkout.token);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
addPayment(checkout.id);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
completeCheckout(checkout.id);
|
|
|
|
})
|
|
|
|
.then(({ order }) => {
|
|
|
|
getOrder(order.id);
|
|
|
|
})
|
|
|
|
.then(order => {
|
|
|
|
cy.expectCorrectBasicAddress(order.shippingAddress, secondUsAddress);
|
|
|
|
cy.expectCorrectBasicAddress(order.billingAddress, usAddress);
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-11-03 11:15:39 +00:00
|
|
|
});
|