 _ = require 'underscore'
-debug = require('debug')('spec-integration:categoryOrderHints')
 _.mixin require('underscore-mixins')
 {Import, Export} = require '../../lib/main'
 Config = require '../../config'

  @importer.validator.suppressMissingHeaderWarning = true
  @client = @importer.client

  debug 'create a category to work with'
  @client.categories.save(newCategory())
  .then (results) =>
    @category = results.body
    debug "Created #{results.length} categories"

    @productType = TestHelpers.mockProductType()
    TestHelpers.setupProductType(@client, @productType)

    beforeEach prepareCategoryAndProduct

    afterEach (done) ->
      console.log 'About to delete all categories'
      @client.categories.process (payload) =>
        console.log "Deleting #{payload.body.count} categories"
        Promise.map payload.body.results, (category) =>
          @client.categories.byId(category.id).delete(category.version)
      .then (results) =>
        console.log "Deleted #{results.length} categories"
        console.log "Delete all the created products"
        @client.products.process (payload) =>
          console.log "Deleting #{payload.body.count} products"
          Promise.map payload.body.results, (product) =>
            @client.products.byId(product.id).delete(product.version)
      .then (results) ->
        console.log "Deleted #{results.length} products"
        done()
      .catch (error) -> done(_.prettify(error))
    , 60000 # 1min
