test for variants
This commit is contained in:
parent
089a2c428d
commit
7e793140e7
5 changed files with 35 additions and 61 deletions
|
@ -1,11 +1,12 @@
|
|||
class Attribute {
|
||||
createAttribute(name) {
|
||||
createAttribute(name, attributeValues = ["value"]) {
|
||||
attributeValues = attributeValues.map(element => `{name:"${element}"}`);
|
||||
const mutation = `mutation{
|
||||
attributeCreate(input:{
|
||||
name:"${name}"
|
||||
valueRequired:false
|
||||
type:PRODUCT_TYPE
|
||||
values:[{name: "value1"}, {name: "value2"}]
|
||||
values: [${attributeValues}]
|
||||
}){
|
||||
attribute{
|
||||
id
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import Utils from "./utils/Utils";
|
||||
import { getValueWithDefault } from "./utils/Utils";
|
||||
|
||||
class Product {
|
||||
utils = new Utils();
|
||||
getFirstProducts(first, search) {
|
||||
const filter = search
|
||||
? `, filter:{
|
||||
|
@ -97,7 +96,7 @@ class Product {
|
|||
price = 1,
|
||||
costPrice = 1
|
||||
) {
|
||||
const channelListings = this.utils.getValueWithDefault(
|
||||
const channelListings = getValueWithDefault(
|
||||
channelId,
|
||||
`channelListings:{
|
||||
channelId:"${channelId}"
|
||||
|
@ -106,7 +105,7 @@ class Product {
|
|||
}`
|
||||
);
|
||||
|
||||
const stocks = this.utils.getValueWithDefault(
|
||||
const stocks = getValueWithDefault(
|
||||
warehouseId,
|
||||
`stocks:{
|
||||
warehouse:"${warehouseId}"
|
||||
|
|
|
@ -1,6 +1,2 @@
|
|||
class Utils {
|
||||
getValueWithDefault(condition, value, defaultValue = "") {
|
||||
return condition ? value : defaultValue;
|
||||
}
|
||||
}
|
||||
export default Utils;
|
||||
export const getValueWithDefault = (condition, value, defaultValue = "") =>
|
||||
condition ? value : defaultValue;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import faker from "faker";
|
||||
import { visit } from "graphql";
|
||||
|
||||
import Channels from "../../apiRequests/Channels";
|
||||
import Product from "../../apiRequests/Product";
|
||||
import ProductDetails from "../../apiRequests/storeFront/ProductDetails";
|
||||
import VariantsSteps from "../../steps/products/VariantsSteps";
|
||||
import { urlList } from "../../url/urlList";
|
||||
import ChannelsUtils from "../../utils/channelsUtils";
|
||||
|
@ -14,6 +12,7 @@ import StoreFrontProductUtils from "../../utils/storeFront/storeFrontProductUtil
|
|||
// <reference types="cypress" />
|
||||
describe("creating variants", () => {
|
||||
const startsWith = "Cy-";
|
||||
const attributeValues = ["value1", "value2"];
|
||||
|
||||
const productUtils = new ProductsUtils();
|
||||
const channelsUtils = new ChannelsUtils();
|
||||
|
@ -21,7 +20,6 @@ describe("creating variants", () => {
|
|||
const storeFrontProductUtils = new StoreFrontProductUtils();
|
||||
const product = new Product();
|
||||
const channels = new Channels();
|
||||
const productDetails = new ProductDetails();
|
||||
|
||||
const variantsSteps = new VariantsSteps();
|
||||
|
||||
|
@ -52,11 +50,13 @@ describe("creating variants", () => {
|
|||
)
|
||||
.then(() => (warehouse = shippingUtils.getWarehouse()));
|
||||
|
||||
productUtils.createTypeAttributeAndCategoryForProduct(name).then(() => {
|
||||
attribute = productUtils.getAttribute();
|
||||
productType = productUtils.getProductType();
|
||||
category = productUtils.getCategory();
|
||||
});
|
||||
productUtils
|
||||
.createTypeAttributeAndCategoryForProduct(name, attributeValues)
|
||||
.then(() => {
|
||||
attribute = productUtils.getAttribute();
|
||||
productType = productUtils.getProductType();
|
||||
category = productUtils.getCategory();
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -87,22 +87,17 @@ describe("creating variants", () => {
|
|||
createdProduct.id,
|
||||
defaultChannel.slug
|
||||
);
|
||||
// productDetails
|
||||
// .getProductDetails(createdProduct.id, defaultChannel.slug)
|
||||
})
|
||||
.then(variants => {
|
||||
// expect(productDetailsResp.body[0].data.product.name).to.equal(name);
|
||||
expect(variants[0].name).to.equal(attribute.values[0].name);
|
||||
expect(variants[0].pricing.price.gross.amount).to.equal(price);
|
||||
// expect(
|
||||
// productDetailsResp.body[0].data.product.variants[0].pricing.price
|
||||
// .gross.amount
|
||||
// ).to.equal(price);
|
||||
});
|
||||
});
|
||||
it("should create several variants", () => {
|
||||
const name = `${startsWith}${faker.random.number()}`;
|
||||
const secondVariantSku = `${startsWith}${faker.random.number()}`;
|
||||
const firstVariant = { price: 5, attributeValue: attributeValues[0] };
|
||||
const secondVariant = { price: 8, attributeValue: attributeValues[1] };
|
||||
const variantsPrice = 5;
|
||||
let createdProduct;
|
||||
|
||||
|
@ -114,7 +109,7 @@ describe("creating variants", () => {
|
|||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
categoryId: category.id,
|
||||
price: variantsPrice
|
||||
price: firstVariant.price
|
||||
})
|
||||
.then(() => {
|
||||
createdProduct = productUtils.getCreatedProduct();
|
||||
|
@ -123,33 +118,18 @@ describe("creating variants", () => {
|
|||
sku: secondVariantSku,
|
||||
warehouseName: warehouse.name,
|
||||
attributeName: attribute.values[1].name,
|
||||
price: variantsPrice
|
||||
price: secondVariant.price
|
||||
});
|
||||
})
|
||||
.then(
|
||||
() =>
|
||||
storeFrontProductUtils.getProductVariants(
|
||||
createdProduct.id,
|
||||
defaultChannel.slug
|
||||
)
|
||||
// productDetails.getProductDetails(createdProduct.id, defaultChannel.slug)
|
||||
.then(() =>
|
||||
storeFrontProductUtils.getProductVariants(
|
||||
createdProduct.id,
|
||||
defaultChannel.slug
|
||||
)
|
||||
)
|
||||
.then(variants => {
|
||||
expect(variants).to.have.length(2);
|
||||
expect(variants[0].pricing.price.gross.amount).to.equal(variantsPrice);
|
||||
expect(variants[1].pricing.price.gross.amount).to.equal(variantsPrice);
|
||||
// expect(productDetailsResp.body[0].data.product.name).to.equal(name);
|
||||
// expect(productDetailsResp.body[0].data.product.variants).to.have.length(
|
||||
// 2
|
||||
// );
|
||||
// expect(
|
||||
// productDetailsResp.body[0].data.product.variants[0].pricing.price
|
||||
// .gross.amount
|
||||
// ).to.equal(variantsPrice);
|
||||
// expect(
|
||||
// productDetailsResp.body[0].data.product.variants[1].pricing.price
|
||||
// .gross.amount
|
||||
// ).to.equal(variantsPrice);
|
||||
expect(variants).includes(firstVariant, secondVariant);
|
||||
});
|
||||
});
|
||||
it("should create variant for many channels", () => {
|
||||
|
@ -183,13 +163,12 @@ describe("creating variants", () => {
|
|||
})
|
||||
.then(() => {
|
||||
cy.visit(`${urlList.products}${createdProduct.id}`);
|
||||
variantsSteps.createFirstVariant(
|
||||
variantsSteps.createFirstVariant({
|
||||
name,
|
||||
warehouse.id,
|
||||
variantsPrice,
|
||||
attribute.name
|
||||
);
|
||||
// productDetails.getProductDetails(product.id, defaultChannel.slug);
|
||||
warehouseId: warehouse.id,
|
||||
price: variantsPrice,
|
||||
attribute: attribute.values[0].name
|
||||
});
|
||||
storeFrontProductUtils.getProductVariants(
|
||||
product.id,
|
||||
defaultChannel.slug
|
||||
|
@ -200,7 +179,6 @@ describe("creating variants", () => {
|
|||
})
|
||||
.then(() => {
|
||||
storeFrontProductUtils.getProductVariants(product.id, newChannel.slug);
|
||||
// productDetails.getProductDetails(product.id, newChannel.slug);
|
||||
})
|
||||
.then(variants => {
|
||||
expect(variants[0].pricing.price.gross.amount).to.equal(variantsPrice);
|
||||
|
|
|
@ -57,14 +57,14 @@ class ProductsUtils {
|
|||
});
|
||||
}
|
||||
|
||||
createTypeAttributeAndCategoryForProduct(name) {
|
||||
return this.createAttribute(name)
|
||||
createTypeAttributeAndCategoryForProduct(name, attributeValues) {
|
||||
return this.createAttribute(name, attributeValues)
|
||||
.then(() => this.createTypeProduct(name, this.attribute.id))
|
||||
.then(() => this.createCategory(name));
|
||||
}
|
||||
createAttribute(name) {
|
||||
createAttribute(name, attributeValues) {
|
||||
return this.attributeRequest
|
||||
.createAttribute(name)
|
||||
.createAttribute(name, attributeValues)
|
||||
.then(
|
||||
resp => (this.attribute = resp.body.data.attributeCreate.attribute)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue