<commit_before>var config = require('config');
var crypto = require('crypto');

var mongoose = require('mongoose');
var ObjectId = require('mongodb').ObjectID;
var chai = require('chai');
var chaiHttp = require('chai-http');
var Promise = require('bluebird');

chai.use(chaiHttp);
global.Promise = Promise;
var app = require('./app');

var usersCollection = 'users';
var rolesCollection = 'roleactions';
var username = 'test';
var password = '<PASSWORD>';

function passwordHash(password) {
  return crypto.createHmac('sha256', config.get('umpack.passwordHashSecret'))
    .update(password)
    .digest('hex');
}

function saveRecordWithParameters(metadata, isActivated, roles) {
  if (isActivated === null || isActivated === undefined) isActivated = true;

  if (!roles) roles = ['user'];

  return mongoose.connection.collection(usersCollection).insert({
    metaData: metadata,
    userName: username,
    password: <PASSWORD>(password),
    email: "<EMAIL>",
    isActivated: isActivated,
    roles: roles,
    '__v': 0
  });
}

function login() {
  return chai.request(app)
    .post('/um/login')
    .send({
      userName: username,
      password: password
    });
}

module.exports = {
  passwordHash: passwordHash,
  saveRecordWithParameters: saveRecordWithParameters,
  login: login
};<commit_msg>bad request test function<commit_after>var config = require('config');
var crypto = require('crypto');

var mongoose = require('mongoose');
var ObjectId = require('mongodb').ObjectID;
var chai = require('chai');
var chaiHttp = require('chai-http');
var Promise = require('bluebird');
var should = chai.should();

chai.use(chaiHttp);
global.Promise = Promise;
var app = require('./app');

var usersCollection = 'users';
var rolesCollection = 'roleactions';
var username = 'test';
var password = '<PASSWORD>';

function passwordHash(password) {
  return crypto.createHmac('sha256', config.get('umpack.passwordHashSecret'))
    .update(password)
    .digest('hex');
}

function saveRecordWithParameters(metadata, isActivated, roles) {
  if (isActivated === null || isActivated === undefined) isActivated = true;

  if (!roles) roles = ['user'];

  return mongoose.connection.collection(usersCollection).insert({
    metaData: metadata,
    userName: username,
    password: <PASSWORD>),
    email: "<EMAIL>",
    isActivated: isActivated,
    roles: roles,
    '__v': 0
  });
}

function login() {
  return chai.request(app)
    .post('/um/login')
    .send({
      userName: username,
      password: password
    });
}

function shouldBeBadRequest(promise, internalStatus) {
  return promise
    .then(function(res) {
      res.should.have.status(400);
    })
    .catch(function(err) {
      if (err instanceof chai.AssertionError) throw err;

      err.should.have.status(400);

      should.exist(err.response.body);

      err.response.body.should.have.property('internalStatus', internalStatus);
    });
}

module.exports = {
  passwordHash: <PASSWORD>,
  saveRecordWithParameters: saveRecordWithParameters,
  login: login,
  shouldBeBadRequest: shouldBeBadRequest
};
{'fraction_non_alphanumeric': 0.14842481325105553, 'fraction_numerical': 0.004546930821695355, 'mean_word_length': 4.460992907801418, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '198151', 'n_tokens_mistral': 951, 'n_tokens_neox': 937, 'n_words': 214}