Add tests for creating preorders (#1563)
* add test for creating preorder variant * all tests for creating & editing variants in preorder
This commit is contained in:
parent
9ffa27a03f
commit
925e723c35
8 changed files with 270 additions and 24 deletions
|
@ -10,5 +10,10 @@ export const VARIANTS_SELECTORS = {
|
||||||
warehouseOption: "[role='menuitem']",
|
warehouseOption: "[role='menuitem']",
|
||||||
saveButton: "[data-test='button-bar-confirm']",
|
saveButton: "[data-test='button-bar-confirm']",
|
||||||
skuInputInAddVariant: "[name='sku']",
|
skuInputInAddVariant: "[name='sku']",
|
||||||
|
preorderCheckbox: "[name='isPreorder']",
|
||||||
|
setUpEndDateButton: "[name='hasPreorderEndDate']",
|
||||||
|
preorderEndDateInput: "[name='preorderEndDateTime:date']",
|
||||||
|
preorderEndTimeInput: "[name='preorderEndDateTime:time']",
|
||||||
|
globalThresholdInput: "[name='globalThreshold']",
|
||||||
stockInput: "[data-test-id='stock-input']"
|
stockInput: "[data-test-id='stock-input']"
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,6 +28,7 @@ export const urlList = {
|
||||||
translations: "translations/",
|
translations: "translations/",
|
||||||
variants: "variant/",
|
variants: "variant/",
|
||||||
vouchers: "discounts/vouchers/",
|
vouchers: "discounts/vouchers/",
|
||||||
|
variant: "variant/",
|
||||||
warehouses: "warehouses/",
|
warehouses: "warehouses/",
|
||||||
weightRete: "weight/"
|
weightRete: "weight/"
|
||||||
};
|
};
|
||||||
|
@ -80,5 +81,8 @@ export const saleDetailsUrl = saleId => `${urlList.sales}${saleId}`;
|
||||||
|
|
||||||
export const voucherDetailsUrl = voucherId => `${urlList.vouchers}${voucherId}`;
|
export const voucherDetailsUrl = voucherId => `${urlList.vouchers}${voucherId}`;
|
||||||
|
|
||||||
|
export const variantDetailsUrl = (productId, variantId) =>
|
||||||
|
`${urlList.products}${productId}/${urlList.variant}${variantId}`;
|
||||||
|
|
||||||
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`;
|
||||||
|
|
133
cypress/integration/preorders/createAndEditVariantsInPreorder.js
Normal file
133
cypress/integration/preorders/createAndEditVariantsInPreorder.js
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
/// <reference types="cypress"/>
|
||||||
|
/// <reference types="../../support"/>
|
||||||
|
|
||||||
|
import { PRODUCT_DETAILS } from "../../elements/catalog/products/product-details";
|
||||||
|
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
||||||
|
import { productDetailsUrl, variantDetailsUrl } from "../../fixtures/urlList";
|
||||||
|
import {
|
||||||
|
activatePreorderOnVariant,
|
||||||
|
deactivatePreorderOnVariant,
|
||||||
|
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 { formatDate, formatTime } from "../../support/formatData/formatDate";
|
||||||
|
import {
|
||||||
|
enablePreorderWithThreshold,
|
||||||
|
fillUpVariantAttributeAndSku,
|
||||||
|
saveVariant,
|
||||||
|
selectChannelForVariantAndFillUpPrices,
|
||||||
|
setUpPreorderEndDate
|
||||||
|
} from "../../support/pages/catalog/products/VariantsPage";
|
||||||
|
|
||||||
|
filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
||||||
|
describe("Creating variants", () => {
|
||||||
|
const startsWith = "CreatePreOrder";
|
||||||
|
const attributeValues = ["value1", "value2", "value3"];
|
||||||
|
const threshold = 100;
|
||||||
|
const futureDate = new Date().setDate(new Date().getDate() + 14);
|
||||||
|
const endDate = formatDate(futureDate);
|
||||||
|
const endTime = formatTime(futureDate);
|
||||||
|
|
||||||
|
let defaultChannel;
|
||||||
|
let product;
|
||||||
|
let variantsList;
|
||||||
|
let checkoutData;
|
||||||
|
|
||||||
|
before(() => {
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
createProductWithShipping({ name: startsWith, attributeValues }).then(
|
||||||
|
resp => {
|
||||||
|
checkoutData = {
|
||||||
|
address: resp.address,
|
||||||
|
channelSlug: resp.defaultChannel.slug,
|
||||||
|
email: "example@example.com",
|
||||||
|
shippingMethodId: resp.shippingMethod.id
|
||||||
|
};
|
||||||
|
defaultChannel = resp.defaultChannel;
|
||||||
|
product = resp.product;
|
||||||
|
variantsList = resp.variantsList;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create variant in preorder", () => {
|
||||||
|
let variant;
|
||||||
|
|
||||||
|
cy.visit(productDetailsUrl(product.id))
|
||||||
|
.get(PRODUCT_DETAILS.addVariantsButton)
|
||||||
|
.click();
|
||||||
|
fillUpVariantAttributeAndSku({
|
||||||
|
attributeName: attributeValues[1],
|
||||||
|
sku: attributeValues[1]
|
||||||
|
});
|
||||||
|
enablePreorderWithThreshold(threshold);
|
||||||
|
setUpPreorderEndDate(endDate, endTime);
|
||||||
|
saveVariant()
|
||||||
|
.then(({ response }) => {
|
||||||
|
variant = response.body.data.productVariantCreate.productVariant;
|
||||||
|
cy.get(BUTTON_SELECTORS.back).click();
|
||||||
|
selectChannelForVariantAndFillUpPrices({
|
||||||
|
channelName: defaultChannel.name,
|
||||||
|
attributeName: attributeValues[1],
|
||||||
|
price: 10
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
checkoutData.variantsList = [variant];
|
||||||
|
createWaitingForCaptureOrder(checkoutData);
|
||||||
|
})
|
||||||
|
.then(({ order }) => {
|
||||||
|
expect(order.id).to.be.ok;
|
||||||
|
getVariant(variant.id, defaultChannel.slug);
|
||||||
|
})
|
||||||
|
.then(({ preorder }) => {
|
||||||
|
const respEndDate = new Date(preorder.endDate);
|
||||||
|
|
||||||
|
expect(preorder.globalThreshold).to.eq(threshold);
|
||||||
|
expect(preorder.globalSoldUnits).to.eq(1);
|
||||||
|
expect(endDate).to.eq(formatDate(respEndDate));
|
||||||
|
expect(endTime).to.eq(formatTime(respEndDate));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should enable preorder on active variant", () => {
|
||||||
|
const variant = variantsList[0];
|
||||||
|
checkoutData.variantsList = [variant];
|
||||||
|
|
||||||
|
deactivatePreorderOnVariant(variant.id);
|
||||||
|
cy.visit(variantDetailsUrl(product.id, variant.id));
|
||||||
|
enablePreorderWithThreshold(threshold);
|
||||||
|
saveVariant("VariantUpdate");
|
||||||
|
createWaitingForCaptureOrder(checkoutData)
|
||||||
|
.then(({ order }) => {
|
||||||
|
expect(order.id).to.be.ok;
|
||||||
|
getVariant(variant.id, defaultChannel.slug);
|
||||||
|
})
|
||||||
|
.then(({ preorder }) => {
|
||||||
|
expect(preorder.globalThreshold).to.eq(threshold);
|
||||||
|
expect(preorder.globalSoldUnits).to.eq(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set end date on preorder variant", () => {
|
||||||
|
const variant = variantsList[0];
|
||||||
|
checkoutData.variantsList = [variant];
|
||||||
|
|
||||||
|
activatePreorderOnVariant(variant.id);
|
||||||
|
cy.visit(variantDetailsUrl(product.id, variant.id));
|
||||||
|
setUpPreorderEndDate(endDate, endTime);
|
||||||
|
saveVariant("VariantUpdate");
|
||||||
|
getVariant(variant.id, defaultChannel.slug).then(({ preorder }) => {
|
||||||
|
const respEndDate = new Date(preorder.endDate);
|
||||||
|
expect(endDate).to.eq(formatDate(respEndDate));
|
||||||
|
expect(endTime).to.eq(formatTime(respEndDate));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,9 +1,6 @@
|
||||||
import { stringify } from "../.././formatData/formatJson";
|
import { stringify } from "../.././formatData/formatJson";
|
||||||
import {
|
import { returnValueDependsOnShopVersion } from "../../formatData/dataDependingOnVersion";
|
||||||
getValuesInArray,
|
import { getValueWithDefault, getVariantsListIds } from "./utils/Utils";
|
||||||
getValueWithDefault,
|
|
||||||
getVariantsListIds
|
|
||||||
} from "./utils/Utils";
|
|
||||||
|
|
||||||
export function getFirstProducts(first, search) {
|
export function getFirstProducts(first, search) {
|
||||||
const filter = search
|
const filter = search
|
||||||
|
@ -241,10 +238,20 @@ export function getVariants(variantsList) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getVariant(id, channel, auth = "auth") {
|
export function getVariant(id, channel, auth = "auth") {
|
||||||
|
const preorder = returnValueDependsOnShopVersion(
|
||||||
|
"3.1",
|
||||||
|
`preorder{
|
||||||
|
globalThreshold
|
||||||
|
globalSoldUnits
|
||||||
|
endDate
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
|
||||||
const query = `query{
|
const query = `query{
|
||||||
productVariant(id:"${id}" channel:"${channel}"){
|
productVariant(id:"${id}" channel:"${channel}"){
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
|
${preorder}
|
||||||
sku
|
sku
|
||||||
pricing{
|
pricing{
|
||||||
onSale
|
onSale
|
||||||
|
@ -268,3 +275,41 @@ export function getVariant(id, channel, auth = "auth") {
|
||||||
}`;
|
}`;
|
||||||
return cy.sendRequestWithQuery(query, auth).its("body.data.productVariant");
|
return cy.sendRequestWithQuery(query, auth).its("body.data.productVariant");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function deactivatePreorderOnVariant(variantId) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
productVariantPreorderDeactivate(id:"${variantId}"){
|
||||||
|
errors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy
|
||||||
|
.sendRequestWithQuery(mutation)
|
||||||
|
.its("body.data.productVariantPreorderDeactivate");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function activatePreorderOnVariant(variantId, threshold, endDate) {
|
||||||
|
const thresholdLine = getValueWithDefault(
|
||||||
|
threshold,
|
||||||
|
`globalThreshold:${threshold}`
|
||||||
|
);
|
||||||
|
const endDateLine = getValueWithDefault(threshold, `endDate:${endDate}`);
|
||||||
|
const mutation = `mutation{
|
||||||
|
productVariantUpdate(id:"${variantId}", input:{
|
||||||
|
preorder:{
|
||||||
|
${thresholdLine}
|
||||||
|
${endDateLine}
|
||||||
|
}
|
||||||
|
}){
|
||||||
|
errors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy
|
||||||
|
.sendRequestWithQuery(mutation)
|
||||||
|
.its("body.data.productVariantUpdate");
|
||||||
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import {
|
||||||
import { deleteAttributesStartsWith } from "../attributes/attributeUtils";
|
import { deleteAttributesStartsWith } from "../attributes/attributeUtils";
|
||||||
import { deleteCollectionsStartsWith } from "../catalog/collectionsUtils";
|
import { deleteCollectionsStartsWith } from "../catalog/collectionsUtils";
|
||||||
import { getDefaultChannel } from "../channelsUtils";
|
import { getDefaultChannel } from "../channelsUtils";
|
||||||
import { createShipping } from "../shippingUtils";
|
import { createShipping, deleteShippingStartsWith } from "../shippingUtils";
|
||||||
|
|
||||||
export function createProductInChannel({
|
export function createProductInChannel({
|
||||||
name,
|
name,
|
||||||
|
@ -116,6 +116,7 @@ export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
|
||||||
name,
|
name,
|
||||||
description = name,
|
description = name,
|
||||||
warehouseId,
|
warehouseId,
|
||||||
|
attributeValues = ["value"],
|
||||||
sku = name,
|
sku = name,
|
||||||
productPrice = 10
|
productPrice = 10
|
||||||
}) {
|
}) {
|
||||||
|
@ -132,7 +133,7 @@ export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
|
||||||
})
|
})
|
||||||
.then(collectionResp => {
|
.then(collectionResp => {
|
||||||
collection = collectionResp;
|
collection = collectionResp;
|
||||||
createTypeAttributeAndCategoryForProduct({ name });
|
createTypeAttributeAndCategoryForProduct({ name, attributeValues });
|
||||||
})
|
})
|
||||||
.then(({ attribute: attributeResp, category, productType }) => {
|
.then(({ attribute: attributeResp, category, productType }) => {
|
||||||
attribute = attributeResp;
|
attribute = attributeResp;
|
||||||
|
@ -154,6 +155,7 @@ export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
|
||||||
|
|
||||||
export function createProductWithShipping({
|
export function createProductWithShipping({
|
||||||
name,
|
name,
|
||||||
|
attributeValues = ["value"],
|
||||||
sku = name,
|
sku = name,
|
||||||
productPrice = 10,
|
productPrice = 10,
|
||||||
shippingPrice = 10
|
shippingPrice = 10
|
||||||
|
@ -164,6 +166,7 @@ export function createProductWithShipping({
|
||||||
let defaultChannel;
|
let defaultChannel;
|
||||||
let shippingZone;
|
let shippingZone;
|
||||||
|
|
||||||
|
deleteShippingStartsWith(name);
|
||||||
return cy
|
return cy
|
||||||
.fixture("addresses")
|
.fixture("addresses")
|
||||||
.then(addresses => {
|
.then(addresses => {
|
||||||
|
@ -191,6 +194,7 @@ export function createProductWithShipping({
|
||||||
deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
|
deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
|
||||||
name,
|
name,
|
||||||
warehouseId: warehouse.id,
|
warehouseId: warehouse.id,
|
||||||
|
attributeValues,
|
||||||
sku,
|
sku,
|
||||||
productPrice
|
productPrice
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,3 +10,11 @@ function getPeriodValue(date, option) {
|
||||||
const formatter = new Intl.DateTimeFormat("en-us", option);
|
const formatter = new Intl.DateTimeFormat("en-us", option);
|
||||||
return formatter.format(date);
|
return formatter.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatTime(date) {
|
||||||
|
const formatter = new Intl.DateTimeFormat([], {
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "numeric"
|
||||||
|
});
|
||||||
|
return formatter.format(date);
|
||||||
|
}
|
||||||
|
|
1
cypress/support/index.d.ts
vendored
1
cypress/support/index.d.ts
vendored
|
@ -48,5 +48,6 @@ declare namespace Cypress {
|
||||||
createNewOption(selectSelector: string, newOption: string): Chainable<any>;
|
createNewOption(selectSelector: string, newOption: string): Chainable<any>;
|
||||||
findElementOnTable(elementName: string): Chainable<any>;
|
findElementOnTable(elementName: string): Chainable<any>;
|
||||||
searchInTable(query: string): Chainable<any>;
|
searchInTable(query: string): Chainable<any>;
|
||||||
|
waitForRequestAndCheckIfNoErrors(alias: string): Chainable<any>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,28 +55,50 @@ export function createVariant({
|
||||||
channelName,
|
channelName,
|
||||||
quantity = 10
|
quantity = 10
|
||||||
}) {
|
}) {
|
||||||
cy.get(PRODUCT_DETAILS.addVariantsButton)
|
cy.get(PRODUCT_DETAILS.addVariantsButton).click();
|
||||||
|
fillUpGeneralVariantInputs({ attributeName, warehouseName, sku });
|
||||||
|
cy.get(VARIANTS_SELECTORS.saveButton)
|
||||||
.click()
|
.click()
|
||||||
.get(VARIANTS_SELECTORS.attributeSelector)
|
.get(BUTTON_SELECTORS.back)
|
||||||
|
.click();
|
||||||
|
selectChannelForVariantAndFillUpPrices({
|
||||||
|
channelName,
|
||||||
|
attributeName,
|
||||||
|
price,
|
||||||
|
costPrice
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fillUpGeneralVariantInputs({
|
||||||
|
attributeName,
|
||||||
|
warehouseName,
|
||||||
|
sku
|
||||||
|
}) {
|
||||||
|
fillUpVariantAttributeAndSku({ attributeName, sku });
|
||||||
|
cy.get(VARIANTS_SELECTORS.addWarehouseButton).click();
|
||||||
|
cy.contains(VARIANTS_SELECTORS.warehouseOption, warehouseName).click({
|
||||||
|
force: true
|
||||||
|
});
|
||||||
|
cy.get(VARIANTS_SELECTORS.stockInput).type(quantity);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fillUpVariantAttributeAndSku({ attributeName, sku }) {
|
||||||
|
cy.get(VARIANTS_SELECTORS.attributeSelector)
|
||||||
.click()
|
.click()
|
||||||
.get(VARIANTS_SELECTORS.attributeOption)
|
.get(VARIANTS_SELECTORS.attributeOption)
|
||||||
.contains(attributeName)
|
.contains(attributeName)
|
||||||
.click();
|
|
||||||
if (sku) {
|
|
||||||
cy.get(VARIANTS_SELECTORS.skuInputInAddVariant).type(sku);
|
|
||||||
}
|
|
||||||
cy.get(VARIANTS_SELECTORS.addWarehouseButton).click();
|
|
||||||
cy.contains(VARIANTS_SELECTORS.warehouseOption, warehouseName)
|
|
||||||
.click({
|
|
||||||
force: true
|
|
||||||
})
|
|
||||||
.get(VARIANTS_SELECTORS.stockInput)
|
|
||||||
.type(quantity)
|
|
||||||
.get(VARIANTS_SELECTORS.saveButton)
|
|
||||||
.click()
|
.click()
|
||||||
.get(BUTTON_SELECTORS.back)
|
.get(VARIANTS_SELECTORS.skuInputInAddVariant)
|
||||||
.click()
|
.type(sku);
|
||||||
.addAliasToGraphRequest("ProductChannelListingUpdate");
|
}
|
||||||
|
|
||||||
|
export function selectChannelForVariantAndFillUpPrices({
|
||||||
|
channelName,
|
||||||
|
attributeName,
|
||||||
|
price,
|
||||||
|
costPrice = price
|
||||||
|
}) {
|
||||||
|
cy.addAliasToGraphRequest("ProductChannelListingUpdate");
|
||||||
selectChannelVariantInDetailsPage(channelName, attributeName);
|
selectChannelVariantInDetailsPage(channelName, attributeName);
|
||||||
cy.get(BUTTON_SELECTORS.confirm)
|
cy.get(BUTTON_SELECTORS.confirm)
|
||||||
.click()
|
.click()
|
||||||
|
@ -97,3 +119,27 @@ export function createVariant({
|
||||||
.get(AVAILABLE_CHANNELS_FORM.menageChannelsButton)
|
.get(AVAILABLE_CHANNELS_FORM.menageChannelsButton)
|
||||||
.should("be.visible");
|
.should("be.visible");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function enablePreorderWithThreshold(threshold) {
|
||||||
|
cy.get(VARIANTS_SELECTORS.preorderCheckbox)
|
||||||
|
.click()
|
||||||
|
.get(VARIANTS_SELECTORS.globalThresholdInput)
|
||||||
|
.type(threshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setUpPreorderEndDate(endDate, endTime) {
|
||||||
|
cy.get(VARIANTS_SELECTORS.setUpEndDateButton)
|
||||||
|
.click()
|
||||||
|
.get(VARIANTS_SELECTORS.preorderEndDateInput)
|
||||||
|
.type(endDate)
|
||||||
|
.get(VARIANTS_SELECTORS.preorderEndTimeInput)
|
||||||
|
.type(endTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveVariant(waitForAlias = "VariantCreate") {
|
||||||
|
return cy
|
||||||
|
.addAliasToGraphRequest(waitForAlias)
|
||||||
|
.get(BUTTON_SELECTORS.confirm)
|
||||||
|
.click()
|
||||||
|
.waitForRequestAndCheckIfNoErrors(`@${waitForAlias}`);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue