<commit_before>const fs = require('fs');
const { promisify } = require('util');
const mongodb = require('mongodb');
const request = require('request');

async function readMongoDocuments(file) {
  const ISODate = (d) => new Date(d);
  const ObjectId = (id) => mongodb.ObjectID.createFromHexString(id);
  return eval(await fs.promises.readFile(file, 'utf-8'));
}

async function insertTestData(url, docsPerCollection) {
  const mongoClient = await mongodb.MongoClient.connect(url);
  const db = mongoClient.db();
  await Promise.all(
    Object.keys(docsPerCollection).map(async (collection) => {
      await db.collection(collection).deleteMany({});
      await db.collection(collection).insertMany(docsPerCollection[collection]);
    })
  );
  await mongoClient.close();
}

/* refresh openwhyd's in-memory cache of users, to allow this user to login */
async function refreshOpenwhydCache(urlPrefix = 'http://localhost:8080') {
  await promisify(request.post)(urlPrefix + '/testing/refresh');
}

module.exports = {<commit_msg>fix(tests): Get rid of Mongo's DeprecationWarning on approval tests<commit_after>const fs = require('fs');
const { promisify } = require('util');
const mongodb = require('mongodb');
const request = require('request');

async function readMongoDocuments(file) {
  const ISODate = (d) => new Date(d);
  const ObjectId = (id) => mongodb.ObjectID.createFromHexString(id);
  return eval(await fs.promises.readFile(file, 'utf-8'));
}

async function insertTestData(url, docsPerCollection) {
  const mongoClient = await mongodb.MongoClient.connect(url, {
    useUnifiedTopology: true,
  });
  const db = mongoClient.db();
  await Promise.all(
    Object.keys(docsPerCollection).map(async (collection) => {
      await db.collection(collection).deleteMany({});
      await db.collection(collection).insertMany(docsPerCollection[collection]);
    })
  );
  await mongoClient.close();
}

/* refresh openwhyd's in-memory cache of users, to allow this user to login */
async function refreshOpenwhydCache(urlPrefix = 'http://localhost:8080') {
  await promisify(request.post)(urlPrefix + '/testing/refresh');
}

module.exports = {
{'fraction_non_alphanumeric': 0.14219114219114218, 'fraction_numerical': 0.004662004662004662, 'mean_word_length': 5.220289855072464, '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': '1311912', 'n_tokens_mistral': 666, 'n_tokens_neox': 655, 'n_words': 148}