GitHub

MockMagentoConfigurableProduct

Mock

import { MockMagentoConfigurableProduct } from '@daffodil/product-configurable/driver/magento/testing'

class MockMagentoConfigurableProduct extends MockMagentoCoreProduct implements MagentoConfigurableProduct {
  __typename: MagentoProductTypeEnum = MagentoProductTypeEnum.ConfigurableProduct
  configurable_options: { attribute_code: string; label: string; position: number; values: { label: string; value_index: number; }[]; }[] = [
      {
        attribute_code: 'color',
        label: 'Color',
        position: 0,
        values: [
          {
            label: 'Blue',
            value_index: 0,
          },
          {
            label: 'Yellow',
            value_index: 1,
          },
          {
            label: 'Red',
            value_index: 2,
          },
        ],
      },
    ]
  variants: ({ attributes: { code: string; value_index: number; }[]; product: { __typename: MagentoProductTypeEnum; uid: any; url_key: any; url_suffix: string; name: any; sku: any; stock_status: MagentoProductStockStatusEnum; image: { ...; }; thumbnail: { ...; }; price_range: { ...; }; }; } | { ...; })[] = [
      {
        attributes: [
          {
            code: 'color',
            value_index: 0,
          },
        ],
        product: {
          __typename: MagentoProductTypeEnum.SimpleProduct,
          uid: faker.string.uuid(),
          url_key: faker.string.alphanumeric(16),
          url_suffix: '.html',
          name: faker.lorem.word(),
          sku: faker.string.alphanumeric(16),
          stock_status: MagentoProductStockStatusEnum.InStock,
          image: {
            __typename: 'ProductImage',
            label: faker.lorem.words(3),
            url: faker.image.url(),
          },
          thumbnail: {
            __typename: 'ProductImage',
            label: faker.lorem.words(3),
            url: faker.image.url(),
          },
          price_range: {
            __typename: 'PriceRange',
            maximum_price: {
              __typename: 'ProductPrice',
              regular_price: {
                __typename: 'Money',
                value: this.priceVariant1,
                currency: null,
              },
              discount: {
                __typename: 'ProductDiscount',
                amount_off: this.discountVariant1,
                percent_off: this.discountVariant1/this.priceVariant1,
              },
            },
          },
        },
      },
      {
        attributes: [
          {
            code: 'color',
            value_index: 1,
          },
        ],
        product: {
          __typename: MagentoProductTypeEnum.SimpleProduct,
          uid: faker.string.uuid(),
          url_key: faker.string.alphanumeric(16),
          url_suffix: '.html',
          name: faker.lorem.word(),
          sku: faker.string.alphanumeric(16),
          stock_status: MagentoProductStockStatusEnum.InStock,
          image: {
            __typename: 'ProductImage',
            label: faker.lorem.words(3),
            url: faker.image.url(),
          },
          thumbnail: {
            __typename: 'ProductImage',
            label: faker.lorem.words(3),
            url: faker.image.url(),
          },
          price_range: {
            __typename: 'PriceRange',
            maximum_price: {
              __typename: 'ProductPrice',
              regular_price: {
                __typename: 'Money',
                value: this.priceVariant2,
                currency: null,
              },
              discount: {
                amount_off: this.discountVariant2,
                percent_off: this.discountVariant2/this.priceVariant2,
              },
            },
          },
        },
      },
      {
        attributes: [
          {
            code: 'color',
            value_index: 2,
          },
        ],
        product: {
          __typename: MagentoProductTypeEnum.SimpleProduct,
          uid: faker.string.uuid(),
          url_key: faker.string.alphanumeric(16),
          url_suffix: '.html',
          name: faker.lorem.word(),
          sku: faker.string.alphanumeric(16),
          stock_status: MagentoProductStockStatusEnum.InStock,
          image: {
            __typename: 'ProductImage',
            label: faker.lorem.words(3),
            url: faker.image.url(),
          },
          thumbnail: {
            __typename: 'ProductImage',
            label: faker.lorem.words(3),
            url: faker.image.url(),
          },
          price_range: {
            __typename: 'PriceRange',
            maximum_price: {
              __typename: 'ProductPrice',
              regular_price: {
                __typename: 'Money',
                value: this.priceVariant3,
                currency: null,
              },
              discount: {
                amount_off: this.discountVariant3,
                percent_off: this.discountVariant3/this.priceVariant3,
              },
            },
          },
        },
      },
    ]
  canonical_url: faker.internet.url() = faker.internet.url()
  meta_title: faker.lorem.word() = faker.lorem.word()
  meta_description: faker.lorem.words(3) = faker.lorem.words(3)
  stock_status: MagentoProductStockStatusEnum = MagentoProductStockStatusEnum.InStock
  description: { __typename: string; html: any; } = {
      __typename: 'ComplexTextValue',
      html: faker.lorem.words(5),
    }
  short_description: { __typename: string; html: any; } = {
      __typename: 'ComplexTextValue',
      html: faker.lorem.words(3),
    }
  media_gallery_entries: any[] = []
  uid: faker.string.uuid() = faker.string.uuid()
  url_key: faker.string.alphanumeric(16) = faker.string.alphanumeric(16)
  url_suffix: string = '.html'
  name: faker.lorem.word() = faker.lorem.word()
  sku: faker.string.alphanumeric(16) = faker.string.alphanumeric(16)
  image: { __typename: string; label: any; url: any; } = {
      __typename: 'ProductImage',
      label: faker.lorem.words(3),
      url: faker.image.url(),
    }
  price_range: { __typename: string; maximum_price: { __typename: string; regular_price: { __typename: string; value: any; currency: any; }; discount: { __typename: string; amount_off: any; percent_off: any; }; }; } = {
      __typename: 'PriceRange',
      maximum_price: {
        __typename: 'ProductPrice',
        regular_price: {
          __typename: 'Money',
          value: faker.number.int({ min: 100, max: 1000 }),
          currency: null,
        },
        discount: {
          __typename: 'ProductDiscount',
          amount_off: faker.number.int({ min: 1, max: 99 }),
          percent_off: faker.number.int({ min: 1, max: 99 }),
        },
      },
    }
}