tests for products

This commit is contained in:
Karolina Rakoczy 2021-02-18 20:32:35 +01:00
parent 1c51419685
commit 1b4da95e81
4 changed files with 130 additions and 96 deletions

View file

@ -45,6 +45,7 @@ class Channels {
channelErrors{ channelErrors{
message message
} }
}
}`; }`;
return cy.sendRequestWithQuery(deleteChannelMutation); return cy.sendRequestWithQuery(deleteChannelMutation);
} }

View file

@ -94,19 +94,26 @@ class Product {
price = 1, price = 1,
costPrice = 1 costPrice = 1
) { ) {
const channelListings = channelId
? `channelListings:{
channelId:"${channelId}"
price:"${price}"
costPrice:"${costPrice}"
}`
: "";
const stocks = warehouseId
? `stocks:{
warehouse:"${warehouseId}"
quantity:${quantity}
}`
: "";
const mutation = `mutation{ const mutation = `mutation{
productVariantBulkCreate(product: "${productId}", variants: { productVariantBulkCreate(product: "${productId}", variants: {
attributes: [] attributes: []
sku: "${sku}" sku: "${sku}"
channelListings: { ${channelListings}
channelId: "${channelId}" ${stocks}
price: "${price}"
costPrice: "${costPrice}"
}
stocks: {
warehouse: "${warehouseId}"
quantity: ${quantity}
}
}) { }) {
productVariants{ productVariants{
id id

View file

@ -34,9 +34,12 @@ describe("Publish products", () => {
}); });
it("should update product to published", () => { it("should update product to published", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => { let defaultChannel;
productsUtils channelsUtils
.createProductInChannel( .getDefaultChannel()
.then(channel => {
defaultChannel = channel;
productsUtils.createProductInChannel(
productName, productName,
defaultChannel.id, defaultChannel.id,
null, null,
@ -44,62 +47,68 @@ describe("Publish products", () => {
productType.id, productType.id,
attribute.id, attribute.id,
category.id, category.id,
null, 1,
false, false,
false, false,
true true
) );
})
.then(() => { .then(() => {
const product = productsUtils.getCreatedProduct(); const product = productsUtils.getCreatedProduct();
const productUrl = `${URL_LIST.products}${product.id}`; const productUrl = `${URL_LIST.products}${product.id}`;
productSteps.updateProductPublish(productUrl, true); productSteps.updateProductPublish(productUrl, true);
frontShopProductUtils frontShopProductUtils.isProductVisible(
.isProductVisible(product.id, defaultChannel.slug, productName) product.id,
defaultChannel.slug,
productName
);
})
.then(isVisible => { .then(isVisible => {
expect(isVisible).to.be.eq(true); expect(isVisible).to.be.eq(true);
}); });
}); });
});
});
it("should update product to not published", () => { it("should update product to not published", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => { let defaultChannel;
productsUtils let product;
.createProductInChannel(
productName, channelsUtils
productType.id, .getDefaultChannel()
attribute.id, .then(channel => {
category.id, defaultChannel = channel;
defaultChannel.id, productsUtils.createProductInChannel(
productName, productName,
defaultChannel.id, defaultChannel.id,
null, null,
null, null,
productType.id, productType.id,
attribute.id, attribute.id,
category.id, category.id
null, );
false, })
false,
true
)
.then(() => { .then(() => {
const product = productsUtils.getCreatedProduct(); product = productsUtils.getCreatedProduct();
const productUrl = `${URL_LIST.products}${product.id}`; const productUrl = `${URL_LIST.products}${product.id}`;
productSteps.updateProductPublish(productUrl, false); productSteps.updateProductPublish(productUrl, false);
frontShopProductUtils frontShopProductUtils.isProductVisible(
.isProductVisible(productId, defaultChannel.slug, productName) product.id,
defaultChannel.slug,
productName
);
})
.then(isVisible => { .then(isVisible => {
expect(isVisible).to.be.eq(false); expect(isVisible).to.be.eq(false);
}); cy.loginInShop();
cy.loginInShop().then(() => { })
frontShopProductUtils .then(() => {
.isProductVisible(product.id, defaultChannel.slug, productName) frontShopProductUtils.isProductVisible(
product.id,
defaultChannel.slug,
productName
);
})
.then(isVisible => { .then(isVisible => {
expect(isVisible).to.be.eq(true); expect(isVisible).to.be.eq(true);
}); });
}); });
});
});
});
}); });

View file

@ -34,61 +34,78 @@ describe("Products displayed in listings", () => {
}); });
it("should update product to visible in listings", () => { it("should update product to visible in listings", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => { let defaultChannel;
productsUtils channelsUtils
.createProductInChannel( .getDefaultChannel()
.then(channel => {
defaultChannel = channel;
productsUtils.createProductInChannel(
productName, productName,
defaultChannel.id,
null,
null,
productType.id, productType.id,
attribute.id, attribute.id,
category.id, category.id,
defaultChannel.id, 1,
true, true,
false, false,
false false
) );
})
.then(() => { .then(() => {
const productId = productsUtils.getCreatedProductId(); const product = productsUtils.getCreatedProduct();
const productUrl = `${URL_LIST.products}${productId}`; const productUrl = `${URL_LIST.products}${product.id}`;
productSteps.updateProductVisibleInListings(productUrl); productSteps.updateProductVisibleInListings(productUrl);
frontShopProductUtils frontShopProductUtils.isProductVisibleInSearchResult(
.isProductVisibleInSearchResult(productName, defaultChannel.slug) productName,
defaultChannel.slug
);
})
.then(isProductVisible => { .then(isProductVisible => {
expect(isProductVisible).to.be.eq(true); expect(isProductVisible).to.be.eq(true);
}); });
}); });
});
});
it("should update product to not visible in listings", () => { it("should update product to not visible in listings", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => { let defaultChannel;
productsUtils channelsUtils
.createProductInChannel( .getDefaultChannel()
.then(channel => {
defaultChannel = channel;
productsUtils.createProductInChannel(
productName, productName,
defaultChannel.id,
null,
null,
productType.id, productType.id,
attribute.id, attribute.id,
category.id, category.id,
defaultChannel.id, 1,
true, true,
false, false,
true true
) );
})
.then(() => { .then(() => {
const productId = productsUtils.getCreatedProductId(); const product = productsUtils.getCreatedProduct();
const productUrl = `${URL_LIST.products}${productId}`; const productUrl = `${URL_LIST.products}${product.id}`;
productSteps.updateProductVisibleInListings(productUrl); productSteps.updateProductVisibleInListings(productUrl);
frontShopProductUtils frontShopProductUtils
.isProductVisibleInSearchResult(productName, defaultChannel.slug) .isProductVisibleInSearchResult(productName, defaultChannel.slug)
.then(isProductVisible => { .then(isProductVisible => {
expect(isProductVisible).to.be.eq(false); expect(isProductVisible).to.be.eq(false);
}); });
cy.loginInShop().then(() => { cy.loginInShop();
frontShopProductUtils })
.isProductVisibleInSearchResult(productName, defaultChannel.slug) .then(() => {
frontShopProductUtils.isProductVisibleInSearchResult(
productName,
defaultChannel.slug
);
})
.then(isProductVisible => { .then(isProductVisible => {
expect(isProductVisible).to.be.eq(true); expect(isProductVisible).to.be.eq(true);
}); });
}); });
});
});
});
}); });