var Net = require('net');
describe('Socket', function () {


    // beforeEach(function(done) {
    // 
    // 
    // });
    it('require', function () {
        var Socket = require('../../lib/http/Socket.js').Socket;
        expect(Socket).toBeTruthy();
    });
    it('test write #1', function () {
        var Socket = require('../../lib/http/Socket.js').Socket;
        var ret = {writable: false, _drained: false,
            write: { push: jasmine.createSpy("socket data spy")}};
        spyOn(Net, 'createConnection').andReturn(ret);
        // Net.createConnection = jasmine.createSpy("socket spy");
        // Socket.prototype._socket = jasmine.createSpy("test");
        socket = new Socket("localhost", "80");
        socket._data['push'] = jasmine.createSpy("socket");
        socket.write("test", "UTF-8", function() {});
        expect(socket._data.push).toHaveBeenCalled();
    });
    it('test write #2', function () {
        var Socket = require('../../lib/http/Socket.js').Socket;
        var ret = {writable: true, drained: true, write: jasmine.createSpy("socket write spy").andReturn(true)};
        // var Net = require('net');
        spyOn(Net, 'createConnection').andReturn(ret);
        socket = new Socket("localhost", "80");
        socket.drained = true
        socket._write = jasmine.createSpy("socket");
        // socket = ret;
        socket.write("test", "UTF-8", function() {});
        expect(socket._write).toHaveBeenCalled();
    });
    it("bufferSize", function () {
        var Socket = require('../../lib/http/Socket.js').Socket;
        var ret = {writable: true, drained: true, _write: jasmine.createSpy("socket write spy"),
            bufferSize: 10
        };
        // var Net = require('net');
        spyOn(Net, 'createConnection').andReturn(ret);
        socket = new Socket("localhost", "80");
        expect(socket.bufferSize()).toEqual(10);
    });
    it("destroy", function () {
        var Socket = require('../../lib/http/Socket.js').Socket;
        var ret = {writable: true, drained: true, destroy: jasmine.createSpy("destroy"),
        };
        // var Net = require('net');
        spyOn(Net, 'createConnection').andReturn(ret);
        socket = new Socket("localhost", "80");
        socket.destroy();
        expect(socket._socket.destroy).toHaveBeenCalled();
    
    });
});

