2022-02-11 15:26:01 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../../support"/>
|
|
|
|
|
|
|
|
import faker from "faker";
|
|
|
|
|
|
|
|
import { createCheckout } from "../../support/api/requests/Checkout";
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
updateStockReservation,
|
|
|
|
} from "../../support/api/requests/ShopSettings";
|
2022-02-11 15:26:01 +00:00
|
|
|
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
|
|
|
|
import {
|
|
|
|
createProductInChannel,
|
|
|
|
createTypeAttributeAndCategoryForProduct,
|
|
|
|
} from "../../support/api/utils/products/productsUtils";
|
2023-05-29 07:15:07 +00:00
|
|
|
import { createShipping } from "../../support/api/utils/shippingUtils";
|
2022-02-11 15:26:01 +00:00
|
|
|
import {
|
|
|
|
enterSiteSettingAndSetStockReservation,
|
2022-06-27 16:49:35 +00:00
|
|
|
userType,
|
2022-02-11 15:26:01 +00:00
|
|
|
} from "../../support/pages/siteSettings";
|
|
|
|
|
2022-10-10 05:57:19 +00:00
|
|
|
describe("As an admin I want to manage stock reservation", () => {
|
2022-06-27 09:30:51 +00:00
|
|
|
const startsWith = "manageStocks";
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const productQuantity = 10;
|
|
|
|
const customerType = {
|
|
|
|
authenticated: "auth",
|
2022-06-27 16:49:35 +00:00
|
|
|
anonymous: "token",
|
2022-06-27 09:30:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let defaultChannel;
|
|
|
|
let address;
|
|
|
|
let warehouse;
|
|
|
|
let attribute;
|
|
|
|
let category;
|
|
|
|
let productType;
|
|
|
|
let dataForCheckout;
|
|
|
|
|
|
|
|
before(() => {
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2023-05-29 07:15:07 +00:00
|
|
|
|
2022-10-10 05:57:19 +00:00
|
|
|
cy.fixture("addresses").then(addresses => {
|
|
|
|
address = addresses.usAddress;
|
|
|
|
|
|
|
|
getDefaultChannel().then(channel => {
|
2022-06-27 09:30:51 +00:00
|
|
|
defaultChannel = channel;
|
2022-10-10 05:57:19 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name,
|
2022-06-27 16:49:35 +00:00
|
|
|
address,
|
2022-10-10 05:57:19 +00:00
|
|
|
}).then(({ warehouse: warehouseResp }) => {
|
|
|
|
warehouse = warehouseResp;
|
|
|
|
|
|
|
|
createTypeAttributeAndCategoryForProduct({ name }).then(
|
|
|
|
({
|
|
|
|
attribute: attributeResp,
|
|
|
|
category: categoryResp,
|
|
|
|
productType: productTypeResp,
|
|
|
|
}) => {
|
|
|
|
attribute = attributeResp;
|
|
|
|
category = categoryResp;
|
|
|
|
productType = productTypeResp;
|
|
|
|
},
|
|
|
|
);
|
2023-01-16 13:55:38 +00:00
|
|
|
cy.checkIfDataAreNotNull({
|
|
|
|
defaultChannel,
|
|
|
|
address,
|
|
|
|
warehouse,
|
|
|
|
attribute,
|
|
|
|
category,
|
|
|
|
productType,
|
|
|
|
dataForCheckout,
|
|
|
|
});
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
2022-10-10 05:57:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(() => {
|
2023-05-29 07:15:07 +00:00
|
|
|
updateStockReservation({}).its("errors").should("be.empty");
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
2022-02-11 15:26:01 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
const productName = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2022-06-27 09:30:51 +00:00
|
|
|
|
|
|
|
createProductInChannel({
|
|
|
|
attributeId: attribute.id,
|
|
|
|
categoryId: category.id,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name: productName,
|
|
|
|
productTypeId: productType.id,
|
|
|
|
warehouseId: warehouse.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
quantityInWarehouse: productQuantity,
|
2022-06-27 09:30:51 +00:00
|
|
|
}).then(({ variantsList }) => {
|
|
|
|
dataForCheckout = {
|
|
|
|
email: "example@example.pl",
|
|
|
|
address,
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
variantsList,
|
2022-06-27 16:49:35 +00:00
|
|
|
productQuantity,
|
2022-06-27 09:30:51 +00:00
|
|
|
};
|
2022-02-11 15:26:01 +00:00
|
|
|
});
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
2022-02-11 15:26:01 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should be able to set stock reservation for authenticated customer in checkout. TC: SALEOR_0415",
|
2022-10-10 05:57:19 +00:00
|
|
|
{ tags: ["@orders", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-02-11 15:26:01 +00:00
|
|
|
dataForCheckout.auth = customerType.authenticated;
|
|
|
|
|
2022-10-10 05:57:19 +00:00
|
|
|
updateStockReservation({});
|
|
|
|
enterSiteSettingAndSetStockReservation(userType.authenticated, 10);
|
2023-05-29 07:15:07 +00:00
|
|
|
createCheckout(dataForCheckout).its("checkout").should("be.ok");
|
2022-10-10 05:57:19 +00:00
|
|
|
createCheckout(dataForCheckout)
|
|
|
|
.its("errors.0")
|
|
|
|
.should("include", { field: "quantity" })
|
|
|
|
.and("include", {
|
|
|
|
message: "Could not add items value. Only 0 remaining in stock.",
|
2022-02-11 15:26:01 +00:00
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2022-02-11 15:26:01 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should be able to set stock reservation for anonymous customer in checkout. TC: SALEOR_0416",
|
2022-10-10 05:57:19 +00:00
|
|
|
{ tags: ["@orders", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-02-11 15:26:01 +00:00
|
|
|
dataForCheckout.auth = customerType.anonymous;
|
|
|
|
|
2022-10-10 05:57:19 +00:00
|
|
|
updateStockReservation({});
|
|
|
|
enterSiteSettingAndSetStockReservation(userType.anonymous, 10);
|
2023-05-29 07:15:07 +00:00
|
|
|
createCheckout(dataForCheckout).its("checkout").should("be.ok");
|
2022-10-10 05:57:19 +00:00
|
|
|
createCheckout(dataForCheckout)
|
|
|
|
.its("errors.0")
|
|
|
|
.should("include", { field: "quantity" })
|
|
|
|
.and("include", {
|
|
|
|
message: "Could not add items value. Only 0 remaining in stock.",
|
2022-02-11 15:26:01 +00:00
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2022-02-11 15:26:01 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should be able to leave empty stock reservation for authenticated customer in checkout. TC: SALEOR_0417",
|
2022-10-10 05:57:19 +00:00
|
|
|
{ tags: ["@orders", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-02-11 15:26:01 +00:00
|
|
|
dataForCheckout.auth = customerType.authenticated;
|
|
|
|
|
2022-10-10 05:57:19 +00:00
|
|
|
updateStockReservation({ authenticatedUserStock: 10 });
|
|
|
|
enterSiteSettingAndSetStockReservation(userType.authenticated);
|
2023-05-29 07:15:07 +00:00
|
|
|
createCheckout(dataForCheckout).its("checkout").should("be.ok");
|
2022-10-10 05:57:19 +00:00
|
|
|
createCheckout(dataForCheckout)
|
|
|
|
.should("be.ok")
|
|
|
|
.its("errors")
|
|
|
|
.should("be.empty");
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2022-02-11 15:26:01 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should be able to leave empty stock reservation for anonymous customer in checkout. TC: SALEOR_0418",
|
2022-10-10 05:57:19 +00:00
|
|
|
{ tags: ["@orders", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-02-11 15:26:01 +00:00
|
|
|
dataForCheckout.auth = customerType.anonymous;
|
|
|
|
|
2022-10-10 05:57:19 +00:00
|
|
|
updateStockReservation({ anonymousUserStock: 10 });
|
|
|
|
enterSiteSettingAndSetStockReservation(userType.anonymous);
|
2023-05-29 07:15:07 +00:00
|
|
|
createCheckout(dataForCheckout).its("checkout").should("be.ok");
|
2022-10-10 05:57:19 +00:00
|
|
|
createCheckout(dataForCheckout)
|
|
|
|
.should("be.ok")
|
|
|
|
.its("errors")
|
|
|
|
.should("be.empty");
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2022-02-11 15:26:01 +00:00
|
|
|
});
|