           prices: []
         ],
         version: 1
+
+      @import._cache.productType[sampleProductTypeResponse.body.results[0].id] = sampleProductTypeResponse.body.results[0]
 
       spyOn(@import, "_prepareNewProduct").andCallFake (prepareProduct) -> Promise.resolve(prepareProduct)
       spyOn(@import, "_prepareUpdateProduct").andCallFake (prepareProduct) -> Promise.resolve(prepareProduct)


  beforeEach ->

    errorDir = path.join(__dirname, '../errors')

    Config =
      clientConfig: ClientConfig
      errorDir: errorDir
      errorLimit: 0
      blackList: ['prices']

    @import = new ProductImport null, Config

  it 'should initialize', ->
    expect(@import).toBeDefined()

      .catch (err) ->
        done(err)

  describe 'update product type', ->

    it ' :: should do nothing for empty update actions', (done) ->
      @import._updateProductType([])
      .then =>
        expect(@import._summary.productTypeUpdated).toBe 0
        done()
      .catch (err) ->
        done(err)

    it ' :: should update product type correctly', (done) ->
      sampleProductType = _.deepClone sampleProductTypeResponse.body.results[0]
      sampleEnumAttribute =
        name: 'sample-enum-attribute'
        label:
          en: 'Sample Enum Attribute'
        type:
          name: 'enum'
          values: [
            key: 'enum-1-key'
            label: 'enum-1-label'
          ,
            key: 'enum-2-key'
            label: 'enum-2-label'
          ]

      sampleProductType.attributes.push sampleEnumAttribute

      sampleUpdateAction =
        action: 'addPlainEnumValue'
        attributeName: 'sample-enum-attribute'
        value:
          key: 'enum-3-key'
          label: 'enum-3-key'

      sampleInput =
        product_type_internal_id: [
          sampleUpdateAction
        ]

      expectedPayload =
        version: sampleProductType.version
        actions: [
          sampleUpdateAction
        ]

      sampleUpdatedProductType = _.deepClone sampleProductType

      sampleUpdatedProductType.version++
      sampleUpdatedProductType.attributes[0].type.values.push sampleUpdateAction.value

      @import._cache.productType[sampleProductType.id] = sampleProductType
      spyOn(@import.client._rest, 'POST').andCallFake (endpoint, payload, callback) ->
        callback(null, {statusCode: 200}, sampleUpdatedProductType)
      @import._updateProductType(sampleInput)
      .then =>
        updatedProductType = @import._cache.productType[sampleProductType.id]
        expect(updatedProductType.version).toBe 2
        expect(updatedProductType.attributes[0].type.values[2]).toEqual(sampleUpdateAction.value)
        expect(@import._summary.productTypeUpdated).toBe 1
        expect(@import.client._rest.POST.calls[0].args[1]).toEqual expectedPayload
        done()
      .catch (err) ->
        done(err)





