       shippingMethod:
         typeId: 'shipping-method'
         id: shippingMethod.id
-
-createResourcePromise = (rest, url, body) ->
-  deferred = Q.defer()
-  rest.POST url, JSON.stringify(body), (error, response, body) ->
-    if response.statusCode is 201
-      deferred.resolve body
-    else if error
-      deferred.reject new Error(error)
-    else
-      deferred.reject new Error(body)
-  deferred.promise
-
-deleteResourcePromise = (rest, url) ->
-  deferred = Q.defer()
-  rest.DELETE url, (error, response, body) ->
-    if response.statusCode is 200
-      deferred.resolve body
-    else if error
-      deferred.reject new Error(error)
-    else
-      deferred.reject new Error(body)
-  deferred.promise

      }]

    # 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 = [

    orderNew.paymentState = 'Paid'
    orderNew.shipmentState = 'Ready'

    @sync.buildActions(orderNew, @order).update()
    .then (result) ->
      expect(result.statusCode).toBe 200
      orderUpdated = result.body
      expect(orderUpdated).toBeDefined()
      expect(orderUpdated.orderState).toBe orderNew.orderState
      expect(orderUpdated.paymentState).toBe orderNew.paymentState
      expect(orderUpdated.shipmentState).toBe orderNew.shipmentState
      done()
    .fail (error) -> done(error)

  it 'should sync returnInfo', (done) ->
    orderNew = _.deepClone @order
