<commit_before>const { Mongodoki } = require('../dist/index');
const chai = require('chai');
const should = chai.should();
const chaiAsPromised = require('chai-as-promised');
const MongoClient = require('mongodb').MongoClient;
const utils = require('./utils.js');

chai.use(chaiAsPromised);

describe('Mongodoki', function () {
    describe('Mongodoki class', function () {

        it('constructor by default should init hostPort and Tag members', function () {
            const md = new Mongodoki();
            md.tag.should.equal('latest');
            md.hostPort.should.equal(27017);
        });

        it('constructor by default should init hostPort', function () {
            const md = new Mongodoki({
                tag: 'aTag'
            });
            md.tag.should.equal('aTag');
            md.hostPort.should.equal(27017);
        });

        it('constructor by default should init Tag and set the right port', function () {
            const md = new Mongodoki({ hostPort: 22222 });
            md.tag.should.equal('latest');
            md.hostPort.should.equal(22222);
        });
    });

    describe('Starting the MongoDB container', function () {
        let md;
        let db;

        before('Start container', async function () {
            md = new Mongodoki();
            db = await md.getDB();

        });

        it('container should start and a connection to DB should be established', async function () {

            db.should.be.ok;
            // get
            const collections = await db.collections();
            collections.should.be.ok;
            await db.close();

        });

        after('Stop and Remove container', async function () {
            await md.stopAndRemove();
            return;
        });
    });

    describe('Starting and stopping and removing the MongoDB container', function () {
        let md;
        let db;

        before('Start container', async function () {
            md = new Mongodoki();
            db = await md.getDB();

        });

        it('container should start and a connection to DB should be established', async function () {

            db.should.be.ok;
            // get
            const collections = await db.collections();
            collections.should.be.ok;
            await db.close();

        });

        after('Stop and Remove container', async function () {
            await md.stop();
            await md.remove();
            return;
        });
    });

    describe('Testing timeouts', function () {
        let md;
        let db;

        before('Create a container for timeouts testing', async function () {
            md = new Mongodoki({ tag: 'latest', containerName: 'ruggero' });
        });

        it('Starting a container with a too low timeout should throw an Error', function () {
            return md.getDB('anotherAmazingDB', 50).should.be.rejected;
        });

        after('Stop and Remove container', async function () {
            await md.stop();
            await md.remove();
            return;
        });
    });

    describe('Trying to create a container with the same name (default) of a running one', function () {
        let md, md2;
        let db, db2;

        before('Create a container', async function () {
            md = new Mongodoki();
            db = await md.getDB();
        });

        it('Should be OK', async function () {
            md2 = new Mongodoki();<commit_msg>feat(module): improve tests, timeout and import/restore<commit_after>const { Mongodoki } = require('../dist/index');
const chai = require('chai');
const should = chai.should();
const chaiAsPromised = require('chai-as-promised');
const MongoClient = require('mongodb').MongoClient;
const utils = require('./utils.js');

chai.use(chaiAsPromised);

describe('Mongodoki', function () {
    describe('Mongodoki class', function () {

        it('constructor by default should init hostPort and Tag members', function () {
            const md = new Mongodoki();
            md.tag.should.equal('latest');
            md.hostPort.should.equal(27017);
        });

        it('constructor by default should init hostPort', function () {
            const md = new Mongodoki({
                tag: 'aTag'
            });
            md.tag.should.equal('aTag');
            md.hostPort.should.equal(27017);
        });

        it('constructor by default should init Tag and set the right port', function () {
            const md = new Mongodoki({ hostPort: 22222 });
            md.tag.should.equal('latest');
            md.hostPort.should.equal(22222);
        });
    });

    describe('Starting the MongoDB container', function () {
        let md;
        let db;

        before('Start container', async function () {
            md = new Mongodoki();
            db = await md.getDB();

        });

        it('container should start and a connection to DB should be established', async function () {

            db.should.be.ok;
            // get
            const collections = await db.collections();
            collections.should.be.ok;
            await db.close();

        });

        after('Stop and Remove container', async function () {
            await md.stopAndRemove();
            return;
        });
    });

    describe('Starting and stopping and removing the MongoDB container', function () {
        let md;
        let db;

        before('Start container', async function () {
            md = new Mongodoki();
            db = await md.getDB();

        });

        it('container should start and a connection to DB should be established', async function () {

            db.should.be.ok;
            // get
            const collections = await db.collections();
            collections.should.be.ok;
            await db.close();

        });

        after('Stop and Remove container', async function () {
            await md.stop();
            await md.remove();
            return;
        });
    });

    describe('Testing timeouts', function () {
        let md;
        let db;

        before('Create a container for timeouts testing', async function () {
            md = new Mongodoki({ tag: 'latest', containerName: 'ruggero' });
        });

        it('Starting a container with a too low timeout should throw an Error', function () {
            return md.getDB('anotherAmazingDB', 2).should.be.rejected;
        });

        after('Stop and Remove container', async function () {
            await md.stop();
            await md.remove();
            return;
        });
    });

    describe('Trying to create a container with the same name (default) of a running one', function () {
        let md, md2;
        let db, db2;

        before('Create a container', async function () {
            md = new Mongodoki();
            db = await md.getDB();
        });

        it('Should be OK', async function () {
            md2 = new Mongodoki();
{'fraction_non_alphanumeric': 0.12544905877281218, 'fraction_numerical': 0.007041241557695071, 'mean_word_length': 1.8536285362853628, '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': '775287', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1767, 'n_words': 544}