Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/fixtures / src / factory / index.ts
Size: Mime:
// to have different data, but consistently gone through in the same order for the  same test output :-)
let index = 0
let count = 0

/**
 * @todo swap with sirv
 */
const images = [
  '//static1.businessinsider.com/image/5581bc1669bedd830253bd29-557-417/nest-app-1.jpg',
  '//static1.businessinsider.com/image/5581bc1669bedd830253bd29-557-417/nest-app-2.jpg',
  '//d16rliti0tklvn.cloudfront.net/2495/1499403546737.701080742.jpeg',
  '//d16rliti0tklvn.cloudfront.net/2495/1501238804695.468409933.jpeg',
  '//d16rliti0tklvn.cloudfront.net/2747/1508362193564.1043728759.png',
]
const imageTexts = [
  'Alt Image 1',
  'Alt Image 2',
  'Textuals',
  'Cloud',
]
const names = [
  'Nest app',
  'Google Blue Shoe',
  'Premium Hot Coco',
  'Eh',
  'Canada',
  'Moose',
  '//www.gourmetint.com/image/cache/catalog/475700_lo-400x400.jpg',
]
const videos = [
  '//www.youtube.com/watch?v=hss6Shpe1YU',
]
const CATEGORY_IDS = [
  { label: 'altice', value: 'Altice' },
  { label: '1476183098424-R', value: 'More' },
  { label: 'parent category', value: 'altice' },
]
const descriptionList = [
  'Know what?s happening at home from anywhere.',
]
const skuFlagPresets = {
  ghosted: { label: 'ghost', value: 'true' },
  variablePriced: { label: 'isvariablepriced', value: 'false' },
  // bundle:
  // collection:
  //
}

const skuFlagList = Object.values(skuFlagPresets)
const skuFlagPresetNames = Object.keys(skuFlagPresets)

// =========

export const makeCategoryIds = () => {
  return [...CATEGORY_IDS]
}

export const makeSkuFlags = () => {
  return [skuFlagPresets.variablePriced]
}
export const EMPTY_DESCRIPTION = [
  {
    label: 'Description',
  },
]
export const makeDescription = () => {
  return [
    {
      label: 'Description',
      value: descriptionList[index],
    },
  ]
}

export const makeLabelValueImage = () => {
  return {
    label: imageTexts[index],
    value: images[index],
  }
}
export const makeVideo = () => {
  return { label: 'video', value: videos[index] }
}
export const makeVideoList = () => {
  return [
    makeVideo(),
  ]
}
export const makeImageList = () => {
  return [
    makeLabelValueImage(),
  ]
}


export const makeItemInfoComplex = () => {
  return {
    categoryids: makeCategoryIds(),
    flags: makeSkuFlags(),
    description: makeDescription(),
    additionalimages: [
      makeLabelValueImage(),
    ],
    isgroupproduct: 'false',
  }
}
export const makeItemInfo = () => {
  const itemInfo = {
    flags: makeSkuFlags(),
    description: makeDescription(),
    additionalimages: [
      makeLabelValueImage(),
    ],
    additionalinfo: [{ label: 'skuflag', value: 'preorder' }],
  }
  return itemInfo
}

const salePrices = ['4.99', '250', '[]']
const regPrices = ['7.99', '400']
const prices = [{ label: 'sale', type: 'Sale', value: '[]' }]
const currencycodeList = ['$']

export const makePricing = () => {
  const salePrice = prices[0]
  const currencycode = currencycodeList[0]
  return {
    pricing: {
      currencycode,
      prices: [salePrice],
    },
  }
}
export const makeComplexBuyInfo = () => {
  return {
    inventorystatus: 'IN STOCK',
    preorder: 'FALSE',
  }
}
export const makeBuyInfo = () => {
  const buyInfo = {
    inventorystatus: 'IN STOCK',
    pricing: makePricing(),
  }
  return buyInfo
}

export const makeSingleSku = () => {
  const skuProperties = {
    buyinfo: makeBuyInfo(),
    iteminfo: makeItemInfo(),
    state: { starttime: '1509970700984' },
  }

  const SingleSku = {
    image:
      '//static1.businessinsider.com/image/5581bc1669bedd830253bd29-557-417/nest-app-1.jpg',
    identifier: 'smoraltnestsecapp1',
    navtype: 'identifier',
    name: 'Nest app',
    type: 'product',
    properties: skuProperties,
  }

  return SingleSku
}
export const makeAdditionalInfoBundle = () => {
  return [
    { label: 'bundleMandatoryProducts', value: '0' },
    { label: 'subProducts', value: '0' },
    { label: 'bundleOptionalProducts', value: '0' },
  ]
}

export const makeProductState = () => {
  return {
    starttime: '1509969991129',
    additionalinfo: makeAdditionalInfoBundle(),
  }
}
export const makeProductProperties = () => {
  const properties = {
    buyinfo: makeBuyInfo(),
    iteminfo: makeItemInfoComplex(),
    state: makeProductState(),
  }
  return properties
}

// improve a lot ! @todo
export const makeChildren = () => {
  return {
    skus: [
      makeSingleSku(),
    ],
  }
}


export const makeProductCommon = () => {
  index += 1
  // always keep incrementing this one - unique per time we call this
  count += 1

  // start again :-)
  if (index > images.length) {
    index = 0
  }

  const image = images[index]
  const name = names[index]

  return {
    name,
    image,
    identifier: 'identifier-' + index + count,
    properties: makeProductProperties(),
    // properties
  }
}

export const simpleProduct = {
  image:
    '//static1.businessinsider.com/image/5581bc1669bedd830253bd29-557-417/nest-app-1.jpg',
  identifier: 'moraltnestsecapp',
  children: {
    skus: [
      makeSingleSku(),
    ],
  },
  name: 'Nest app',
  type: 'product',
  properties: makeProductProperties(),
}