
assert = require 'assert'

window = global.window = global

{ABBrowserComm} = require '../src/appborg_browser'

comm = new ABBrowserComm

comm.on 'auto-response', (info) ->
  console.log 'on:foo'

comm.on 'manual-response-ok', (info, callback) ->
  callback null, {oh: 'hai'}

comm.on 'manual-response-err', (info, callback) ->
  callback {oh: 'noes'}


# req, auto-response
[e] = JSON.parse window.appborg.pushAndPullEvents([
  {method:"auto-response", id:"100", info:{}, from:"native", to:"js"}
])
assert.equal e.id, 100
assert.ok e.result

# req, manual-response-ok
[e] = JSON.parse window.appborg.pushAndPullEvents([
  {method:"manual-response-ok", id:"101", info:{}, from:"native", to:"js"}
])
assert.equal e.id, 101
assert.ok e.result
assert.equal e.result.oh, 'hai'

# req, manual-response-err
[e] = JSON.parse window.appborg.pushAndPullEvents([
  {method:"manual-response-err", id:"102", info:{}, from:"native", to:"js"}
])
assert.equal e.id, 102
assert.ok e.error
assert.equal e.error.oh, 'noes'


console.log 'OK'