<commit_before>import Room from 'aircheck/models/room';

var rtc = window.rtc;
var room, openDataChannel, closedDataChannel;
module("Unit - Model - Room", {
    setup: function() {
        room = new Room({
            name: 'room name',
            user: {
                nick: 'user nick',
                videoSrc: 'videoSrc',
                stream: 'stream'
            }
        });
        openDataChannel = {
            readyState: 'open',
            send: sinon.spy()
        };
        closedDataChannel = {
            readyState: 'connecting',
            send: sinon.spy()
        };
        rtc.dataChannels['open'] = openDataChannel;
        rtc.dataChannels['closed'] = closedDataChannel;

    },
    teardown: function() {
        rtc.dataChannels['open'] = null;
        rtc.dataChannels['closed'] = null;
        rtc._events = {};
    }
});

test('Room#send', 2, function() {
    room.send('foo');
    equal(room.messages.length, 1);
    var arg = openDataChannel.send.getCall(0).args[0];

    ok(/foo/.test(arg), 'should send foo in the message');
});

test('Room#setNick', 2, function() {
    room.setNick('new nick');
    equal(room.messages.length, 1);
    var arg = openDataChannel.send.getCall(0).args[0];

    equal(':user_nick@room_name NICK new_nick', arg);
});

test('Room#_sendIrcMsg', 2, function() {
    var ircMsg = {
        prefix: {
            nick: 'nick',
            server: 'server',
            user: 'user'
        },
        command: 'asdf',
        parameters: []
    };
    room._sendIrcMsg(ircMsg);
    ok(openDataChannel.send.called, 'should call send on all open data channels');
    equal(closedDataChannel.send.called, false, 'should not call send on all not open data channels');
});

test('Room#_sendIrcMsg w socketId arg', 1, function() {
    var ircMsg = {
        prefix: {<commit_msg>fix tests when node web.js is running<commit_after>import Room from 'aircheck/models/room';

var rtc = window.rtc;
var room, openDataChannel, closedDataChannel;
module("Unit - Model - Room", {
    setup: function() {
        room = new Room({
            name: 'room name',
            user: {
                nick: 'user nick',
                videoSrc: 'videoSrc',
                stream: 'stream'
            }
        });
        openDataChannel = {
            readyState: 'open',
            send: sinon.spy()
        };
        closedDataChannel = {
            readyState: 'connecting',
            send: sinon.spy()
        };
        rtc.dataChannels['open'] = openDataChannel;
        rtc.dataChannels['closed'] = closedDataChannel;

    },
    teardown: function() {
        rtc.dataChannels['open'] = null;
        rtc.dataChannels['closed'] = null;
        rtc._events = {};
    }
});

test('Room#send', 2, function() {
    room.send('foo');
    equal(room.messages.length, 1);
    var arg = openDataChannel.send.getCall(0).args[0];

    ok(/foo/.test(arg), 'should send foo in the message');
});

test('Room#setNick', 2, function() {
    room.setNick('new nick');
    equal(room.messages.length, 1);
    var arg = openDataChannel.send.getCall(0).args[0];
    console.log(arg);
    //:user_nick@room_name NICK new_nick
    // or
    //:user_nick asdfe-asdfda-asdfasd-32f32f@room_name NICK new_nick
    ok(/:user_nick[^@]*@room_name NICK new_nick/.test(arg));
});

test('Room#_sendIrcMsg', 2, function() {
    var ircMsg = {
        prefix: {
            nick: 'nick',
            server: 'server',
            user: 'user'
        },
        command: 'asdf',
        parameters: []
    };
    room._sendIrcMsg(ircMsg);
    ok(openDataChannel.send.called, 'should call send on all open data channels');
    equal(closedDataChannel.send.called, false, 'should not call send on all not open data channels');
});

test('Room#_sendIrcMsg w socketId arg', 1, function() {
    var ircMsg = {
        prefix: {
{'fraction_non_alphanumeric': 0.14792746113989638, 'fraction_numerical': 0.0062176165803108805, 'mean_word_length': 2.220183486238532, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '887149', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1198, 'n_words': 268}