Add tests for preorders- threshold and stocks (#1567)

* tests for preorder, stoks an threshold

* fix tests for ordering products in channel threshold
This commit is contained in:
Karolina Rakoczy 2021-12-05 16:03:04 +01:00 committed by GitHub
parent 78f7b5d4fb
commit b7da933bf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 159 additions and 13 deletions

View file

@ -11,6 +11,7 @@ export const VARIANTS_SELECTORS = {
saveButton: "[data-test='button-bar-confirm']",
skuInputInAddVariant: "[name='sku']",
preorderCheckbox: "[name='isPreorder']",
channelThresholdInput: "[name='channel-threshold']",
setUpEndDateButton: "[name='hasPreorderEndDate']",
preorderEndDateInput: "[name='preorderEndDateTime:date']",
preorderEndTimeInput: "[name='preorderEndDateTime:time']",

View file

@ -79,10 +79,10 @@ export const warehouseDetailsUrl = warehouseId =>
export const saleDetailsUrl = saleId => `${urlList.sales}${saleId}`;
export const voucherDetailsUrl = voucherId => `${urlList.vouchers}${voucherId}`;
export const variantDetailsUrl = (productId, variantId) =>
`${urlList.products}${productId}/${urlList.variant}${variantId}`;
`${urlList.products}${productId}/${urlList.variants}${variantId}`;
export const voucherDetailsUrl = voucherId => `${urlList.vouchers}${voucherId}`;
export const stripeConfirmationUrl = id =>
`https://api.stripe.com/v1/payment_intents/${id}/confirm`;

View file

@ -0,0 +1,117 @@
/// <reference types="cypress"/>
/// <reference types="../../support"/>
import { VARIANTS_SELECTORS } from "../../elements/catalog/products/variants-selectors";
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import { variantDetailsUrl } from "../../fixtures/urlList";
import { createCheckout } from "../../support/api/requests/Checkout";
import { fulfillOrder } from "../../support/api/requests/Order";
import { getVariant } from "../../support/api/requests/Product";
import { createWaitingForCaptureOrder } from "../../support/api/utils/ordersUtils";
import { createProductWithShipping } from "../../support/api/utils/products/productsUtils";
import filterTests from "../../support/filterTests";
import { saveVariant } from "../../support/pages/catalog/products/VariantsPage";
filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
describe("Creating variants", () => {
const startsWith = "CreatePreOrder";
const attributeValues = ["value1", "value2"];
const preorder = {
globalThreshold: 15
};
let defaultChannel;
let product;
let variantsList;
let warehouse;
let checkoutData;
before(() => {
cy.clearSessionData().loginUserViaRequest();
createProductWithShipping({
name: startsWith,
attributeValues,
preorder
}).then(resp => {
checkoutData = {
address: resp.address,
channelSlug: resp.defaultChannel.slug,
email: "example@example.com",
shippingMethodId: resp.shippingMethod.id,
variantsList: resp.variantsList
};
warehouse = resp.warehouse;
defaultChannel = resp.defaultChannel;
product = resp.product;
variantsList = resp.variantsList;
});
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should not be able to order more products then channel threshold", () => {
cy.visit(variantDetailsUrl(product.id, variantsList[0].id))
.get(VARIANTS_SELECTORS.channelThresholdInput)
.type(5)
.addAliasToGraphRequest("ProductVariantChannelListingUpdate");
saveVariant("VariantUpdate");
cy.wait("@ProductVariantChannelListingUpdate");
checkoutData.productQuantity = 7;
createCheckout(checkoutData).then(({ errors }) => {
expect(errors[0].field).to.eq("quantity");
});
});
it("should not be able to order more products then threshold even if channel is not exceeded", () => {
cy.visit(variantDetailsUrl(product.id, variantsList[0].id))
.get(VARIANTS_SELECTORS.channelThresholdInput)
.type(40);
saveVariant("VariantUpdate");
checkoutData.productQuantity = 20;
createCheckout(checkoutData).then(({ errors }) => {
expect(errors[0].field).to.eq("quantity");
});
});
it("should allocate variants bought in preorder to correct warehouses", () => {
let order;
createWaitingForCaptureOrder(checkoutData)
.then(({ order: orderResp }) => {
order = orderResp;
cy.visit(variantDetailsUrl(product.id, variantsList[0].id))
.get(VARIANTS_SELECTORS.preorderCheckbox)
.click()
.addAliasToGraphRequest("ProductVariantPreorderDeactivate")
.get(BUTTON_SELECTORS.submit)
.click()
.waitForRequestAndCheckIfNoErrors(
"@ProductVariantPreorderDeactivate"
);
getVariant(variantsList[0].id, defaultChannel.slug);
})
.then(variantResp => {
expect(
variantResp.stocks[0].quantityAllocated,
"product is allocated with correct quantity"
).to.eq(1);
expect(
variantResp.stocks[0].warehouse.id,
"product is allocated to correct warehouse"
).to.eq(warehouse.id);
})
.then(() => {
fulfillOrder({
orderId: order.id,
warehouse: warehouse.id,
quantity: 1,
linesId: order.lines
});
})
.then(({ errors }) => {
expect(errors, "no errors when fulfilling order").to.be.empty;
});
});
});
});

View file

@ -141,6 +141,9 @@ export function completeCheckout(checkoutId, paymentData) {
checkoutComplete(checkoutId:"${checkoutId}" ${paymentDataLine}){
order{
id
lines{
id
}
paymentStatus
total{
gross{

View file

@ -150,9 +150,14 @@ export function createVariant({
costPrice = 1,
trackInventory = true,
weight = 1,
attributeValues = ["value"],
attributeName = "value",
attributeValues = ["value"]
preorder
}) {
const preorderLines = getValueWithDefault(
preorder,
`preorder:${stringify(preorder)}`
);
const skuLines = getValueWithDefault(sku, `sku: "${sku}"`);
const attributeLines = getValueWithDefault(
@ -183,6 +188,7 @@ export function createVariant({
const mutation = `mutation{
productVariantBulkCreate(product: "${productId}", variants: {
${preorderLines}
${attributeLines}
weight: ${weight}
${skuLines}
@ -237,7 +243,7 @@ export function getVariants(variantsList) {
return cy.sendRequestWithQuery(query).its("body.data.productVariants");
}
export function getVariant(id, channel, auth = "auth") {
export function getVariant(id, channelSlug, auth = "auth") {
const preorder = returnValueDependsOnShopVersion(
"3.1",
`preorder{
@ -248,9 +254,15 @@ export function getVariant(id, channel, auth = "auth") {
);
const query = `query{
productVariant(id:"${id}" channel:"${channel}"){
productVariant(id:"${id}" channel:"${channelSlug}"){
id
name
stocks{
warehouse{
id
}
quantityAllocated
}
${preorder}
sku
pricing{

View file

@ -30,6 +30,7 @@ export function createProductInChannel({
description = null,
trackInventory = true,
weight = 1,
preorder,
sku = name
}) {
let product;
@ -57,7 +58,8 @@ export function createProductInChannel({
channelId,
price,
trackInventory,
weight
weight,
preorder
});
})
.then(variantsResp => {
@ -116,6 +118,7 @@ export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
name,
description = name,
warehouseId,
preorder,
attributeValues = ["value"],
sku = name,
productPrice = 10
@ -146,8 +149,9 @@ export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
collectionId: collection.id,
description,
warehouseId,
sku,
price: productPrice
price: productPrice,
preorder,
sku
});
})
.then(({ product, variantsList }) => ({ product, variantsList }));
@ -158,7 +162,8 @@ export function createProductWithShipping({
attributeValues = ["value"],
sku = name,
productPrice = 10,
shippingPrice = 10
shippingPrice = 10,
preorder
}) {
let address;
let warehouse;
@ -194,9 +199,10 @@ export function createProductWithShipping({
deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
name,
warehouseId: warehouse.id,
productPrice,
preorder,
attributeValues,
sku,
productPrice
sku
});
}
)

View file

@ -12,7 +12,7 @@ Cypress.Commands.add("waitForRequestAndCheckIfNoErrors", alias => {
cy.wait(alias).then(resp => {
expect(
resp.response.body.errors,
`There are errors in ${alias} operation in graphql response`
`No errors in ${alias} operation in graphql response`
).to.be.undefined;
return resp;
});

View file

@ -604,6 +604,7 @@ const ProductStocks: React.FC<ProductStocksProps> = ({
</TableCell>
<TableCell className={classes.colQuantity}>
<TextField
name="channel-threshold"
disabled={disabled}
fullWidth
inputProps={{

View file

@ -232818,6 +232818,7 @@ exports[`Storyshots Views / Products / Product variant details attribute errors
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
min="0"
name="channel-threshold"
placeholder="Unlimited"
type="number"
value=""
@ -232866,6 +232867,7 @@ exports[`Storyshots Views / Products / Product variant details attribute errors
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
min="0"
name="channel-threshold"
placeholder="Unlimited"
type="number"
value=""
@ -234691,6 +234693,7 @@ exports[`Storyshots Views / Products / Product variant details no warehouses 1`]
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
min="0"
name="channel-threshold"
placeholder="Unlimited"
type="number"
value=""
@ -234739,6 +234742,7 @@ exports[`Storyshots Views / Products / Product variant details no warehouses 1`]
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
min="0"
name="channel-threshold"
placeholder="Unlimited"
type="number"
value=""
@ -236564,6 +236568,7 @@ exports[`Storyshots Views / Products / Product variant details when loaded data
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
min="0"
name="channel-threshold"
placeholder="Unlimited"
type="number"
value=""
@ -236612,6 +236617,7 @@ exports[`Storyshots Views / Products / Product variant details when loaded data
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
min="0"
name="channel-threshold"
placeholder="Unlimited"
type="number"
value=""