<commit_before>'use strict';

var should = require('should')
  , Avatar = require('../../index')
  , ltx    = require('ltx')
  , helper = require('../helper')

/* jshint -W030 */
describe('Avatar', function() {

    var avatar, socket, xmpp, manager

    before(function() {
        socket = new helper.SocketEventer()
        xmpp = new helper.XmppEventer()
        manager = {
            socket: socket,
            client: xmpp,
            trackId: function(id, callback) {
                if (typeof id !== 'object')
                    throw new Error('Stanza ID spoofing protection not implemented')
                this.callback = callback
            },
            makeCallback: function(error, data) {
                this.callback(error, data)
            },
            getJidType: function(type) {
                if ('bare' === type)
                    return '<EMAIL>'
                throw new Error('Unknown JID type')
            }
        }
        avatar = new Avatar()
        avatar.init(manager)
    })

    beforeEach(function() {
        socket.removeAllListeners()
        xmpp.removeAllListeners()
        avatar.init(manager)
    })

    describe('Handles', function() {

        it('Returns false for non-message stanzas', function() {
            avatar.handles(ltx.parse('<iq/>')).should.be.false
        })

        it('Returns true for correct stanza', function() {
            var stanza = '<message>' +
                '<event xmlns="' + avatar.NS_EVENT + '">' +
                '<items xmlns="' + avatar.NS_META + '">' +
                '<item>' +
                '<metadata xmlns="' + avatar.NS_META + '" />' +
                '</item>' +
                '</items>' +
                '</event>' +
                '</message>'
            avatar.handles(ltx.parse(stanza)).should.be.true
        })

    })

    describe('Handles incoming messages', function() {

        it('Handles requests to disable avatars', function(done) {
            socket.once('xmpp.avatar.push.metadata', function(data) {
                data.from.should.eql({
                    domain: 'shakespeare.lit',
                    user: 'romeo'
                })
                data.disabled.should.be.true
                done()
            })
            var stanza = '<message from="<EMAIL>">' +
                '<event xmlns="' + avatar.NS_EVENT + '">' +
                '<items xmlns="' + avatar.NS_META + '">' +
                '<item>' +
                '<metadata xmlns="' + avatar.NS_META + '" />' +
                '</item>' +
                '</items>' +
                '</event>' +
                '</message>'
            avatar.handle(ltx.parse(stanza))
        })

        it('Handles full metadata update', function(done) {
            socket.once('xmpp.avatar.push.metadata', function(data) {
                data.from.should.eql({
                    domain: 'shakespeare.lit',
                    user: 'romeo'<commit_msg>Add test to increase coverage<commit_after>'use strict';

var should = require('should')
  , Avatar = require('../../index')
  , ltx    = require('ltx')
  , helper = require('../helper')

/* jshint -W030 */
describe('Avatar', function() {

    var avatar, socket, xmpp, manager

    before(function() {
        socket = new helper.SocketEventer()
        xmpp = new helper.XmppEventer()
        manager = {
            socket: socket,
            client: xmpp,
            trackId: function(id, callback) {
                if (typeof id !== 'object')
                    throw new Error('Stanza ID spoofing protection not implemented')
                this.callback = callback
            },
            makeCallback: function(error, data) {
                this.callback(error, data)
            },
            getJidType: function(type) {
                if ('bare' === type)
                    return '<EMAIL>'
                throw new Error('Unknown JID type')
            }
        }
        avatar = new Avatar()
        avatar.init(manager)
    })

    beforeEach(function() {
        socket.removeAllListeners()
        xmpp.removeAllListeners()
        avatar.init(manager)
    })

    describe('Handles', function() {

        it('Returns false for non-message stanzas', function() {
            avatar.handles(ltx.parse('<iq/>')).should.be.false
        })

        it('Returns true for correct stanza', function() {
            var stanza = '<message>' +
                '<event xmlns="' + avatar.NS_EVENT + '">' +
                '<items xmlns="' + avatar.NS_META + '">' +
                '<item>' +
                '<metadata xmlns="' + avatar.NS_META + '" />' +
                '</item>' +
                '</items>' +
                '</event>' +
                '</message>'
            avatar.handles(ltx.parse(stanza)).should.be.true
        })

    })

    describe('Handles incoming messages', function() {

        it('Handles requests to disable avatars', function(done) {
            socket.once('xmpp.avatar.push.metadata', function(data) {
                data.from.should.eql({
                    domain: 'shakespeare.lit',
                    user: 'romeo'
                })
                data.disabled.should.be.true
                done()
            })
            var stanza = '<message from="<EMAIL>">' +
                '<event xmlns="' + avatar.NS_EVENT + '">' +
                '<items xmlns="' + avatar.NS_META + '">' +
                '<item>' +
                '<metadata xmlns="' + avatar.NS_META + '" />' +
                '</item>' +
                '</items>' +
                '</event>' +
                '</message>'
            avatar.handle(ltx.parse(stanza))
        })
        
        it('Handles a bad stanza', function() {
            var stanza = ltx.parse('<iq from="<EMAIL>" />')
            avatar.handle(stanza).should.be.false
        })

        it('Handles full metadata update', function(done) {
            socket.once('xmpp.avatar.push.metadata', function(data) {
                data.from.should.eql({
                    domain: 'shakespeare.lit',
                    user: 'romeo'
{'fraction_non_alphanumeric': 0.14774214659685864, 'fraction_numerical': 0.000981675392670157, 'mean_word_length': 1.4393455706304867, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '5960146', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1660, 'n_words': 327}