tests for available for purchase

This commit is contained in:
Karolina Rakoczy 2021-02-18 19:28:01 +01:00
parent 5fa5eda4a7
commit a33b13aaa2
4 changed files with 84 additions and 53 deletions

View file

@ -46,6 +46,7 @@ class Product {
} }
} }
}`; }`;
cy.sendRequestWithQuery(mutation);
} }
updateChannelPriceInVariant(variantId, channelId) { updateChannelPriceInVariant(variantId, channelId) {
@ -106,16 +107,16 @@ class Product {
warehouse: "${warehouseId}" warehouse: "${warehouseId}"
quantity: ${quantity} quantity: ${quantity}
} }
}) { }) {
productVariants{ productVariants{
id id
name name
} }
bulkProductErrors{ bulkProductErrors{
field field
message message
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }

View file

@ -27,16 +27,24 @@ describe("Products available in listings", () => {
shippingUtils.deleteShipping(startsWith); shippingUtils.deleteShipping(startsWith);
productsUtils.deleteProperProducts(startsWith); productsUtils.deleteProperProducts(startsWith);
channelsUtils.getDefaultChannel().then(channel => { channelsUtils
defaultChannel = channel; .getDefaultChannel()
cy.fixture("addresses").then(json => { .then(channel => {
shippingUtils defaultChannel = channel;
.createShipping(defaultChannel, name, json.plAddress, 10) cy.fixture("addresses");
.then(() => { })
warehouse = shippingUtils.getWarehouse(); .then(addressesFixture => {
}); shippingUtils.createShipping(
defaultChannel,
name,
addressesFixture.plAddress,
10
);
})
.then(() => {
warehouse = shippingUtils.getWarehouse();
}); });
});
productsUtils.createTypeAttributeAndCategoryForProduct(name).then(() => { productsUtils.createTypeAttributeAndCategoryForProduct(name).then(() => {
productType = productsUtils.getProductType(); productType = productsUtils.getProductType();
attribute = productsUtils.getAttribute(); attribute = productsUtils.getAttribute();
@ -50,7 +58,6 @@ describe("Products available in listings", () => {
it("should update product to available for purchase", () => { it("should update product to available for purchase", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
productsUtils.createProductInChannel(productName);
productsUtils productsUtils
.createProductInChannel( .createProductInChannel(
productName, productName,
@ -59,26 +66,27 @@ describe("Products available in listings", () => {
10, 10,
productType.id, productType.id,
attribute.id, attribute.id,
category, category.id,
1,
true, true,
false, false,
true, true
1
) )
.then(() => { .then(() => {
const productUrl = `${ const productUrl = `${URL_LIST.products}${
URL_LIST.products productsUtils.getCreatedProduct().id
}${productsUtils.getCreatedProductId()}`; }`;
productSteps.updateProductIsAvailableForPurchase(productUrl, true); productSteps.updateProductIsAvailableForPurchase(productUrl, true);
frontShopProductUtils })
.isProductAvailableForPurchase( .then(() => {
productsUtils.getCreatedProductId(), frontShopProductUtils.isProductAvailableForPurchase(
defaultChannel.slug, productsUtils.getCreatedProduct().id,
productName defaultChannel.slug,
) productName
.then(isProductVisible => { );
expect(isProductVisible).to.be.eq(true); })
}); .then(isProductVisible => {
expect(isProductVisible).to.be.eq(true);
}); });
}); });
it("should update product to not available for purchase", () => { it("should update product to not available for purchase", () => {
@ -91,20 +99,20 @@ describe("Products available in listings", () => {
10, 10,
productType.id, productType.id,
attribute.id, attribute.id,
category, category.id,
1,
true, true,
true, true,
true, true
1
) )
.then(() => { .then(() => {
const productUrl = `${ const productUrl = `${URL_LIST.products}${
URL_LIST.products productsUtils.getCreatedProduct().id
}${productsUtils.getCreatedProductId()}`; }`;
productSteps.updateProductIsAvailableForPurchase(productUrl, false); productSteps.updateProductIsAvailableForPurchase(productUrl, false);
frontShopProductUtils frontShopProductUtils
.isProductAvailableForPurchase( .isProductAvailableForPurchase(
productsUtils.getCreatedProductId(), productsUtils.getCreatedProduct().id,
defaultChannel.slug, defaultChannel.slug,
productName productName
) )

View file

@ -38,20 +38,23 @@ describe("Publish products", () => {
productsUtils productsUtils
.createProductInChannel( .createProductInChannel(
productName, productName,
defaultChannel.id,
null,
null,
productType.id, productType.id,
attribute.id, attribute.id,
category.id, category.id,
defaultChannel.id, null,
false, false,
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.updateProductPublish(productUrl, true); productSteps.updateProductPublish(productUrl, true);
frontShopProductUtils frontShopProductUtils
.isProductVisible(productId, defaultChannel.slug, productName) .isProductVisible(product.id, defaultChannel.slug, productName)
.then(isVisible => { .then(isVisible => {
expect(isVisible).to.be.eq(true); expect(isVisible).to.be.eq(true);
}); });
@ -68,13 +71,21 @@ describe("Publish products", () => {
attribute.id, attribute.id,
category.id, category.id,
defaultChannel.id, defaultChannel.id,
true, productName,
defaultChannel.id,
null,
null,
productType.id,
attribute.id,
category.id,
null,
false,
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.updateProductPublish(productUrl, false); productSteps.updateProductPublish(productUrl, false);
frontShopProductUtils frontShopProductUtils
.isProductVisible(productId, defaultChannel.slug, productName) .isProductVisible(productId, defaultChannel.slug, productName)
@ -83,7 +94,7 @@ describe("Publish products", () => {
}); });
cy.loginInShop().then(() => { cy.loginInShop().then(() => {
frontShopProductUtils frontShopProductUtils
.isProductVisible(productId, defaultChannel.slug, productName) .isProductVisible(product.id, defaultChannel.slug, productName)
.then(isVisible => { .then(isVisible => {
expect(isVisible).to.be.eq(true); expect(isVisible).to.be.eq(true);
}); });

View file

@ -30,11 +30,20 @@ class ProductsUtils {
productTypeId, productTypeId,
attributeId, attributeId,
categoryId, categoryId,
price price,
isPublished = true,
isAvailableForPurchase = true,
visibleInListings = true
) { ) {
return this.createProduct(attributeId, name, productTypeId, categoryId) return this.createProduct(attributeId, name, productTypeId, categoryId)
.then(() => .then(() =>
this.productRequest.updateChannelInProduct(this.product.id, channelId) this.productRequest.updateChannelInProduct(
this.product.id,
channelId,
isPublished,
isAvailableForPurchase,
visibleInListings
)
) )
.then(() => { .then(() => {
this.createVariant( this.createVariant(
@ -101,7 +110,9 @@ class ProductsUtils {
resp.body.data.productVariantBulkCreate.productVariants) resp.body.data.productVariantBulkCreate.productVariants)
); );
} }
getCreatedProduct() {
return this.product;
}
getCreatedVariants() { getCreatedVariants() {
return this.variants; return this.variants;
} }