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";
|
|
|
|
|
2021-09-27 10:04:21 +00:00
|
|
|
import {
|
|
|
|
updateMetadata,
|
2022-06-27 16:49:35 +00:00
|
|
|
updatePrivateMetadata,
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../support/api/requests/Metadata";
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
createDraftOrder,
|
|
|
|
getOrder,
|
|
|
|
} from "../support/api/requests/Order";
|
|
|
|
import {
|
|
|
|
getProductMetadata,
|
|
|
|
} from "../support/api/requests/storeFront/ProductDetails";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { getDefaultChannel } from "../support/api/utils/channelsUtils";
|
2021-07-23 09:46:44 +00:00
|
|
|
import {
|
|
|
|
createProductInChannel,
|
2022-01-31 08:37:49 +00:00
|
|
|
createTypeAttributeAndCategoryForProduct,
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../support/api/utils/products/productsUtils";
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
describe("Test for metadata", () => {
|
|
|
|
const startsWith = "Metadata";
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const metadata = { key: "metadataKey", value: "metadataValue" };
|
|
|
|
let channel;
|
|
|
|
let product;
|
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(channelResp => {
|
|
|
|
channel = channelResp;
|
|
|
|
createTypeAttributeAndCategoryForProduct({ name });
|
|
|
|
})
|
|
|
|
.then(({ attribute, category, productType }) => {
|
|
|
|
createProductInChannel({
|
|
|
|
attributeId: attribute.id,
|
|
|
|
categoryId: category.id,
|
|
|
|
channelId: channel.id,
|
|
|
|
name,
|
2022-06-27 16:49:35 +00:00
|
|
|
productTypeId: productType.id,
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
2022-06-27 09:30:51 +00:00
|
|
|
})
|
|
|
|
.then(({ product: productResp }) => {
|
|
|
|
product = productResp;
|
2023-01-16 13:55:38 +00:00
|
|
|
cy.checkIfDataAreNotNull({ channel, product });
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
2023-08-17 10:43:03 +00:00
|
|
|
"should create metadata for product TC: SALEOR_3301",
|
2022-06-27 09:30:51 +00:00
|
|
|
{ tags: ["@metadata", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2021-07-23 09:46:44 +00:00
|
|
|
updateMetadata(product.id, metadata.key, metadata.value);
|
|
|
|
updatePrivateMetadata(product.id, metadata.key, metadata.value)
|
|
|
|
.then(() => {
|
|
|
|
getProductMetadata({
|
|
|
|
productId: product.id,
|
|
|
|
channelSlug: channel.slug,
|
|
|
|
auth: "auth",
|
2022-06-27 16:49:35 +00:00
|
|
|
withPrivateMetadata: true,
|
2021-07-23 09:46:44 +00:00
|
|
|
}).its("data");
|
|
|
|
})
|
|
|
|
.then(({ product: productResp }) => {
|
|
|
|
expect(productResp.metadata[0].key).to.eq(metadata.key);
|
|
|
|
expect(productResp.metadata[0].value).to.eq(metadata.value);
|
|
|
|
expect(productResp.privateMetadata[0].key).to.eq(metadata.key);
|
|
|
|
expect(productResp.privateMetadata[0].value).to.eq(metadata.value);
|
|
|
|
getProductMetadata({
|
|
|
|
productId: product.id,
|
|
|
|
channelSlug: channel.slug,
|
|
|
|
auth: "token",
|
2022-06-27 16:49:35 +00:00
|
|
|
withPrivateMetadata: true,
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(({ errors }) => {
|
|
|
|
expect(errors[0].extensions.exception.code).to.eq("PermissionDenied");
|
|
|
|
getProductMetadata({
|
|
|
|
productId: product.id,
|
|
|
|
channelSlug: channel.slug,
|
|
|
|
auth: "token",
|
2022-06-27 16:49:35 +00:00
|
|
|
withPrivateMetadata: false,
|
2021-07-23 09:46:44 +00:00
|
|
|
}).its("data");
|
|
|
|
})
|
|
|
|
.then(({ product: productResp }) => {
|
|
|
|
expect(productResp.metadata[0].key).to.eq(metadata.key);
|
|
|
|
expect(productResp.metadata[0].value).to.eq(metadata.value);
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
|
|
|
it(
|
2023-08-17 10:43:03 +00:00
|
|
|
"should create metadata for order TC: SALEOR_3302",
|
2022-06-27 09:30:51 +00:00
|
|
|
{ tags: ["@metadata", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
let order;
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2021-07-23 09:46:44 +00:00
|
|
|
createDraftOrder({ channelId: channel.id })
|
|
|
|
.then(orderResp => {
|
|
|
|
order = orderResp;
|
2022-10-27 09:40:52 +00:00
|
|
|
updateMetadata(order.id, metadata.key, metadata.value);
|
|
|
|
updatePrivateMetadata(order.id, metadata.key, metadata.value);
|
2021-07-23 09:46:44 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
getOrder(order.id);
|
|
|
|
})
|
|
|
|
.then(orderResp => {
|
|
|
|
expect(orderResp.metadata[0].key).to.eq(metadata.key);
|
|
|
|
expect(orderResp.metadata[0].value).to.eq(metadata.value);
|
|
|
|
expect(orderResp.privateMetadata[0].key).to.eq(metadata.key);
|
|
|
|
expect(orderResp.privateMetadata[0].value).to.eq(metadata.value);
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|