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";
|
|
|
|
|
|
|
|
import {
|
|
|
|
addProductsToCheckout,
|
2022-06-27 16:49:35 +00:00
|
|
|
createCheckout,
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../support/api/requests/Checkout";
|
|
|
|
import { getVariants } from "../../support/api/requests/Product";
|
2022-03-21 12:17:37 +00:00
|
|
|
import { createWaitingForCaptureOrder } from "../../support/api/utils/ordersUtils";
|
|
|
|
import { createNewProductWithSeveralVariants } from "../../support/api/utils/products/productsUtils";
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
describe("Manage products stocks in checkout", () => {
|
|
|
|
const startsWith = "CyStocksCheckout-";
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
let defaultChannel;
|
|
|
|
let address;
|
|
|
|
let shippingMethod;
|
|
|
|
let variantsWithLowStock;
|
|
|
|
let variantsWithoutTrackInventory;
|
|
|
|
let lastVariantInStock;
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
before(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
const variantsData = [
|
|
|
|
{
|
|
|
|
name: "variantsWithLowStock",
|
|
|
|
trackInventory: true,
|
2022-06-27 16:49:35 +00:00
|
|
|
quantityInWarehouse: 1,
|
2022-06-27 09:30:51 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "variantsWithoutTrackInventory",
|
|
|
|
trackInventory: false,
|
2022-06-27 16:49:35 +00:00
|
|
|
quantityInWarehouse: 0,
|
2022-06-27 09:30:51 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "lastVariantInStock",
|
|
|
|
trackInventory: true,
|
2022-06-27 16:49:35 +00:00
|
|
|
quantityInWarehouse: 1,
|
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
];
|
2022-03-21 12:17:37 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
createNewProductWithSeveralVariants(name, variantsData).then(resp => {
|
|
|
|
defaultChannel = resp.defaultChannel;
|
|
|
|
address = resp.address;
|
|
|
|
shippingMethod = resp.shippingMethod;
|
|
|
|
variantsWithLowStock = resp.createdVariants.find(
|
2022-06-27 16:49:35 +00:00
|
|
|
variant => variant.name === "variantsWithLowStock",
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
|
|
|
variantsWithoutTrackInventory = resp.createdVariants.find(
|
2022-06-27 16:49:35 +00:00
|
|
|
variant => variant.name === "variantsWithoutTrackInventory",
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
|
|
|
lastVariantInStock = resp.createdVariants.find(
|
2022-06-27 16:49:35 +00:00
|
|
|
variant => variant.name === "lastVariantInStock",
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2023-01-16 13:55:38 +00:00
|
|
|
cy.checkIfDataAreNotNull({
|
|
|
|
defaultChannel,
|
|
|
|
address,
|
|
|
|
shippingMethod,
|
|
|
|
variantsWithLowStock,
|
|
|
|
variantsWithoutTrackInventory,
|
|
|
|
lastVariantInStock,
|
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should not be possible to add product with quantity greater than stock to checkout. TC: SALEOR_0405",
|
2022-10-25 17:27:26 +00:00
|
|
|
{ tags: ["@checkout", "@allEnv", "@stable", "@oldRelease"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-03-21 12:17:37 +00:00
|
|
|
createCheckout({
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
address,
|
|
|
|
billingAddress: address,
|
|
|
|
email: "email@example.com",
|
|
|
|
variantsList: [variantsWithLowStock],
|
2022-06-27 16:49:35 +00:00
|
|
|
auth: "token",
|
2021-07-23 09:46:44 +00:00
|
|
|
})
|
|
|
|
.then(({ checkout: checkout }) => {
|
2022-03-21 12:17:37 +00:00
|
|
|
addProductsToCheckout(checkout.id, [variantsWithLowStock], 2);
|
2021-07-23 09:46:44 +00:00
|
|
|
})
|
|
|
|
.then(({ errors }) => {
|
|
|
|
expect(
|
|
|
|
errors[0],
|
2022-06-27 16:49:35 +00:00
|
|
|
"should return error on field quantity",
|
2021-07-23 09:46:44 +00:00
|
|
|
).to.have.property("field", "quantity");
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should buy product with no quantity if tracking is not set. TC: SALEOR_0406",
|
2022-10-25 17:27:26 +00:00
|
|
|
{ tags: ["@checkout", "@allEnv", "@stable", "@oldRelease"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-03-21 12:17:37 +00:00
|
|
|
createWaitingForCaptureOrder({
|
|
|
|
address,
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
email: "example@example.com",
|
|
|
|
shippingMethodName: shippingMethod.name,
|
2022-06-27 16:49:35 +00:00
|
|
|
variantsList: [variantsWithoutTrackInventory],
|
2021-07-23 09:46:44 +00:00
|
|
|
}).then(({ order }) => {
|
|
|
|
expect(order, "order should be created").to.be.ok;
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should create checkout with last product in stock. TC: SALEOR_0419",
|
2022-10-25 17:27:26 +00:00
|
|
|
{ tags: ["@checkout", "@allEnv", "@stable", "@oldRelease"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-03-21 12:17:37 +00:00
|
|
|
createWaitingForCaptureOrder({
|
|
|
|
address,
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
email: "example@example.com",
|
|
|
|
shippingMethodName: shippingMethod.name,
|
2022-06-27 16:49:35 +00:00
|
|
|
variantsList: [lastVariantInStock],
|
2021-07-23 09:46:44 +00:00
|
|
|
})
|
2022-03-21 12:17:37 +00:00
|
|
|
.then(({ order }) => {
|
|
|
|
expect(order, "order should be created").to.be.ok;
|
|
|
|
getVariants([lastVariantInStock]);
|
2021-07-23 09:46:44 +00:00
|
|
|
})
|
|
|
|
.then(variantsList => {
|
|
|
|
const variant = variantsList.edges[0];
|
|
|
|
expect(variant.node.stocks[0].quantityAllocated).to.eq(1);
|
2022-03-21 12:17:37 +00:00
|
|
|
expect(variant.node.stocks[0].quantity).to.eq(1);
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|