2021-09-27 10:04:21 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../../support"/>
|
|
|
|
|
2021-07-23 09:46:44 +00:00
|
|
|
import faker from "faker";
|
|
|
|
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
PRODUCT_DETAILS,
|
|
|
|
} from "../../elements/catalog/products/product-details";
|
2021-07-23 09:46:44 +00:00
|
|
|
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { productDetailsUrl } from "../../fixtures/urlList";
|
|
|
|
import { ONE_PERMISSION_USERS } from "../../fixtures/users";
|
|
|
|
import { createCategory } from "../../support/api/requests/Category";
|
|
|
|
import { createCollection } from "../../support/api/requests/Collections";
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
getProductDetails,
|
|
|
|
} from "../../support/api/requests/storeFront/ProductDetails";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
expectCorrectProductInformation,
|
|
|
|
} from "../../support/api/utils/products/checkProductInfo";
|
2021-07-23 09:46:44 +00:00
|
|
|
import {
|
|
|
|
createProductInChannel,
|
|
|
|
createTypeAttributeAndCategoryForProduct,
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../support/api/utils/products/productsUtils";
|
|
|
|
import { metadataForms } from "../../support/pages/catalog/metadataComponent";
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
fillUpCommonFieldsForAllProductTypes,
|
|
|
|
} from "../../support/pages/catalog/products/productDetailsPage";
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
describe("Update products", () => {
|
|
|
|
const startsWith = "CyUpdateProducts-";
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const description = faker.lorem.sentences(2);
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
let defaultChannel;
|
|
|
|
let collection;
|
|
|
|
let product;
|
|
|
|
let attribute;
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
before(() => {
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2022-06-27 09:30:51 +00:00
|
|
|
getDefaultChannel()
|
|
|
|
.then(channel => {
|
|
|
|
defaultChannel = channel;
|
|
|
|
createCollection(name);
|
|
|
|
})
|
|
|
|
.then(collectionResp => {
|
|
|
|
collection = collectionResp;
|
|
|
|
createTypeAttributeAndCategoryForProduct({ name });
|
|
|
|
})
|
|
|
|
.then(({ attribute: attributeResp, category, productType }) => {
|
|
|
|
attribute = attributeResp;
|
|
|
|
createProductInChannel({
|
|
|
|
attributeId: attribute.id,
|
|
|
|
categoryId: category.id,
|
|
|
|
productTypeId: productType.id,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
name,
|
|
|
|
collectionId: collection.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
description,
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
2022-06-27 09:30:51 +00:00
|
|
|
})
|
|
|
|
.then(({ product: productResp }) => {
|
|
|
|
product = productResp;
|
2023-01-16 09:43:13 +00:00
|
|
|
cy.checkIfDataAreNotNull({
|
|
|
|
defaultChannel,
|
|
|
|
collection,
|
|
|
|
product,
|
|
|
|
attribute,
|
|
|
|
});
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-12-30 07:21:28 +00:00
|
|
|
it(
|
|
|
|
"Should update product. TC: SALEOR_2703",
|
|
|
|
{ tags: ["@products", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
|
|
|
const updatedName = `${startsWith}${faker.random.number()}`;
|
|
|
|
let updatedCategory;
|
|
|
|
let updatedCollection;
|
|
|
|
createCategory({ name: updatedName })
|
|
|
|
.then(categoryResp => {
|
|
|
|
updatedCategory = categoryResp;
|
|
|
|
createCollection(updatedName);
|
|
|
|
})
|
|
|
|
.then(collectionResp => {
|
|
|
|
updatedCollection = collectionResp;
|
|
|
|
const productData = {
|
|
|
|
generalInfo: {
|
|
|
|
name: updatedName,
|
|
|
|
description: faker.lorem.sentence(),
|
|
|
|
rating: 3,
|
2021-07-23 09:46:44 +00:00
|
|
|
},
|
2022-12-30 07:21:28 +00:00
|
|
|
seo: {
|
|
|
|
slug: updatedName,
|
|
|
|
title: "newTitle",
|
|
|
|
description: "New description.",
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-12-30 07:21:28 +00:00
|
|
|
metadata: {
|
|
|
|
private: {
|
|
|
|
metadataForm: metadataForms.private,
|
|
|
|
name: "newPrivate",
|
|
|
|
value: "value1",
|
|
|
|
},
|
|
|
|
public: {
|
|
|
|
metadataForm: metadataForms.public,
|
|
|
|
name: "newPublic",
|
|
|
|
value: "value2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
productOrganization: {
|
|
|
|
category: updatedCategory.name,
|
|
|
|
collection: updatedCollection.name,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
cy.clearSessionData()
|
|
|
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.product)
|
|
|
|
.visit(productDetailsUrl(product.id))
|
|
|
|
.get(PRODUCT_DETAILS.collectionRemoveButtons)
|
|
|
|
.click();
|
|
|
|
fillUpCommonFieldsForAllProductTypes(productData, false);
|
|
|
|
cy.addAliasToGraphRequest("UpdatePrivateMetadata")
|
|
|
|
.addAliasToGraphRequest("UpdateMetadata")
|
|
|
|
.addAliasToGraphRequest("ProductUpdate")
|
|
|
|
.get(BUTTON_SELECTORS.confirm)
|
|
|
|
.click()
|
|
|
|
.confirmationMessageShouldDisappear()
|
|
|
|
.waitForRequestAndCheckIfNoErrors("@ProductUpdate")
|
|
|
|
.waitForRequestAndCheckIfNoErrors("@UpdateMetadata")
|
|
|
|
.waitForRequestAndCheckIfNoErrors("@UpdatePrivateMetadata");
|
|
|
|
productData.productOrganization.productType = name;
|
|
|
|
productData.attribute = attribute;
|
|
|
|
cy.loginUserViaRequest("token")
|
|
|
|
.then(() => {
|
|
|
|
getProductDetails(product.id, defaultChannel.slug, "auth").its(
|
|
|
|
"body.data.product",
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.then(resp => {
|
|
|
|
expectCorrectProductInformation(resp, productData);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
2022-12-30 07:21:28 +00:00
|
|
|
"should delete product. TC: SALEOR_2704",
|
2022-06-27 09:30:51 +00:00
|
|
|
{ tags: ["@products", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
cy.clearSessionData()
|
|
|
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.product)
|
|
|
|
.visit(productDetailsUrl(product.id))
|
|
|
|
.addAliasToGraphRequest("ProductDelete")
|
|
|
|
.get(BUTTON_SELECTORS.deleteButton)
|
|
|
|
.click()
|
|
|
|
.get(BUTTON_SELECTORS.submit)
|
|
|
|
.click()
|
2021-09-27 10:04:21 +00:00
|
|
|
.waitForRequestAndCheckIfNoErrors("@ProductDelete")
|
2021-07-23 09:46:44 +00:00
|
|
|
.loginUserViaRequest("token")
|
|
|
|
.then(() => {
|
|
|
|
getProductDetails(product.id, defaultChannel.slug).its("body.data");
|
|
|
|
})
|
|
|
|
.then(
|
|
|
|
productResp =>
|
2022-06-27 16:49:35 +00:00
|
|
|
expect(productResp.product, "Check if product exist").to.be.null,
|
2021-07-23 09:46:44 +00:00
|
|
|
);
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|