'use strict'

require('should')

const DummyTransport = require('chix-transport/dummy')
const ProcessManager = require('chix-flow/src/process/manager')
const RuntimeHandler = require('../lib/handler/runtime')
const pkg = require('../package')
const schemas = require('../schemas')

// TODO: this just loads the definitions from the live webserver.
// Doesn't matter that much I think..

describe('Runtime Handler:', () => {
  it('Should respond to getruntime', (done) => {

    const transport = new DummyTransport({
      // logger: console,
      bail: true,
      schemas: schemas
    })

    RuntimeHandler.handle(pm, transport /*, console*/)

    transport.capabilities = ['my-capabilities']

    transport.once('send', (data, conn) => {
      data.protocol.should.eql('runtime')
      data.command.should.eql('runtime')
      data.payload.version.should.eql(pkg.version)
      data.payload.capabilities.should.eql([
        'my-capabilities'
      ])

      conn.should.eql('test-connection')
      // assume the data from the server is ok

      done()
    })

    // trigger component action
    transport.receive({
      protocol: 'runtime',
      command: 'getruntime'
    }, 'test-connection')
  })
})
    const pm = new ProcessManager()