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) {
@ -106,16 +107,16 @@ class Product {
warehouse: "${warehouseId}"
quantity: ${quantity}
}
}) {
productVariants{
id
name
}
bulkProductErrors{
field
message
}
}
}) {
productVariants{
id
name
}
bulkProductErrors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}

View file

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

View file

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

View file

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