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:
parent
78f7b5d4fb
commit
b7da933bf2
9 changed files with 159 additions and 13 deletions
|
@ -11,6 +11,7 @@ export const VARIANTS_SELECTORS = {
|
||||||
saveButton: "[data-test='button-bar-confirm']",
|
saveButton: "[data-test='button-bar-confirm']",
|
||||||
skuInputInAddVariant: "[name='sku']",
|
skuInputInAddVariant: "[name='sku']",
|
||||||
preorderCheckbox: "[name='isPreorder']",
|
preorderCheckbox: "[name='isPreorder']",
|
||||||
|
channelThresholdInput: "[name='channel-threshold']",
|
||||||
setUpEndDateButton: "[name='hasPreorderEndDate']",
|
setUpEndDateButton: "[name='hasPreorderEndDate']",
|
||||||
preorderEndDateInput: "[name='preorderEndDateTime:date']",
|
preorderEndDateInput: "[name='preorderEndDateTime:date']",
|
||||||
preorderEndTimeInput: "[name='preorderEndDateTime:time']",
|
preorderEndTimeInput: "[name='preorderEndDateTime:time']",
|
||||||
|
|
|
@ -79,10 +79,10 @@ export const warehouseDetailsUrl = warehouseId =>
|
||||||
|
|
||||||
export const saleDetailsUrl = saleId => `${urlList.sales}${saleId}`;
|
export const saleDetailsUrl = saleId => `${urlList.sales}${saleId}`;
|
||||||
|
|
||||||
export const voucherDetailsUrl = voucherId => `${urlList.vouchers}${voucherId}`;
|
|
||||||
|
|
||||||
export const variantDetailsUrl = (productId, variantId) =>
|
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 =>
|
export const stripeConfirmationUrl = id =>
|
||||||
`https://api.stripe.com/v1/payment_intents/${id}/confirm`;
|
`https://api.stripe.com/v1/payment_intents/${id}/confirm`;
|
||||||
|
|
117
cypress/integration/preorders/stocksAndThreshold.js
Normal file
117
cypress/integration/preorders/stocksAndThreshold.js
Normal 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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -141,6 +141,9 @@ export function completeCheckout(checkoutId, paymentData) {
|
||||||
checkoutComplete(checkoutId:"${checkoutId}" ${paymentDataLine}){
|
checkoutComplete(checkoutId:"${checkoutId}" ${paymentDataLine}){
|
||||||
order{
|
order{
|
||||||
id
|
id
|
||||||
|
lines{
|
||||||
|
id
|
||||||
|
}
|
||||||
paymentStatus
|
paymentStatus
|
||||||
total{
|
total{
|
||||||
gross{
|
gross{
|
||||||
|
|
|
@ -150,9 +150,14 @@ export function createVariant({
|
||||||
costPrice = 1,
|
costPrice = 1,
|
||||||
trackInventory = true,
|
trackInventory = true,
|
||||||
weight = 1,
|
weight = 1,
|
||||||
|
attributeValues = ["value"],
|
||||||
attributeName = "value",
|
attributeName = "value",
|
||||||
attributeValues = ["value"]
|
preorder
|
||||||
}) {
|
}) {
|
||||||
|
const preorderLines = getValueWithDefault(
|
||||||
|
preorder,
|
||||||
|
`preorder:${stringify(preorder)}`
|
||||||
|
);
|
||||||
const skuLines = getValueWithDefault(sku, `sku: "${sku}"`);
|
const skuLines = getValueWithDefault(sku, `sku: "${sku}"`);
|
||||||
|
|
||||||
const attributeLines = getValueWithDefault(
|
const attributeLines = getValueWithDefault(
|
||||||
|
@ -183,6 +188,7 @@ export function createVariant({
|
||||||
|
|
||||||
const mutation = `mutation{
|
const mutation = `mutation{
|
||||||
productVariantBulkCreate(product: "${productId}", variants: {
|
productVariantBulkCreate(product: "${productId}", variants: {
|
||||||
|
${preorderLines}
|
||||||
${attributeLines}
|
${attributeLines}
|
||||||
weight: ${weight}
|
weight: ${weight}
|
||||||
${skuLines}
|
${skuLines}
|
||||||
|
@ -237,7 +243,7 @@ export function getVariants(variantsList) {
|
||||||
return cy.sendRequestWithQuery(query).its("body.data.productVariants");
|
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(
|
const preorder = returnValueDependsOnShopVersion(
|
||||||
"3.1",
|
"3.1",
|
||||||
`preorder{
|
`preorder{
|
||||||
|
@ -248,9 +254,15 @@ export function getVariant(id, channel, auth = "auth") {
|
||||||
);
|
);
|
||||||
|
|
||||||
const query = `query{
|
const query = `query{
|
||||||
productVariant(id:"${id}" channel:"${channel}"){
|
productVariant(id:"${id}" channel:"${channelSlug}"){
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
|
stocks{
|
||||||
|
warehouse{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
quantityAllocated
|
||||||
|
}
|
||||||
${preorder}
|
${preorder}
|
||||||
sku
|
sku
|
||||||
pricing{
|
pricing{
|
||||||
|
|
|
@ -30,6 +30,7 @@ export function createProductInChannel({
|
||||||
description = null,
|
description = null,
|
||||||
trackInventory = true,
|
trackInventory = true,
|
||||||
weight = 1,
|
weight = 1,
|
||||||
|
preorder,
|
||||||
sku = name
|
sku = name
|
||||||
}) {
|
}) {
|
||||||
let product;
|
let product;
|
||||||
|
@ -57,7 +58,8 @@ export function createProductInChannel({
|
||||||
channelId,
|
channelId,
|
||||||
price,
|
price,
|
||||||
trackInventory,
|
trackInventory,
|
||||||
weight
|
weight,
|
||||||
|
preorder
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(variantsResp => {
|
.then(variantsResp => {
|
||||||
|
@ -116,6 +118,7 @@ export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
|
||||||
name,
|
name,
|
||||||
description = name,
|
description = name,
|
||||||
warehouseId,
|
warehouseId,
|
||||||
|
preorder,
|
||||||
attributeValues = ["value"],
|
attributeValues = ["value"],
|
||||||
sku = name,
|
sku = name,
|
||||||
productPrice = 10
|
productPrice = 10
|
||||||
|
@ -146,8 +149,9 @@ export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
description,
|
description,
|
||||||
warehouseId,
|
warehouseId,
|
||||||
sku,
|
price: productPrice,
|
||||||
price: productPrice
|
preorder,
|
||||||
|
sku
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(({ product, variantsList }) => ({ product, variantsList }));
|
.then(({ product, variantsList }) => ({ product, variantsList }));
|
||||||
|
@ -158,7 +162,8 @@ export function createProductWithShipping({
|
||||||
attributeValues = ["value"],
|
attributeValues = ["value"],
|
||||||
sku = name,
|
sku = name,
|
||||||
productPrice = 10,
|
productPrice = 10,
|
||||||
shippingPrice = 10
|
shippingPrice = 10,
|
||||||
|
preorder
|
||||||
}) {
|
}) {
|
||||||
let address;
|
let address;
|
||||||
let warehouse;
|
let warehouse;
|
||||||
|
@ -194,9 +199,10 @@ export function createProductWithShipping({
|
||||||
deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
|
deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
|
||||||
name,
|
name,
|
||||||
warehouseId: warehouse.id,
|
warehouseId: warehouse.id,
|
||||||
|
productPrice,
|
||||||
|
preorder,
|
||||||
attributeValues,
|
attributeValues,
|
||||||
sku,
|
sku
|
||||||
productPrice
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,7 +12,7 @@ Cypress.Commands.add("waitForRequestAndCheckIfNoErrors", alias => {
|
||||||
cy.wait(alias).then(resp => {
|
cy.wait(alias).then(resp => {
|
||||||
expect(
|
expect(
|
||||||
resp.response.body.errors,
|
resp.response.body.errors,
|
||||||
`There are errors in ${alias} operation in graphql response`
|
`No errors in ${alias} operation in graphql response`
|
||||||
).to.be.undefined;
|
).to.be.undefined;
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
|
|
|
@ -604,6 +604,7 @@ const ProductStocks: React.FC<ProductStocksProps> = ({
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className={classes.colQuantity}>
|
<TableCell className={classes.colQuantity}>
|
||||||
<TextField
|
<TextField
|
||||||
|
name="channel-threshold"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
fullWidth
|
fullWidth
|
||||||
inputProps={{
|
inputProps={{
|
||||||
|
|
|
@ -232818,6 +232818,7 @@ exports[`Storyshots Views / Products / Product variant details attribute errors
|
||||||
aria-invalid="false"
|
aria-invalid="false"
|
||||||
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
||||||
min="0"
|
min="0"
|
||||||
|
name="channel-threshold"
|
||||||
placeholder="Unlimited"
|
placeholder="Unlimited"
|
||||||
type="number"
|
type="number"
|
||||||
value=""
|
value=""
|
||||||
|
@ -232866,6 +232867,7 @@ exports[`Storyshots Views / Products / Product variant details attribute errors
|
||||||
aria-invalid="false"
|
aria-invalid="false"
|
||||||
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
||||||
min="0"
|
min="0"
|
||||||
|
name="channel-threshold"
|
||||||
placeholder="Unlimited"
|
placeholder="Unlimited"
|
||||||
type="number"
|
type="number"
|
||||||
value=""
|
value=""
|
||||||
|
@ -234691,6 +234693,7 @@ exports[`Storyshots Views / Products / Product variant details no warehouses 1`]
|
||||||
aria-invalid="false"
|
aria-invalid="false"
|
||||||
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
||||||
min="0"
|
min="0"
|
||||||
|
name="channel-threshold"
|
||||||
placeholder="Unlimited"
|
placeholder="Unlimited"
|
||||||
type="number"
|
type="number"
|
||||||
value=""
|
value=""
|
||||||
|
@ -234739,6 +234742,7 @@ exports[`Storyshots Views / Products / Product variant details no warehouses 1`]
|
||||||
aria-invalid="false"
|
aria-invalid="false"
|
||||||
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
||||||
min="0"
|
min="0"
|
||||||
|
name="channel-threshold"
|
||||||
placeholder="Unlimited"
|
placeholder="Unlimited"
|
||||||
type="number"
|
type="number"
|
||||||
value=""
|
value=""
|
||||||
|
@ -236564,6 +236568,7 @@ exports[`Storyshots Views / Products / Product variant details when loaded data
|
||||||
aria-invalid="false"
|
aria-invalid="false"
|
||||||
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
||||||
min="0"
|
min="0"
|
||||||
|
name="channel-threshold"
|
||||||
placeholder="Unlimited"
|
placeholder="Unlimited"
|
||||||
type="number"
|
type="number"
|
||||||
value=""
|
value=""
|
||||||
|
@ -236612,6 +236617,7 @@ exports[`Storyshots Views / Products / Product variant details when loaded data
|
||||||
aria-invalid="false"
|
aria-invalid="false"
|
||||||
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
class="MuiInputBase-input-id MuiOutlinedInput-input-id ProductStocks-input-id"
|
||||||
min="0"
|
min="0"
|
||||||
|
name="channel-threshold"
|
||||||
placeholder="Unlimited"
|
placeholder="Unlimited"
|
||||||
type="number"
|
type="number"
|
||||||
value=""
|
value=""
|
||||||
|
|
Loading…
Reference in a new issue