GitHub

DaffMockStatefulConfigurableCartItem

Mock

import { DaffMockStatefulConfigurableCartItem } from '@daffodil/cart/state/testing'

class DaffMockStatefulConfigurableCartItem extends DaffMockConfigurableCartItem implements DaffOperationEntity<DaffConfigurableCartItem> {
  daffState: DaffState = DaffState.Stable
  daffErrors: any[] = []
  daffTemp: boolean = false
  type: DaffCartItemInputType = DaffCartItemInputType.Configurable
  attributes: { attribute_label: string; value_label: string; }[] = [
      {
        attribute_label: 'Color',
        value_label: 'Red',
      },
      {
        attribute_label: 'Size',
        value_label: 'M',
      },
    ]
  id: faker.string.uuid() = faker.string.uuid()
  product_id: faker.string.uuid() = faker.string.uuid()
  parent_item_id: faker.string.uuid() = faker.string.uuid()
  image: DaffProductImage = <DaffProductImage>new DaffProductImageFactory().create()
  sku: string = 'sku'
  name: string = 'Product Name'
  url: string = `/${faker.internet.domainWord()}.html`
  qty: faker.number.int({ min: 1, max: 100 }) = faker.number.int({ min: 1, max: 100 })
  price: faker.number.int({ min: 10, max: 1500 }) = faker.number.int({ min: 10, max: 1500 })
  row_total: number = this.qty * this.price
  in_stock: boolean = true
  _numberOfDiscounts: faker.number.int({ min: 1, max: 2 }) = faker.number.int({ min: 1, max: 2 })
  discounts: DaffCartItemDiscount[] = this._discounts(this._numberOfDiscounts, Math.floor(this.price / this._numberOfDiscounts))
}