saleor-dashboard/cypress/integration/allEnv/metadata.js
Karolina Rakoczy e6d6621816
tests for metadata (#1206)
* tests for metadata

* change name of the function
2021-07-15 12:25:31 +03:00

100 lines
3.4 KiB
JavaScript

import faker from "faker";
import {
updateMetadata,
updatePrivateMetadata
} from "../../apiRequests/Metadata";
import { createDraftOrder, getOrder } from "../../apiRequests/Order";
import { getProductMetadata } from "../../apiRequests/storeFront/ProductDetails";
import { getDefaultChannel } from "../../utils/channelsUtils";
import {
createProductInChannel,
createTypeAttributeAndCategoryForProduct
} from "../../utils/products/productsUtils";
describe("Test for metadata", () => {
const startsWith = "Metadata";
const name = `${startsWith}${faker.datatype.number()}`;
const metadata = { key: "metadataKey", value: "metadataValue" };
let channel;
let product;
before(() => {
cy.clearSessionData().loginUserViaRequest();
getDefaultChannel()
.then(channelResp => {
channel = channelResp;
createTypeAttributeAndCategoryForProduct(name);
})
.then(({ attribute, category, productType }) => {
createProductInChannel({
attributeId: attribute.id,
categoryId: category.id,
channelId: channel.id,
name,
productTypeId: productType.id
});
})
.then(({ product: productResp }) => {
product = productResp;
});
});
it("should create metadata for product", () => {
cy.clearSessionData().loginUserViaRequest();
updateMetadata(product.id, metadata.key, metadata.value);
updatePrivateMetadata(product.id, metadata.key, metadata.value)
.then(() => {
getProductMetadata({
productId: product.id,
channelSlug: channel.slug,
auth: "auth",
withPrivateMetadata: true
}).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",
withPrivateMetadata: true
});
})
.then(({ errors }) => {
expect(errors[0].extensions.exception.code).to.eq("PermissionDenied");
getProductMetadata({
productId: product.id,
channelSlug: channel.slug,
auth: "token",
withPrivateMetadata: false
}).its("data");
})
.then(({ product: productResp }) => {
expect(productResp.metadata[0].key).to.eq(metadata.key);
expect(productResp.metadata[0].value).to.eq(metadata.value);
});
});
it("should create metadata for order", () => {
let order;
cy.clearSessionData().loginUserViaRequest();
createDraftOrder({ channelId: channel.id })
.then(orderResp => {
order = orderResp;
updateMetadata(order.id, metadata.key, metadata.value);
updatePrivateMetadata(order.id, metadata.key, metadata.value);
})
.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);
});
});
});