Fix tests for SKU (#2924)

* add tests update and tc ids

* move test to proper file and refactor

* update before for createProductWithoutSku

* update before for updatingProductsWithoutSku

* add function for create simple product
This commit is contained in:
Anna Szczęch 2023-01-05 08:06:46 +01:00 committed by GitHub
parent c60f6f870c
commit 7545bc152b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 262 additions and 132 deletions

View file

@ -10,15 +10,24 @@ import { urlList } from "../../../fixtures/urlList";
import { ONE_PERMISSION_USERS } from "../../../fixtures/users"; import { ONE_PERMISSION_USERS } from "../../../fixtures/users";
import { updateVariantWarehouse } from "../../../support/api/requests/Product"; import { updateVariantWarehouse } from "../../../support/api/requests/Product";
import { createTypeProduct } from "../../../support/api/requests/ProductType"; import { createTypeProduct } from "../../../support/api/requests/ProductType";
import { import { deleteChannelsStartsWith } from "../../../support/api/utils/channelsUtils";
deleteChannelsStartsWith,
getDefaultChannel,
} from "../../../support/api/utils/channelsUtils";
import { createWaitingForCaptureOrder } from "../../../support/api/utils/ordersUtils"; import { createWaitingForCaptureOrder } from "../../../support/api/utils/ordersUtils";
import * as productUtils from "../../../support/api/utils/products/productsUtils"; import * as productUtils from "../../../support/api/utils/products/productsUtils";
import * as shippingUtils from "../../../support/api/utils/shippingUtils"; import * as shippingUtils from "../../../support/api/utils/shippingUtils";
import { enterVariantEditPage } from "../../../support/pages/catalog/products/productDetailsPage"; import { getProductVariants } from "../../../support/api/utils/storeFront/storeFrontProductUtils";
import { selectChannelsForVariant } from "../../../support/pages/catalog/products/VariantsPage"; import { deleteWarehouseStartsWith } from "../../../support/api/utils/warehouseUtils";
import {
fillUpPriceList,
priceInputLists,
} from "../../../support/pages/catalog/products/priceListComponent";
import {
enterVariantEditPage,
fillUpProductTypeDialog,
} from "../../../support/pages/catalog/products/productDetailsPage";
import {
createVariant,
selectChannelsForVariant,
} from "../../../support/pages/catalog/products/VariantsPage";
import { selectChannelInDetailsPages } from "../../../support/pages/channelsPage"; import { selectChannelInDetailsPages } from "../../../support/pages/channelsPage";
describe("Creating variants", () => { describe("Creating variants", () => {
@ -39,28 +48,24 @@ describe("Creating variants", () => {
shippingUtils.deleteShippingStartsWith(startsWith); shippingUtils.deleteShippingStartsWith(startsWith);
productUtils.deleteProductsStartsWith(startsWith); productUtils.deleteProductsStartsWith(startsWith);
deleteChannelsStartsWith(startsWith); deleteChannelsStartsWith(startsWith);
deleteWarehouseStartsWith(startsWith);
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const simpleProductTypeName = `${startsWith}${faker.datatype.number()}`; const simpleProductTypeName = `${startsWith}${faker.datatype.number()}`;
getDefaultChannel()
.then(channel => { cy.fixture("addresses").then(fixtureAddresses => {
defaultChannel = channel; address = fixtureAddresses.plAddress;
cy.fixture("addresses");
})
.then(fixtureAddresses => {
address = fixtureAddresses.usAddress;
shippingUtils.createShipping({
channelId: defaultChannel.id,
name,
address,
}); });
})
.then( shippingUtils
({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => { .createShippingWithDefaultChannelAndAddress(name)
warehouse = warehouseResp; .then(resp => {
shippingMethod = shippingMethodResp; category = resp.category;
}, defaultChannel = resp.defaultChannel;
); warehouse = resp.warehouse;
shippingMethod = resp.shippingMethod;
});
productUtils productUtils
.createTypeAttributeAndCategoryForProduct({ name, attributeValues }) .createTypeAttributeAndCategoryForProduct({ name, attributeValues })
.then( .then(
@ -91,8 +96,8 @@ describe("Creating variants", () => {
); );
}); });
xit( it(
"should create variant without sku", "should create variant without sku TC: SALEOR_2807",
{ tags: ["@products", "@allEnv"] }, { tags: ["@products", "@allEnv"] },
() => { () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
@ -112,11 +117,16 @@ describe("Creating variants", () => {
.then(({ product: productResp }) => { .then(({ product: productResp }) => {
createdProduct = productResp; createdProduct = productResp;
cy.visit(`${urlList.products}${createdProduct.id}`); cy.visit(`${urlList.products}${createdProduct.id}`);
enterVariantEditPage();
cy.get(PRODUCT_DETAILS.addVariantButton)
.click()
.then(() => {
createVariant({ createVariant({
warehouseName: warehouse.name,
attributeName: variants[1].name, attributeName: variants[1].name,
price: variants[1].price, price: variants[1].price,
channelName: defaultChannel.name, channelName: defaultChannel.name,
warehouseId: warehouse.id,
});
}); });
}) })
.then(() => { .then(() => {
@ -141,28 +151,25 @@ describe("Creating variants", () => {
); );
it( it(
"should create simple product without sku SALEOR_2806", "should create simple product without sku SALEOR_2808",
{ tags: ["@products", "@allEnv"] }, { tags: ["@products", "@allEnv"] },
() => { () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const prices = { sellingPrice: 10, costPrice: 6 };
cy.visit(urlList.products) cy.visit(urlList.products)
.get(PRODUCTS_LIST.createProductBtn) .get(PRODUCTS_LIST.createProductBtn)
.click();
fillUpProductTypeDialog({ productType: simpleProductType.name });
cy.get(BUTTON_SELECTORS.submit)
.click() .click()
.fillAutocompleteSelect( .get(PRODUCT_DETAILS.productNameInput)
PRODUCTS_LIST.dialogProductTypeInput,
simpleProductType.name,
);
cy.get(BUTTON_SELECTORS.submit).click();
cy.get(PRODUCT_DETAILS.productNameInput)
.type(name) .type(name)
.fillAutocompleteSelect(PRODUCT_DETAILS.categoryInput); .fillAutocompleteSelect(PRODUCT_DETAILS.categoryInput);
selectChannelInDetailsPages(defaultChannel.name); selectChannelInDetailsPages(defaultChannel.name);
cy.get(PRODUCT_DETAILS.costPriceInput) fillUpPriceList(prices.sellingPrice);
.type(10) fillUpPriceList(prices.costPrice, priceInputLists.costPrice);
.get(PRODUCT_DETAILS.sellingPriceInput) cy.addAliasToGraphRequest("VariantCreate")
.type(10)
.addAliasToGraphRequest("VariantCreate")
.get(BUTTON_SELECTORS.confirm) .get(BUTTON_SELECTORS.confirm)
.click() .click()
.confirmationMessageShouldDisappear() .confirmationMessageShouldDisappear()
@ -170,18 +177,16 @@ describe("Creating variants", () => {
.then(({ response }) => { .then(({ response }) => {
const variantId = const variantId =
response.body.data.productVariantCreate.productVariant.id; response.body.data.productVariantCreate.productVariant.id;
updateVariantWarehouse({
updateVariantWarehouse({ variantId, warehouseId: warehouse.id }); variantId,
warehouseId: warehouse.id,
quantity: 10,
});
}); });
enterVariantEditPage(); enterVariantEditPage();
cy.addAliasToGraphRequest("ProductVariantDetails"); cy.addAliasToGraphRequest("ProductVariantDetails");
selectChannelsForVariant(); selectChannelsForVariant();
cy.get(PRODUCT_DETAILS.stockInput) cy.get(BUTTON_SELECTORS.confirm)
.parents()
.contains(warehouse.name)
.get(PRODUCT_DETAILS.stockInput)
.clearAndType(10)
.get(BUTTON_SELECTORS.confirm)
.click() .click()
.confirmationMessageShouldDisappear() .confirmationMessageShouldDisappear()
.wait("@ProductVariantDetails") .wait("@ProductVariantDetails")

View file

@ -9,23 +9,15 @@ import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
import { productVariantDetailUrl } from "../../../fixtures/urlList"; import { productVariantDetailUrl } from "../../../fixtures/urlList";
import { import {
createVariant, createVariant,
createVariantForSimpleProduct,
getVariant, getVariant,
updateChannelPriceInVariant,
} from "../../../support/api/requests/Product"; } from "../../../support/api/requests/Product";
import { import { createTypeProduct } from "../../../support/api/requests/ProductType";
createTypeProduct,
productAttributeAssignmentUpdate,
} from "../../../support/api/requests/ProductType";
import { getDefaultChannel } from "../../../support/api/utils/channelsUtils";
import { createWaitingForCaptureOrder } from "../../../support/api/utils/ordersUtils"; import { createWaitingForCaptureOrder } from "../../../support/api/utils/ordersUtils";
import { import * as productUtils from "../../../support/api/utils/products/productsUtils";
createProductInChannelWithoutVariants, import * as shippingUtils from "../../../support/api/utils/shippingUtils";
createTypeAttributeAndCategoryForProduct, import { deleteWarehouseStartsWith } from "../../../support/api/utils/warehouseUtils";
deleteProductsStartsWith,
} from "../../../support/api/utils/products/productsUtils";
import {
createShipping,
deleteShippingStartsWith,
} from "../../../support/api/utils/shippingUtils";
describe("Updating products without sku", () => { describe("Updating products without sku", () => {
const startsWith = "UpdateProductsSku"; const startsWith = "UpdateProductsSku";
@ -47,55 +39,33 @@ describe("Updating products without sku", () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
deleteProductsStartsWith(startsWith); productUtils.deleteProductsStartsWith(startsWith);
deleteShippingStartsWith(startsWith); shippingUtils.deleteShippingStartsWith(startsWith);
getDefaultChannel() deleteWarehouseStartsWith(startsWith);
.then(channel => {
defaultChannel = channel; cy.fixture("addresses").then(fixtureAddresses => {
cy.fixture("addresses");
})
.then(fixtureAddresses => {
address = fixtureAddresses.plAddress; address = fixtureAddresses.plAddress;
createShipping({
channelId: defaultChannel.id,
name,
address,
});
})
.then(
({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => {
warehouse = warehouseResp;
shippingMethod = shippingMethodResp;
createTypeAttributeAndCategoryForProduct({ name, attributeValues });
},
)
.then(
({
attribute: attributeResp,
productType: productTypeResp,
category: categoryResp,
}) => {
attribute = attributeResp;
productTypeWithVariants = productTypeResp;
category = categoryResp;
productAttributeAssignmentUpdate({
productTypeId: productTypeWithVariants.id,
attributeId: attribute.id,
}); });
productUtils
.createShippingProductTypeAttributeAndCategory(name, attributeValues)
.then(resp => {
cy.log(resp);
attribute = resp.attribute;
productTypeWithVariants = resp.productType;
category = resp.category;
defaultChannel = resp.defaultChannel;
warehouse = resp.warehouse;
shippingMethod = resp.shippingMethod;
createTypeProduct({ createTypeProduct({
name: productTypeWithoutVariantsName, name: productTypeWithoutVariantsName,
attributeId: attribute.id, attributeId: attribute.id,
hasVariants: false, hasVariants: false,
}); });
}, })
)
.then(productTypeResp => { .then(productTypeResp => {
productTypeWithoutVariants = productTypeResp; productTypeWithoutVariants = productTypeResp;
productAttributeAssignmentUpdate({ productUtils.createProductInChannelWithoutVariants({
productTypeId: productTypeWithoutVariants.id,
attributeId: attribute.id,
});
createProductInChannelWithoutVariants({
name, name,
channelId: defaultChannel.id, channelId: defaultChannel.id,
attributeId: attribute.id, attributeId: attribute.id,
@ -109,9 +79,51 @@ describe("Updating products without sku", () => {
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
}); });
it(
"should be able to add SKU to simple product TC: SALEOR_2802",
{ tags: ["@products", "@allEnv"] },
() => {
const productName = `${startsWith}${faker.datatype.number()}`;
const sku = `Sku${faker.datatype.number()}`;
let product;
let variant;
const productData = {
name: productName,
attributeId: attribute.id,
categoryId: category.id,
productTypeId: productTypeWithoutVariants.id,
channelId: defaultChannel.id,
warehouseId: warehouse.id,
quantityInWarehouse: 10,
trackInventory: false,
};
createSimpleProductWithVariant(productData).then(resp => {
product = resp.product;
variant = resp.variant;
cy.visitAndWaitForProgressBarToDisappear(
productVariantDetailUrl(product.id, variant.id),
)
.get(SHARED_ELEMENTS.skeleton)
.should("not.exist")
.get(VARIANTS_SELECTORS.skuInput)
.type(sku)
.addAliasToGraphRequest("VariantUpdate")
.get(BUTTON_SELECTORS.confirm)
.click()
.waitForRequestAndCheckIfNoErrors("@VariantUpdate")
.then(({ response }) => {
const responseSku =
response.body.data.productVariantUpdate.productVariant.sku;
expect(responseSku).to.equal(sku);
});
});
},
);
it( it(
"should add sku to variant", "should add sku to variant TC: SALEOR_2803",
{ tags: ["@products", "@allEnv", "@stable"] }, { tags: ["@products", "@allEnv", "@stable"] },
() => { () => {
const sku = "NewSku"; const sku = "NewSku";
@ -146,7 +158,7 @@ describe("Updating products without sku", () => {
); );
it( it(
"should remove sku from variant", "should remove sku from variant TC: SALEOR_2805",
{ tags: ["@products", "@allEnv", "@stable"] }, { tags: ["@products", "@allEnv", "@stable"] },
() => { () => {
let variant; let variant;
@ -192,4 +204,41 @@ describe("Updating products without sku", () => {
expect(order.id).to.be.ok; expect(order.id).to.be.ok;
}); });
} }
function createSimpleProductWithVariant({
name,
channelId,
warehouseId = null,
quantityInWarehouse = 10,
productTypeId,
attributeId,
categoryId,
trackInventory = true,
}) {
let product;
let variant;
return productUtils
.createProductInChannelWithoutVariants({
name,
channelId,
productTypeId,
attributeId,
categoryId,
})
.then(productResp => {
product = productResp;
createVariantForSimpleProduct({
productId: product.id,
warehouseId,
quantityInWarehouse,
trackInventory,
});
})
.then(variantResp => {
variant = variantResp;
updateChannelPriceInVariant(variant.id, defaultChannel.id);
})
.then(() => ({ product, variant }));
}
}); });

View file

@ -211,6 +211,58 @@ export function createVariant({
.its("body.data.productVariantBulkCreate.productVariants"); .its("body.data.productVariantBulkCreate.productVariants");
} }
export function createVariantForSimpleProduct({
productId,
sku,
warehouseId,
quantityInWarehouse = 1,
trackInventory = true,
weight = 1,
attributeId,
attributeName = "value",
}) {
const skuLines = getValueWithDefault(sku, `sku: "${sku}"`);
const attributeLines = getValueWithDefault(
attributeId,
`attributes: [{
id:"${attributeId}"
values: ["${attributeName}"]
}]`,
"attributes:[]",
);
const stocks = getValueWithDefault(
warehouseId,
`stocks:{
warehouse:"${warehouseId}"
quantity:${quantityInWarehouse}
}`,
);
const mutation = `mutation{
productVariantCreate(input: {
${attributeLines}
${skuLines}
trackInventory:${trackInventory}
weight: ${weight}
product: "${productId}"
${stocks}
}) {
productVariant{
id
name
}
errors{
field
message
}
}
}`;
return cy
.sendRequestWithQuery(mutation)
.its("body.data.productVariantCreate.productVariant");
}
export function deleteProduct(productId) { export function deleteProduct(productId) {
const mutation = `mutation{ const mutation = `mutation{
productDelete(id: "${productId}"){ productDelete(id: "${productId}"){
@ -304,12 +356,18 @@ export function updateVariantPrice({ variantId, channelId, price }) {
.its("body.data.productVariantChannelListingUpdate"); .its("body.data.productVariantChannelListingUpdate");
} }
export function updateVariantWarehouse({ variantId, warehouseId }) { export function updateVariantWarehouse({ variantId, warehouseId, quantity }) {
const quantityInWarehouse = getValueWithDefault(
quantity,
`quantity:${quantity}`,
`quantity: 0`,
);
const mutation = `mutation{ const mutation = `mutation{
productVariantStocksCreate(variantId: "${variantId}", productVariantStocksCreate(variantId: "${variantId}",
stocks: stocks:
{ {
quantity: 0, ${quantityInWarehouse}
warehouse: "${warehouseId}" warehouse: "${warehouseId}"
} }
){ ){

View file

@ -444,20 +444,29 @@ export function createShippingProductTypeAttributeAndCategory(
) { ) {
let warehouse; let warehouse;
let defaultChannel; let defaultChannel;
let shippingMethod;
return createShippingWithDefaultChannelAndAddress(name) return createShippingWithDefaultChannelAndAddress(name)
.then(({ warehouse: warehouseResp, defaultChannel: channel }) => { .then(
({
warehouse: warehouseResp,
defaultChannel: channel,
shippingMethod: shippingMethodResp,
}) => {
warehouse = warehouseResp; warehouse = warehouseResp;
defaultChannel = channel; defaultChannel = channel;
shippingMethod = shippingMethodResp;
createTypeAttributeAndCategoryForProduct({ name, attributeValues }); createTypeAttributeAndCategoryForProduct({ name, attributeValues });
}) },
)
.then(({ attribute, productType, category }) => ({ .then(({ attribute, productType, category }) => ({
attribute, attribute,
productType, productType,
category, category,
warehouse, warehouse,
defaultChannel, defaultChannel,
shippingMethod,
})); }));
} }

View file

@ -50,7 +50,7 @@ Cypress.Commands.add("fillAutocompleteSelect", (selectSelector, option) => {
}); });
cy.contains(BUTTON_SELECTORS.selectOption, option) cy.contains(BUTTON_SELECTORS.selectOption, option)
.should("be.visible") .should("be.visible")
.click(); .click({ force: true });
cy.wrap(option).as("option"); cy.wrap(option).as("option");
}); });
} else { } else {

View file

@ -3,6 +3,7 @@ import { PRODUCT_DETAILS } from "../../../../elements/catalog/products/product-d
import { VARIANTS_SELECTORS } from "../../../../elements/catalog/products/variants-selectors"; import { VARIANTS_SELECTORS } from "../../../../elements/catalog/products/variants-selectors";
import { AVAILABLE_CHANNELS_FORM } from "../../../../elements/channels/available-channels-form"; import { AVAILABLE_CHANNELS_FORM } from "../../../../elements/channels/available-channels-form";
import { BUTTON_SELECTORS } from "../../../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../../../elements/shared/button-selectors";
import { updateVariantWarehouse } from "../../../../support/api/requests/Product";
import { formatDate } from "../../../formatData/formatDate"; import { formatDate } from "../../../formatData/formatDate";
import { selectChannelVariantInDetailsPage } from "../../channelsPage"; import { selectChannelVariantInDetailsPage } from "../../channelsPage";
@ -14,6 +15,7 @@ export function variantsShouldBeVisible({ price }) {
export function createVariant({ export function createVariant({
sku, sku,
warehouseName, warehouseName,
warehouseId,
attributeName, attributeName,
price, price,
costPrice = price, costPrice = price,
@ -23,6 +25,7 @@ export function createVariant({
attributeName, attributeName,
sku, sku,
warehouseName, warehouseName,
warehouseId,
quantity, quantity,
costPrice, costPrice,
price, price,
@ -62,11 +65,21 @@ export function fillUpVariantDetails({
attributeType = "DROPDOWN", attributeType = "DROPDOWN",
sku, sku,
warehouseName, warehouseName,
warehouseId,
quantity, quantity,
costPrice, costPrice,
price, price,
}) { }) {
selectAttributeWithType({ attributeType, attributeName }); selectAttributeWithType({ attributeType, attributeName });
cy.get(PRICE_LIST.priceInput)
.each(input => {
cy.wrap(input).type(price);
})
.get(PRICE_LIST.costPriceInput)
.each(input => {
cy.wrap(input).type(costPrice);
});
if (sku) { if (sku) {
cy.get(VARIANTS_SELECTORS.skuInputInAddVariant).type(sku); cy.get(VARIANTS_SELECTORS.skuInputInAddVariant).type(sku);
} }
@ -79,17 +92,13 @@ export function fillUpVariantDetails({
.get(VARIANTS_SELECTORS.stockInput) .get(VARIANTS_SELECTORS.stockInput)
.type(quantity); .type(quantity);
} }
if (warehouseId) {
cy.get(PRICE_LIST.priceInput) saveVariant().then(({ response }) => {
.each(input => { const variantId =
cy.wrap(input).type(price); response.body.data.productVariantCreate.productVariant.id;
}) updateVariantWarehouse({ variantId, warehouseId, quantity });
.get(PRICE_LIST.costPriceInput)
.each(input => {
cy.wrap(input).type(costPrice);
}); });
}
cy.get(VARIANTS_SELECTORS.saveButton).click();
} }
export function fillUpVariantAttributeAndSku({ attributeName, sku }) { export function fillUpVariantAttributeAndSku({ attributeName, sku }) {