tests for metadata (#1206)

* tests for metadata

* change name of the function
This commit is contained in:
Karolina Rakoczy 2021-07-15 12:25:31 +03:00 committed by GitHub
parent 2412911a9d
commit e6d6621816
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 178 additions and 7 deletions

View file

@ -0,0 +1,31 @@
export function updateMetadata(id, key, value) {
const mutation = `mutation{
updateMetadata(id:"${id}" input:{
key:"${key}",
value:"${value}"
}){
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation).its("body.data.updateMetadata");
}
export function updatePrivateMetadata(id, key, value) {
const mutation = `mutation{
updatePrivateMetadata(id:"${id}" input:{
key:"${key}",
value:"${value}"
}){
errors{
field
message
}
}
}`;
return cy
.sendRequestWithQuery(mutation)
.its("body.data.updatePrivateMetadata");
}

View file

@ -1,4 +1,4 @@
import { getDefaultAddress } from "./utils/Utils";
import { getDefaultAddress, getValueWithDefault } from "./utils/Utils";
export function markOrderAsPaid(orderId) {
const mutation = `mutation{
@ -25,16 +25,22 @@ export function addProductToOrder(orderId, variantId, quantity = 1) {
return cy.sendRequestWithQuery(mutation);
}
export function createDraftOrder(
export function createDraftOrder({
customerId,
shippingMethodId,
channelId,
address
) {
}) {
const user = getValueWithDefault(customerId, `user:"${customerId}"`);
const shippingMethod = getValueWithDefault(
shippingMethodId,
`shippingMethod:"${shippingMethodId}"`
);
const mutation = `mutation{
draftOrderCreate(input:{
user:"${customerId}"
shippingMethod:"${shippingMethodId}"
${user}
${shippingMethod}
channelId: "${channelId}"
${getDefaultAddress(address, "shippingAddress")}
${getDefaultAddress(address, "billingAddress")}
@ -80,6 +86,14 @@ export function getOrder(orderId) {
shippingMethod{
id
}
metadata{
key
value
}
privateMetadata{
key
value
}
}
}`;
cy.sendRequestWithQuery(query).its("body.data.order");

View file

@ -69,3 +69,29 @@ export function getProductDetails(productId, channelId, auth = "token") {
}`;
return cy.sendRequestWithQuery(query, auth);
}
export function getProductMetadata({
productId,
channelSlug,
auth,
withPrivateMetadata
}) {
const privateMetadata = getValueWithDefault(
withPrivateMetadata,
`privateMetadata{
key
value
}`
);
const query = `query{
product(id:"${productId}" channel:"${channelSlug}"){
metadata{
key
value
}
${privateMetadata}
}
}`;
return cy.sendRequestWithQuery(query, auth).its("body");
}

View file

@ -0,0 +1,100 @@
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);
});
});
});

View file

@ -61,7 +61,7 @@ export function createReadyToFulfillOrder({
}) {
let order;
return orderRequest
.createDraftOrder(customerId, shippingMethodId, channelId, address)
.createDraftOrder({ customerId, shippingMethodId, channelId, address })
.then(orderResp => {
order = orderResp;
assignVariantsToOrder(order, variantsList);
@ -104,7 +104,7 @@ export function createOrder({
}) {
let order;
return orderRequest
.createDraftOrder(customerId, shippingMethodId, channelId, address)
.createDraftOrder({ customerId, shippingMethodId, channelId, address })
.then(orderResp => {
order = orderResp;
assignVariantsToOrder(order, variantsList);