<commit_before>'use strict'

const Hemera = require('./../../hemera')
const HemeraMongoStore = require('./../index')
const Nats = require('nats')
const HemeraTestsuite = require('hemera-testsuite')
const EJSON = require('mongodb-extended-json')
const expect = require('code').expect

function createExtendedData(mongodb, date) {
  const oid = new mongodb.ObjectID('58c6c65ed78c6a977a0041a8')
  return EJSON.serialize({
    date: date || new Date(),
    objectId: oid,
    ref: mongodb.DBRef('test', oid),
  })
}

function testExtendedData(plugin, testCollection, id, done) {
  plugin.db.collection(testCollection).findOne({
    _id: new plugin.mongodb.ObjectID(id)
  }, (err, doc) => {
    expect(err).to.be.null()
    testExtendedDoc(plugin, doc)
    done()
  })
}

function testExtendedDoc(plugin, doc) {
  const ObjectID = plugin.mongodb.ObjectID
  const DBRef = plugin.mongodb.DBRef

  expect(doc.date).to.be.a.date()
  expect(doc.objectId).to.be.an.instanceof(ObjectID)
  expect(doc.ref).to.be.an.instanceof(DBRef)
}

function initServer(topic, testCollection, pluginOptions, cb) {
  const PORT = 6243
  const noAuthUrl = 'nats://localhost:' + PORT
  let server
  let hemera
  let plugin

  server = HemeraTestsuite.start_server(PORT, {}, () => {
    const nats = Nats.connect(noAuthUrl)
    hemera = new Hemera(nats, {
      logLevel: 'silent'
    })
    hemera.use(HemeraMongoStore, pluginOptions)
    hemera.ready(() => {
      plugin = hemera.exposition['hemera-mongo-store']
      hemera.act({
        topic,
        cmd: 'dropCollection',
        collection: testCollection
      }, function (err, resp) {
        cb(null, { server, hemera, plugin })
      })
    })
  })
}


exports.initServer = initServer
exports.testExtendedData = testExtendedData
exports.createExtendedData = createExtendedData
exports.testExtendedDoc = testExtendedDoc<commit_msg>Adjust variable declarations<commit_after>'use strict'

const Hemera = require('./../../hemera')
const HemeraMongoStore = require('./../index')
const Nats = require('nats')
const HemeraTestsuite = require('hemera-testsuite')
const EJSON = require('mongodb-extended-json')
const expect = require('code').expect

function createExtendedData(mongodb, date) {
  const oid = new mongodb.ObjectID('58c6c65ed78c6a977a0041a8')
  return EJSON.serialize({
    date: date || new Date(),
    objectId: oid,
    ref: mongodb.DBRef('test', oid),
  })
}

function testExtendedData(plugin, testCollection, id, done) {
  plugin.db.collection(testCollection).findOne({
    _id: new plugin.mongodb.ObjectID(id)
  }, (err, doc) => {
    expect(err).to.be.null()
    testExtendedDoc(plugin, doc)
    done()
  })
}

function testExtendedDoc(plugin, doc) {
  const ObjectID = plugin.mongodb.ObjectID
  const DBRef = plugin.mongodb.DBRef

  expect(doc.date).to.be.a.date()
  expect(doc.objectId).to.be.an.instanceof(ObjectID)
  expect(doc.ref).to.be.an.instanceof(DBRef)
}

function initServer(topic, testCollection, pluginOptions, cb) {
  const PORT = 6243
  const noAuthUrl = 'nats://localhost:' + PORT

  const server = HemeraTestsuite.start_server(PORT, {}, () => {
    const nats = Nats.connect(noAuthUrl)
    const hemera = new Hemera(nats, {
      logLevel: 'silent'
    })
    hemera.use(HemeraMongoStore, pluginOptions)
    hemera.ready(() => {
      const plugin = hemera.exposition['hemera-mongo-store']
      hemera.act({
        topic,
        cmd: 'dropCollection',
        collection: testCollection
      }, function (err, resp) {
        cb(null, { server, hemera, plugin })
      })
    })
  })
}


exports.initServer = initServer
exports.testExtendedData = testExtendedData
exports.createExtendedData = createExtendedData
exports.testExtendedDoc = testExtendedDoc
{'fraction_non_alphanumeric': 0.13917248790972594, 'fraction_numerical': 0.010746910263299301, 'mean_word_length': 3.84765625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4216962', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1222, 'n_words': 236}