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,7 +45,8 @@ class Channels {
channelErrors{
message
}
}`;
}
}`;
return cy.sendRequestWithQuery(deleteChannelMutation);
}
}

View file

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

View file

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