<commit_before>var mqtt = require('mqtt'),
    _ = require('busyman'),
    chai = require('chai'),
    expect = chai.expect;
    sinon = require('sinon'),
    sinonChai = require('sinon-chai'),
    expect = require('chai').expect;

var USE_TRAVIS = true;
chai.use(sinonChai);

var Mqnode = require('../index.js'),
    SmartObject = require('smartobject');

var so = new SmartObject();

describe('Signature Check', function () {
     var mqnode = new Mqnode('foo', so, { version: '0.0.1' });

     // for travis-ci, since network module cannot run on it
     if (USE_TRAVIS) {
         mqnode.ip = '192.168.0.100';
         mqnode.mac = '00:0c:29:c2:dc:8e';
     }

    describe('#new mqnode', function () {
        it('should throw TypeError if clientId is not a string', function () {
            expect(function () { return new Mqnode(null, so, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode(undefined, so, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode(true, so, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode(NaN, so, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode(12, so, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode({}, so, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode([], so, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode(new Date(), so, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode(function () {}, so, { version: '0.0.1' } ); }).to.throw(TypeError);

            expect(function () { return new Mqnode('foo', so, { version: '0.0.1' } ); }).not.to.throw(Error);
        });

        it('should throw TypeError if so is not an instance of SmartObject class', function () {
            expect(function () { return new Mqnode('foo', 'x', { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', 12, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', null, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', undefined, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', NaN, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', true, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', new Date(), { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', {}, { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', [], { version: '0.0.1' } ); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', function () {}, { version: '0.0.1' } ); }).to.throw(TypeError);

            expect(function () { return new Mqnode('foo', so, { version: '0.0.1' } ); }).not.to.throw(Error);
        });

        it('should throw TypeError if devAttrs is not an object if given', function () {
            expect(function () { return new Mqnode('foo', so, 'x'); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', so, 12); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', so, true); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', so, new Date()); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', so, []); }).to.throw(TypeError);
            expect(function () { return new Mqnode('foo', so, function () {}); }).to.throw(TypeError);

            expect(function () { return new Mqnode('foo', so, null); }).not.to.throw(TypeError);
            expect(function () { return new Mqnode('foo', so, undefined); }).not.to.throw(TypeError);
            expect(function () { return new Mqnode('foo', so, NaN); }).not.to.throw(TypeError);
            expect(function () { return new Mqnode('foo', so, {}); }).not.to.throw(TypeError);
            expect(function () { return new Mqnode('foo', so, { version: '0.0.1' } ); }).not.to.throw(Error);
        });
    });

    describe('#.setDevAttrs', function () {
        // mqnode.on('error', function (e) {
        //     console.log(e);
        // });
        it('should throw TypeError if devAttrs is not an object', function () {
            expect(function () { return mqnode.setDevAttrs('x'); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(1); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(true); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs([]); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(null); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(undefined); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(NaN); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(new Date()); }).to.throw(TypeError);

            expect(function () { return mqnode.setDevAttrs({}); }).not.to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs({}, function (e, r) {}); }).not.to.throw(TypeError);
        });
    });

    describe('#.enableReport', function () {
        it('should throw TypeError if oid is not a number or a string', function () {
            expect(function () { return mqnode.enableReport(); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport({}); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport([]); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport(true); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport(null); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport(NaN); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport(new Date()); }).to.throw(TypeError);<commit_msg>skip constructor test for travis testing, since network cannot be used<commit_after>var mqtt = require('mqtt'),
    _ = require('busyman'),
    chai = require('chai'),
    expect = chai.expect;
    sinon = require('sinon'),
    sinonChai = require('sinon-chai'),
    expect = require('chai').expect;

var USE_TRAVIS = true;
chai.use(sinonChai);

var Mqnode = require('../index.js'),
    SmartObject = require('smartobject');

var so = new SmartObject();

describe('Signature Check', function () {
     var mqnode = new Mqnode('foo', so, { version: '0.0.1' });

     // for travis-ci, since network module cannot run on it
     if (USE_TRAVIS) {
         mqnode.ip = '192.168.0.100';
         mqnode.mac = '00:0c:29:c2:dc:8e';
     }

    if (!USE_TRAVIS) {
        describe('#new mqnode', function () {
            it('should throw TypeError if clientId is not a string', function () {
                expect(function () { return new Mqnode(null, so, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode(undefined, so, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode(true, so, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode(NaN, so, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode(12, so, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode({}, so, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode([], so, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode(new Date(), so, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode(function () {}, so, { version: '0.0.1' } ); }).to.throw(TypeError);

                expect(function () { return new Mqnode('foo', so, { version: '0.0.1' } ); }).not.to.throw(Error);
            });

            it('should throw TypeError if so is not an instance of SmartObject class', function () {
                expect(function () { return new Mqnode('foo', 'x', { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', 12, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', null, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', undefined, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', NaN, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', true, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', new Date(), { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', {}, { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', [], { version: '0.0.1' } ); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', function () {}, { version: '0.0.1' } ); }).to.throw(TypeError);

                expect(function () { return new Mqnode('foo', so, { version: '0.0.1' } ); }).not.to.throw(Error);
            });

            it('should throw TypeError if devAttrs is not an object if given', function () {
                expect(function () { return new Mqnode('foo', so, 'x'); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', so, 12); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', so, true); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', so, new Date()); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', so, []); }).to.throw(TypeError);
                expect(function () { return new Mqnode('foo', so, function () {}); }).to.throw(TypeError);

                expect(function () { return new Mqnode('foo', so, null); }).not.to.throw(TypeError);
                expect(function () { return new Mqnode('foo', so, undefined); }).not.to.throw(TypeError);
                expect(function () { return new Mqnode('foo', so, NaN); }).not.to.throw(TypeError);
                expect(function () { return new Mqnode('foo', so, {}); }).not.to.throw(TypeError);
                expect(function () { return new Mqnode('foo', so, { version: '0.0.1' } ); }).not.to.throw(Error);
            });
        });
    }

    describe('#.setDevAttrs', function () {
        // mqnode.on('error', function (e) {
        //     console.log(e);
        // });
        it('should throw TypeError if devAttrs is not an object', function () {
            expect(function () { return mqnode.setDevAttrs('x'); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(1); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(true); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs([]); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(null); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(undefined); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(NaN); }).to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs(new Date()); }).to.throw(TypeError);

            expect(function () { return mqnode.setDevAttrs({}); }).not.to.throw(TypeError);
            expect(function () { return mqnode.setDevAttrs({}, function (e, r) {}); }).not.to.throw(TypeError);
        });
    });

    describe('#.enableReport', function () {
        it('should throw TypeError if oid is not a number or a string', function () {
            expect(function () { return mqnode.enableReport(); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport({}); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport([]); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport(true); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport(null); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport(NaN); }).to.throw(TypeError);
            expect(function () { return mqnode.enableReport(new Date()); }).to.throw(TypeError);
{'fraction_non_alphanumeric': 0.19268030139935413, 'fraction_numerical': 0.01430109180378287, 'mean_word_length': 2.743021582733813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5961712', 'n_tokens_mistral': 4083, 'n_tokens_neox': 3994, 'n_words': 892}