GitHub

MockConfigurableProduct

Mock

import { MockConfigurableProduct } from '@daffodil/product-configurable/testing'

Mocked DaffConfigurableProduct object.

class MockConfigurableProduct extends MockProduct implements DaffConfigurableProduct {
  type: DaffProductTypeEnum = DaffProductTypeEnum.Configurable
  configurableAttributes: { code: string; label: string; order: number; values: { value: string; label: string; swatch: { value: string; thumbnail: any; }; }[]; }[] = [
      {
        code: 'color',
        label: 'Color',
        order: 0,
        values: [
          {
            value: '0',
            label: 'Blue',
            swatch: {
              value: '#0000FF',
              thumbnail: null,
            },
          },
          {
            value: '1',
            label: 'Yellow',
            swatch: {
              value: '#FFFF00',
              thumbnail: null,
            },
          },
          {
            value: '2',
            label: 'Red',
            swatch: {
              value: '#FF0000',
              thumbnail: null,
            },
          },
        ],
      },
      {
        code: 'size',
        label: 'Size',
        order: 1,
        values: [
          {
            value: '0',
            label: 'Small',
            swatch: null,
          },
          {
            value: '1',
            label: 'Medium',
            swatch: null,
          },
          {
            value: '2',
            label: 'Large',
            swatch: null,
          },
        ],
      },
      {
        code: 'material',
        label: 'Material',
        order: 2,
        values: [
          {
            value: '0',
            label: 'Cotton',
            swatch: null,
          },
          {
            value: '1',
            label: 'Polyester',
            swatch: null,
          },
          {
            value: '2',
            label: 'Spandex',
            swatch: null,
          },
        ],
      },
    ]
  variants: { appliedAttributes: { color: string; size: string; material: string; }; price: any; discount: { amount: any; percent: number; }; id: any; in_stock: boolean; }[] = [
      {
        appliedAttributes: {
          color: '0',
          size: '0',
          material: '0',
        },
        price: this.stubPriceVariant1,
        discount: {
          amount: this.stubDiscountVariant1,
          percent: Math.floor((this.stubDiscountVariant1/this.stubPriceVariant1) * 100),
        },
        id: faker.string.uuid(),
        in_stock: true,
      },
      {
        appliedAttributes: {
          color: '0',
          size: '1',
          material: '0',
        },
        price: this.stubPriceVariant1,
        discount: {
          amount: this.stubDiscountVariant1,
          percent: Math.floor((this.stubDiscountVariant1/this.stubPriceVariant1) * 100),
        },
        id: faker.string.uuid(),
        in_stock: true,
      },
      {
        appliedAttributes: {
          color: '0',
          size: '1',
          material: '2',
        },
        price: this.stubPriceVariant3,
        discount: {
          amount: this.stubDiscountVariant3,
          percent: Math.floor((this.stubDiscountVariant3/this.stubPriceVariant3) * 100),
        },
        id: faker.string.uuid(),
        in_stock: true,
      },
      {
        appliedAttributes: {
          color: '0',
          size: '2',
          material: '0',
        },
        price: this.stubPriceVariant1,
        discount: {
          amount: this.stubDiscountVariant1,
          percent: Math.floor((this.stubDiscountVariant1/this.stubPriceVariant1) * 100),
        },
        id: faker.string.uuid(),
        in_stock: true,
      },
      {
        appliedAttributes: {
          color: '1',
          size: '0',
          material: '0',
        },
        price: this.stubPriceVariant1,
        discount: {
          amount: this.stubDiscountVariant1,
          percent: Math.floor((this.stubDiscountVariant1/this.stubPriceVariant1) * 100),
        },
        id: faker.string.uuid(),
        in_stock: true,
      },
      {
        appliedAttributes: {
          color: '1',
          size: '0',
          material: '2',
        },
        price: this.stubPriceVariant3,
        discount: {
          amount: this.stubDiscountVariant3,
          percent: Math.floor((this.stubDiscountVariant3/this.stubPriceVariant3) * 100),
        },
        id: faker.string.uuid(),
        in_stock: true,
      },
      {
        appliedAttributes: {
          color: '1',
          size: '2',
          material: '0',
        },
        price: this.stubPriceVariant1,
        discount: {
          amount: this.stubDiscountVariant1,
          percent: Math.floor((this.stubDiscountVariant1/this.stubPriceVariant1) * 100),
        },
        id: faker.string.uuid(),
        in_stock: true,
      },
      {
        appliedAttributes: {
          color: '1',
          size: '2',
          material: '1',
        },
        price: this.stubPriceVariant2,
        discount: {
          amount: this.stubDiscountVariant2,
          percent: Math.floor((this.stubDiscountVariant2/this.stubPriceVariant2) * 100),
        },
        id: faker.string.uuid(),
        in_stock: true,
      },
      {
        appliedAttributes: {
          color: '2',
          size: '0',
          material: '0',
        },
        price: this.stubPriceVariant3,
        discount: {
          amount: this.stubDiscountVariant3,
          percent: Math.floor((this.stubDiscountVariant3/this.stubPriceVariant3) * 100),
        },
        id: faker.string.uuid(),
        in_stock: true,
      },
      {
        appliedAttributes: {
          color: '2',
          size: '2',
          material: '0',
        },
        price: this.stubPriceVariant1,
        discount: {
          amount: this.stubDiscountVariant1,
          percent: Math.floor((this.stubDiscountVariant1/this.stubPriceVariant1) * 100),
        },
        id: faker.string.uuid(),
        in_stock: true,
      },
    ]
  id: faker.string.uuid() = faker.string.uuid()
  url: string = `/${faker.internet.domainWord()}.html`
  canonicalUrl: faker.internet.url() = faker.internet.url()
  price: this.stubPrice = this.stubPrice
  in_stock: boolean = true
  discount: { amount: any; percent: number; } = {
      amount: this.stubDiscount,
      percent: Math.floor((this.stubDiscount/this.stubPrice) * 100),
    }
  images: DaffProductImage[] = this.imageFactory.createMany(faker.number.int({ min: 1, max: 10 }))
  thumbnail: DaffProductImage = this.imageFactory.create()
  name: faker.commerce.productName() = faker.commerce.productName()
  brand: faker.company.name() = faker.company.name()
  description: faker.commerce.productDescription() = faker.commerce.productDescription()
  short_description: faker.commerce.productDescription() = faker.commerce.productDescription()
  meta_title: faker.commerce.productName() = faker.commerce.productName()
  meta_description: faker.commerce.productDescription() = faker.commerce.productDescription()
}