<commit_before>'use strict';

const Hapi = require('hapi');
const Lab = require('lab');
const Code = require('code');
const FS = require('fs');
const Path = require('path');

const internals = {};

const lab = exports.lab = Lab.script();
const expect = Code.expect;

lab.experiment('Plugin Tests', () => {

  let server = {};

  lab.beforeEach((done) => {

    server = new Hapi.Server();
    done();
  });

  lab.test('Rejection of invalid options', (done) => {

    const register = () => {

      server.register({
        register: require('../'),
        options: {
          directory: 'blah'
        }
      }, (err) => {

        throw err;
      });
    };

    expect(register).to.throw(Error);
    done();
  });

  lab.test('Successful registration of plugin', (done) => {

    server.register({
      register: require('../'),
      options: {
        modelName: 'test',
        filename: 'testlinvodb.1',
        schema: {}
      }
    }, (err) => {

      const files_before = FS.readdirSync(Path.join(__dirname, '..'));
      console.info('\n Files in dir before:\n', files_before);

      // Attempt to get tets to pass on Travis
      setTimeout(function () {
        const db = Path.join(__dirname, '..', 'testlinvodb.1');
        expect(err).to.not.exist();
        expect(FS.accessSync(db, FS.F_OK)).to.not.exist();
        done();
      }, 100);
    });
  });

  lab.test('Successfully access plugin exposed objects and methods', (done) => {

    const files_after = FS.readdirSync(Path.join(__dirname, '..'));
    console.info('\n Files in dir after:\n', files_after);

    server.connection();
    server.register({
      register: require('../'),
      options: {
        modelName: 'test',
        filename: 'testlinvodb.2',
        schema: {}
      }
    }, (err) => {

      expect(err).to.not.exist();

      server.route({
        method: 'GET',
        path: '/',
        handler: (request, reply) => {

          const plugin = request.server.plugins['hapi-linvodb'];

          expect(plugin.db.modelName).to.equal('test');
          expect(plugin.db.filename).to.equal('testlinvodb.2');

          plugin.db.insert({ a: 1 }, (err, doc) => {

            expect(err).to.not.exist();
            expect(doc.a).to.equal(1);<commit_msg>Removed console output and fixed listing<commit_after>'use strict';

const Hapi = require('hapi');
const Lab = require('lab');
const Code = require('code');
const FS = require('fs');
const Path = require('path');

const internals = {};

const lab = exports.lab = Lab.script();
const expect = Code.expect;

lab.experiment('Plugin Tests', () => {

  let server = {};

  lab.beforeEach((done) => {

    server = new Hapi.Server();
    done();
  });

  lab.test('Rejection of invalid options', (done) => {

    const register = () => {

      server.register({
        register: require('../'),
        options: {
          directory: 'blah'
        }
      }, (err) => {

        throw err;
      });
    };

    expect(register).to.throw(Error);
    done();
  });

  lab.test('Successful registration of plugin', (done) => {

    server.register({
      register: require('../'),
      options: {
        modelName: 'test',
        filename: 'testlinvodb.1',
        schema: {}
      }
    }, (err) => {

      // Attempt to get tets to pass on Travis
      setTimeout(() => {

        const db = Path.join(__dirname, '..', 'testlinvodb.1');
        expect(err).to.not.exist();
        expect(FS.accessSync(db, FS.F_OK)).to.not.exist();
        done();
      }, 100);
    });
  });

  lab.test('Successfully access plugin exposed objects and methods', (done) => {

    server.connection();
    server.register({
      register: require('../'),
      options: {
        modelName: 'test',
        filename: 'testlinvodb.2',
        schema: {}
      }
    }, (err) => {

      expect(err).to.not.exist();

      server.route({
        method: 'GET',
        path: '/',
        handler: (request, reply) => {

          const plugin = request.server.plugins['hapi-linvodb'];

          expect(plugin.db.modelName).to.equal('test');
          expect(plugin.db.filename).to.equal('testlinvodb.2');

          plugin.db.insert({ a: 1 }, (err, doc) => {

            expect(err).to.not.exist();
            expect(doc.a).to.equal(1);
{'fraction_non_alphanumeric': 0.18652366519002098, 'fraction_numerical': 0.004196782466775472, 'mean_word_length': 2.218304576144036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '2169520', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1307, 'n_words': 272}