2021-09-27 10:04:21 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../../support"/>
|
|
|
|
|
2021-07-23 09:46:44 +00:00
|
|
|
import faker from "faker";
|
|
|
|
|
2021-09-27 10:04:21 +00:00
|
|
|
import { createCheckout } from "../../support/api/requests/Checkout";
|
|
|
|
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
|
2021-07-23 09:46:44 +00:00
|
|
|
import {
|
|
|
|
createProductInChannel,
|
|
|
|
createTypeAttributeAndCategoryForProduct,
|
|
|
|
deleteProductsStartsWith
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../support/api/utils/products/productsUtils";
|
2021-07-23 09:46:44 +00:00
|
|
|
import {
|
|
|
|
createShipping,
|
|
|
|
deleteShippingStartsWith
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../support/api/utils/shippingUtils";
|
|
|
|
import filterTests from "../../support/filterTests";
|
2021-10-05 11:46:58 +00:00
|
|
|
import {
|
|
|
|
pickupOptions,
|
|
|
|
visitAndEnablePickup,
|
|
|
|
visitSetPublicStockAndEnablePickup
|
|
|
|
} from "../../support/pages/warehousePage";
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2021-09-27 10:04:21 +00:00
|
|
|
filterTests({ definedTags: ["all"] }, () => {
|
2021-07-23 09:46:44 +00:00
|
|
|
describe("Warehouses in checkout", () => {
|
|
|
|
const startsWith = `CyWarehouseCheckout`;
|
|
|
|
let defaultChannel;
|
|
|
|
let usAddress;
|
|
|
|
let plAddress;
|
2021-10-05 11:46:58 +00:00
|
|
|
let productData;
|
|
|
|
let checkoutData;
|
|
|
|
let variantsInOtherWarehouse;
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2021-10-05 11:46:58 +00:00
|
|
|
before(() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
deleteShippingStartsWith(startsWith);
|
|
|
|
deleteProductsStartsWith(startsWith);
|
|
|
|
cy.fixture("addresses")
|
|
|
|
.then(addresses => {
|
|
|
|
usAddress = addresses.usAddress;
|
|
|
|
plAddress = addresses.plAddress;
|
|
|
|
getDefaultChannel();
|
|
|
|
})
|
|
|
|
.then(channelResp => {
|
|
|
|
defaultChannel = channelResp;
|
2021-10-05 11:46:58 +00:00
|
|
|
createTypeAttributeAndCategoryForProduct({ name: startsWith });
|
2021-07-23 09:46:44 +00:00
|
|
|
})
|
|
|
|
.then(({ attribute, productType, category }) => {
|
2021-10-05 11:46:58 +00:00
|
|
|
productData = {
|
2021-07-23 09:46:44 +00:00
|
|
|
attributeId: attribute.id,
|
|
|
|
categoryId: category.id,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
productTypeId: productType.id,
|
|
|
|
quantityInWarehouse: 100
|
2021-10-05 11:46:58 +00:00
|
|
|
};
|
|
|
|
checkoutData = {
|
|
|
|
returnAvailableCollectionPoints: true,
|
2021-07-23 09:46:44 +00:00
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
email: "example@example.com",
|
2021-10-05 11:46:58 +00:00
|
|
|
address: plAddress
|
|
|
|
};
|
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name: startsWith,
|
2021-07-23 09:46:44 +00:00
|
|
|
address: plAddress
|
|
|
|
});
|
|
|
|
})
|
2021-10-05 11:46:58 +00:00
|
|
|
.then(({ warehouse: warehouseResp }) => {
|
|
|
|
productData.name = startsWith;
|
|
|
|
productData.warehouseId = warehouseResp.id;
|
|
|
|
createProductInChannel(productData);
|
|
|
|
})
|
|
|
|
.then(({ variantsList }) => {
|
|
|
|
variantsInOtherWarehouse = variantsList;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create warehouse with all warehouses pickup and private stock", () => {
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let warehouse;
|
|
|
|
|
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name,
|
|
|
|
address: plAddress
|
|
|
|
})
|
|
|
|
.then(({ warehouse: warehouseResp }) => {
|
|
|
|
warehouse = warehouseResp;
|
|
|
|
visitAndEnablePickup(warehouse.id);
|
|
|
|
productData.name = name;
|
|
|
|
productData.warehouseId = warehouse.id;
|
|
|
|
createProductInChannel(productData);
|
|
|
|
})
|
|
|
|
.then(({ variantsList }) => {
|
|
|
|
checkoutData.variantsList = variantsList.concat(
|
|
|
|
variantsInOtherWarehouse
|
|
|
|
);
|
|
|
|
createCheckout(checkoutData);
|
|
|
|
})
|
|
|
|
.then(({ checkout }) => {
|
|
|
|
const clickAndCollectOption = checkout.availableCollectionPoints[0];
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create warehouse with all warehouses pickup and public stock", () => {
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let warehouse;
|
|
|
|
|
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name,
|
|
|
|
address: plAddress
|
|
|
|
})
|
|
|
|
.then(({ warehouse: warehouseResp }) => {
|
|
|
|
warehouse = warehouseResp;
|
|
|
|
visitSetPublicStockAndEnablePickup(warehouse.id);
|
|
|
|
productData.name = name;
|
|
|
|
productData.warehouseId = warehouse.id;
|
|
|
|
createProductInChannel(productData);
|
|
|
|
})
|
|
|
|
.then(({ variantsList }) => {
|
|
|
|
checkoutData.variantsList = variantsList.concat(
|
|
|
|
variantsInOtherWarehouse
|
|
|
|
);
|
|
|
|
createCheckout(checkoutData);
|
|
|
|
})
|
|
|
|
.then(({ checkout }) => {
|
|
|
|
const clickAndCollectOption = checkout.availableCollectionPoints[0];
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create warehouse with local stock only pickup and public stock", () => {
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let warehouse;
|
|
|
|
let variantsInLocalStock;
|
|
|
|
|
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name,
|
|
|
|
address: plAddress
|
|
|
|
})
|
|
|
|
.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(
|
|
|
|
variantsInOtherWarehouse
|
|
|
|
);
|
|
|
|
createCheckout(checkoutData);
|
|
|
|
})
|
|
|
|
.then(({ checkout }) => {
|
|
|
|
expect(checkout.availableCollectionPoints).to.have.length(
|
|
|
|
0,
|
|
|
|
"there should be no available collection point"
|
|
|
|
);
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not be possible to buy product for country not listed in warehouse", () => {
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let warehouse;
|
|
|
|
|
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name,
|
|
|
|
address: usAddress
|
|
|
|
})
|
|
|
|
.then(({ warehouse: warehouseResp }) => {
|
|
|
|
warehouse = warehouseResp;
|
|
|
|
productData.name = name;
|
|
|
|
productData.warehouseId = warehouse.id;
|
|
|
|
createProductInChannel(productData);
|
|
|
|
})
|
|
|
|
.then(({ variantsList }) => {
|
|
|
|
checkoutData.variantsList = variantsList;
|
|
|
|
createCheckout(checkoutData);
|
|
|
|
})
|
2021-07-23 09:46:44 +00:00
|
|
|
.then(({ errors }) => {
|
|
|
|
expect(errors[0]).to.have.property("field", "quantity");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|