<commit_before>const Dock = require('../../lib/bases/Dock');
const Sparkles = require('sparkles');
const test = require('tape');
const group = require('tape-plus').group;

const config = {
    port: 8080,
    parser: {
        subtagSeparator: '|',
        dataSeparator: ','
    },
    encoder: {
        subtagSeparator: '|',
        dataSeparator: ','
    },
    maxMessageLength: 100
};
const dispatcher = {
    tags: {
        'tag1': {}
    },
    dispatch: (data, callback) => {}
};

group('id', (test) => {
    var dock = new Dock('test', 'test');

    test('sets dock Id', (t) => {
        dock.id = 'test';
        t.equal(dock.id, 'test');
    });

    test('gets dock Id', (t) => {
        dock.id = 'example';
        t.equal(dock.id, 'example');
    });
});

group('name', (test) => {
    const dock = new Dock('test', 'test');

    test('gets dock name', (t) => {
        t.equal(dock.name, 'test');
    });
});

group('protocol', (test) => {
    const dock = new Dock('test', 'test');

    test('gets dock protocol', (t) => {
        t.equal(dock.protocol, 'test');
    });
});

group('port', (test) => {
    const dock = new Dock('test', 'test');

    test('gets dock port', (t) => {
        dock.config = {
            port: 8080
        };
        t.equal(dock.port, 8080);
    });
});

group('config', (test) => {
    const dock = new Dock('test', 'test');

    const config = {
        port: 8080,
        test: 'test'
    };
    const expectedConfig = {
        maxMessageLength: 300,
        port: 8080,
        test: 'test'
    };

    test('sets dock config', (t) => {
        dock.config = config;
        t.deepEqual(dock.config, expectedConfig);
    });

    test('gets dock config', (t) => {
        t.deepEqual(dock.config, expectedConfig);
    });
});

group('dispatcher', (test) => {
    const dock = new Dock('test', 'test');

    test('sets dispatcher instance', (t) => {
        dock.dispatcher = dispatcher;
        t.deepEqual(dock._dispatcher, dispatcher);
    });
});

group('validate()', (test) => {
    const dock = new Dock('test', 'test');

    const config = {
        port: 8080,
        parser: {
            subtagSeparator: '|',
            dataSeparator: ','
        },
        encoder: {
            subtagSeparator: '|',
            dataSeparator: ','
        },
        maxMessageLength: 100
    };

    dock.dispatcher = dispatcher;
    dock.config = config;

    test('validates messages', (t) => {<commit_msg>Refactored Dock tests to avoid code duplication<commit_after>const Dock = require('../../lib/bases/Dock');
const Sparkles = require('sparkles');
const test = require('tape');
const group = require('tape-plus').group;

const config = {
    port: 8080,
    parser: {
        subtagSeparator: '|',
        dataSeparator: ','
    },
    encoder: {
        subtagSeparator: '|',
        dataSeparator: ','
    },
    maxMessageLength: 100
};
const dispatcher = {
    tags: {
        'tag1': {}
    },
    dispatch: (data, callback) => {}
};

group('id', (test) => {
    var dock = new Dock('test', 'test');

    test('sets dock Id', (t) => {
        dock.id = 'test';
        t.equal(dock.id, 'test');
    });

    test('gets dock Id', (t) => {
        dock.id = 'example';
        t.equal(dock.id, 'example');
    });
});

group('name', (test) => {
    const dock = new Dock('test', 'test');

    test('gets dock name', (t) => {
        t.equal(dock.name, 'test');
    });
});

group('protocol', (test) => {
    const dock = new Dock('test', 'test');

    test('gets dock protocol', (t) => {
        t.equal(dock.protocol, 'test');
    });
});

group('port', (test) => {
    const dock = new Dock('test', 'test');

    test('gets dock port', (t) => {
        dock.config = {
            port: 8080
        };
        t.equal(dock.port, 8080);
    });
});

group('config', (test) => {
    const dock = new Dock('test', 'test');

    test('sets dock config', (t) => {
        dock.config = config;
        t.deepEqual(dock.config, config);
    });

    test('gets dock config', (t) => {
        t.deepEqual(dock.config, config);
    });
});

group('dispatcher', (test) => {
    const dock = new Dock('test', 'test');

    test('sets dispatcher instance', (t) => {
        dock.dispatcher = dispatcher;
        t.deepEqual(dock._dispatcher, dispatcher);
    });
});

group('validate()', (test) => {
    const dock = new Dock('test', 'test');

    dock.dispatcher = dispatcher;
    dock.config = config;

    test('validates messages', (t) => {
{'fraction_non_alphanumeric': 0.2011111111111111, 'fraction_numerical': 0.011111111111111112, 'mean_word_length': 2.2568740955137483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '5480252', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1464, 'n_words': 324}