/**
 * Created by TalhaAkkas on 05/05/15.
 */
var MessageServer = require("..");
var assert = require("assert");
var sinon = require("sinon");
describe("It Should Pass", function (){
	it("It Should Pass", function () {
		assert(true);
	});
});

describe("It Should Send Message To Each Other", function (){
	var server1 = new MessageServer({},{},{ip:"127.0.0.1", host:"0.0.0.0", port:"3010"});//clusters, listener, host
	var server2 = new MessageServer({},{},{ip:"127.0.0.1", host:"0.0.0.0", port:"3011"});//clusters, listener, host

	var sock1 = new MockupSocket();
	var sock2 = new MockupSocket();

	sock1.pair = sock2;
	sock2.pair = sock1;
	it("It Should Send getInfo", function () {
		server1.onSocketConnected(sock1);
		server2.onSocketConnected(sock2);

		assert(JSON.stringify(sock1.writeCalls[0]) == JSON.stringify(sock2.writeCalls[0]));
		assert(sock1.writeCalls[0].type == "GetInfo");
	});
	it("", function(){

	})
});

function MockupSocket(){
	this.writeCalls = [];
	this.events = {};
	this.on = function(key, f){
		this.events[key] = f;
	};
	this.write = function(message){
		this.writeCalls.push(message);
		if(this.pair && this.pair.events["data"]){
			this.pair.events["data"].call(this.pair, message);
		}
	};
	this.setTimeout = function(){};
}