/*jslint node: true */
/* global -Promise */
"use strict";

var dualproto = require('../index');
var _ = require('lodash');
var assert = require('assert');
var EventEmitter = require('events').EventEmitter;
var Promise = require('bluebird');

describe('dualproto', function () {
    
    describe('Message', function () {

        it('should provide defaults for each dual-protocol parameter except body', function () {
            var ctxt = new dualproto.Message({});            
            assert.deepEqual(ctxt.to, []);
            assert.deepEqual(ctxt.from, []);
            assert(_.isObject(ctxt.options));
            assert(_.isUndefined(ctxt.body));
        });

        it('should consist of only dual message in toJSON', function () {
            var ctxt = new dualproto.Message({
                domain: { twenty: 'years'}
                , to: ['vice', 'president']
                , from: ['senate']
                , body: { maybe: 'house' }
                , options: { punching: 'bag' }
            });      
            var json = ctxt.toJSON();
            var jsonKeys = _.keys(json);
            assert.equal(4, jsonKeys.length);
            assert.deepEqual(json.to, ['vice', 'president']);
            assert.deepEqual(json.from, ['senate']);
            assert.equal(json.body.maybe, 'house');
            assert.equal(json.options.punching, 'bag');
        });

        describe('.parent', function (ctxt) {

            it('should return the route up to destination', function () {
                var ctxt = new dualproto.Message({
                    to: ['play', 'him', 'off']
                });
                assert.deepEqual(ctxt.parent(), ['play', 'him']);
            });

            it('should return the parent parent when given 2', function () {
                var ctxt = new dualproto.Message({
                    to: ['play', 'him', 'off']
                });
                assert.deepEqual(ctxt.parent(2), ['play']);
            });

            it('should throw exception when given parent depth greater than destination', function () {
                var ctxt = new dualproto.Message({
                    to: ['play', 'him', 'off']
                });
                assert.throws(function () {
                    ctxt.parent(4);
                });
            });

        });

    });

});

@@ -57,45 +57,8 @@
 %22;%0A%0A
-var dualproto = require('../index');%0A
 var 
@@ -116,70 +116,22 @@
 ');%0A
+%0A
 var 
-EventEmitter = require('events').EventEmitter;%0Avar Promise
+dualproto
  = r
@@ -142,16 +142,16 @@
 re('
-bluebird
+../index
 ');%0A

Clean up Message tests.