var pokerConnection = require('../../lib/poker-connection');

describe('poker-connection', function() {
    it('should be initialized', function() {
        var currentUsers = [1,2,3];
        var carddisplay = [8,13,20];
        var connectionHandler = pokerConnection.getNewHandler();

        connectionHandler.init(currentUsers, carddisplay);

        expect(connectionHandler.pokerData).toEqual({
            "users": currentUsers,
            "carddisplay": carddisplay
        });
    });

    it('should set a connection', function() {
        var connectionMock = {
            on: function(type, callback) {}
        };
        spyOn(connectionMock, 'on');

        var connectionHandler = pokerConnection.getNewHandler();
        connectionHandler.init(null, null);
        connectionHandler.setConnection(connectionMock);

        expect(connectionMock.on).toHaveBeenCalledWith('message', jasmine.any(Function));
        expect(connectionMock.on).toHaveBeenCalledWith('close', jasmine.any(Function));
    });
});
@@ -1013,12 +1013,656 @@
 %0A    %7D);
+%0A%0A    it('should remove all connection listeners when connection is closed', function() %7B%0A        var connectionMock = %7B%0A            on: function() %7B%7D,%0A            removeAllListeners: function() %7B%7D%0A        %7D;%0A        spyOn(connectionMock, 'removeAllListeners');%0A%0A        var connectionHandler = pokerConnection.getNewHandler();%0A        connectionHandler.init(null, null);%0A        connectionHandler.setConnection(connectionMock);%0A%0A        connectionHandler.onclose();%0A        expect(connectionMock.removeAllListeners).toHaveBeenCalled();%0A    %7D);%0A%0A    it('should remove the user and all listeners when connection is closed', function() %7B%0A%0A    %7D);
 %0A%7D);

test the removal of all listeners