     key = uniqueId "channel"
     @client.channels.ensure(key, ROLE_ORDER_EXPORT)
     .then (result) ->
-      channels.push result.body
       expect(result.body).toBeDefined()
       expect(result.body.key).toEqual key
       expect(result.body.roles).toEqual [ROLE_ORDER_EXPORT]

    .fail (error) -> done _.prettify(error)

  it 'should fetch an existing channel, add given role and return it', (done) ->

    @client.channels.ensure(@channel.key, ROLE_ORDER_EXPORT)
    .then (result) =>
      @client.channels.ensure(@channel.key, ROLE_PRIMARY)
      .then (result) ->
      expect(result.body.roles).toEqual [ROLE_INVENTORY_SUPPLY, ROLE_ORDER_EXPORT]
      done()
    .fail (error) -> done _.prettify(error)
  , 10000 # 10sec

  it 'should fetch an existing channel and return it', (done) ->

    @client.channels.byId(@channel.id).update(updateChannel(@channel.version))
    .then (result) =>
      @channel = result.body
      @client.channels.ensure(@channel.key, ROLE_ORDER_EXPORT)
    .then (result) =>
      expect(result.body).toBeDefined()
      expect(result.body.id).toEqual @channel.id
      expect(result.body.roles).toEqual @channel.roles
      done()
    .fail (error) -> done _.prettify(error)
  , 10000 # 10sec

  it 'should fail if role value is not supported', (done) ->
    @client.channels.ensure(@channel.key, 'undefined-role')
    .then (result) ->
      done 'Role value not supported.'
    .fail (error) ->

    @client.channels.save(newChannel())
    .then (result) =>
      expect(result.statusCode).toBe 201
      @channelId = result.body.id
      @logger.info @channel, "New channel created: #{@channelId}"
      done()
    .fail (error) -> done _.prettify(error)

  afterEach (done) ->
    @client.channels.byId(@channelId).fetch()
    .then (result) =>
      @client.channels.byId(@channelId).delete(result.body.version)
    .then (result) =>
      @logger.info "Channel deleted: #{@channelId}"
      expect(result.statusCode).toBe 200
      done()
    .fail (error) -> done _.prettify(error)

  it 'should update a channel', (done) ->
    @client.channels.byId(@channelId).fetch()
    .then (result) =>
      @client.channels.byId(@channelId).update(updateChannel(result.body.version))
    .then (result) ->
      expect(result.statusCode).toBe 200
      expect(result.body.name).toEqual {en: 'A Channel'}
      expect(result.body.description).toEqual {en: 'This is a Channel'}
      expect(result.body.roles).toEqual [ROLE_INVENTORY_SUPPLY, ROLE_ORDER_EXPORT]
      done()
    .fail (error) -> done _.prettify(error)

