          quantity: 1
       }]]
 
-    @sync.buildActions(orderNew, @order).update (error, response, body) =>
-      expect(response.statusCode).toBe 200
-      console.error body unless response.statusCode is 200
-      orderUpdated = body
-
-      orderNew2 = JSON.parse(JSON.stringify(orderUpdated))
-
+    @sync.buildActions(orderNew, @order).update()
+    .then (result) ->
+      expect(result.statusCode).toBe 200
+      orderUpdated = result.body
+
+      orderNew2 = _.deepClone orderUpdated
 
       # add a parcel item
       orderNew2.shippingInfo.deliveries[0].parcels = [{

      }]

    # prepare order: add returnInfo first
    @sync.buildActions(orderNew, @order).update (error, response, body) =>

      console.error body unless response.statusCode is 200
      orderUpdated = body
      orderNew2 = _.deepClone orderUpdated

      orderNew2.returnInfo[0].items[0].shipmentState = 'BackInStock'
      orderNew2.returnInfo[0].items[0].paymentState = 'Refunded'

      # update returnInfo status
      @sync.buildActions(orderNew2, orderUpdated).update (error, response, body) ->

        expect(response.statusCode).toBe 200
        console.error body unless response.statusCode is 200
        orderUpdated2 = body

        expect(orderUpdated2).toBeDefined()
        expect(orderUpdated2.returnInfo[0].items[0].shipmentState).toEqual orderNew2.returnInfo[0].items[0].shipmentState
        expect(orderUpdated2.returnInfo[0].items[0].paymentState).toEqual orderNew2.returnInfo[0].items[0].paymentState
        done()

  it 'should sync delivery items', (done) ->

    orderNew = JSON.parse(JSON.stringify(@order))

    # add one delivery item
    orderNew.shippingInfo.deliveries = [

_ = require 'underscore'
_.mixin require('sphere-node-utils')._u
Q = require 'q'
OrderSync = require '../../lib/sync/order-sync'
Config = require('../../config').config
