<commit_before>var chai = require('chai');
var chaiHttp = require('chai-http');
var should = chai.should();

var config = require('config');
var Promise = require('bluebird');

var umpack = require('./helpers/umpack');
var utils = require('./helpers/utils');
var mongoose = require('mongoose');
var ObjectId = require('mongodb').ObjectID;

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

chai.use(chaiHttp);
global.Promise = Promise;


describe('service api users administrative routes', function() {

  var app = require('./helpers/app');

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

  before(function() {
    return mongoose.connection.db.dropCollection(rolesCollection)
      .then(function() {
        return mongoose.connection.db.collection(rolesCollection)
          .insert({
            "name": "admin",
            "actions": [{
              "_id": new ObjectId("58a301b880a92f3930ebfef4"),
              "pattern": "/um/*",
              "name": "um",
              "verbDelete": true,
              "verbPost": true,
              "verbPut": true,
              "verbGet": true
            }],
            "__v": 0
          });
      });
  });

  beforeEach(function() {
    return mongoose.connection.db.dropCollection(usersCollection)
      .then(function() {
        return mongoose.connection.db.collection(usersCollection)
          .insert({
            userName: username,
            password: utils.passwordHash(password),
            isActivated: true,
            roles: ['admin'],
            '__v': 1
          });
      });
  });

  describe('GET users/:id', function() {
    it('should return full object', function() {
      var id = new ObjectId();

      return mongoose.connection.db.collection(usersCollection)
        .insert({
          _id: id,
          userName: defaultUser,
          password: utils.passwordHash(password),
          isActivated: true,
          roles: ['admin'],
          email: '<EMAIL>',
          firstName: 'test',
          '__v': 1
        })
        .then(login)
        .then(function(res) {
          res.should.have.status(200);

          return chai.request(app)
            .get('/um/users/' + id)
            .set('authorization', res.text);
        })
        .then(function(res) {
          res.should.have.status(200);

          should.exist(res.body);
          res.body.should.have.property('userName', defaultUser);
          res.body.should.have.property('email', '<EMAIL>');
          res.body.should.have.property('firstName', 'test');
        });
    });
  });

  describe('DELETE users/:id', function() {
    it('should remove user', function() {
      var id = new ObjectId();

      return mongoose.connection.db.collection(usersCollection)
        .insert({
          _id: id,
          userName: defaultUser,
          password: <PASSWORD>(password),
          isActivated: true,
          roles: ['admin'],
          email: '<EMAIL>',
          firstName: 'test',
          '__v': 1
        })
        .then(login)
        .then(function(res) {
          res.should.have.status(200);

          return chai.request(app)
            .delete('/um/users/' + id)
            .set('authorization', res.text);
        })
        .then(function(res) {
          res.should.have.status(200);

          should.exist(res.body);
          res.body.should.have.property('success', true);
        });
    });
  });

  describe('PUT users/:id/info', function() {
    it('should update', function() {
      var id = new ObjectId();

      return mongoose.connection.db.collection(usersCollection)
        .insert({
          _id: id,
          userName: defaultUser,
          password: <PASSWORD>.<PASSWORD>(password),
          isActivated: true,
          roles: ['admin'],<commit_msg>on delete test check if exists in db<commit_after>var chai = require('chai');
var chaiHttp = require('chai-http');
var should = chai.should();

var config = require('config');
var Promise = require('bluebird');

var umpack = require('./helpers/umpack');
var utils = require('./helpers/utils');
var mongoose = require('mongoose');
var ObjectId = require('mongodb').ObjectID;

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

chai.use(chaiHttp);
global.Promise = Promise;


describe('service api users administrative routes', function() {

  var app = require('./helpers/app');

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

  before(function() {
    return mongoose.connection.db.dropCollection(rolesCollection)
      .then(function() {
        return mongoose.connection.db.collection(rolesCollection)
          .insert({
            "name": "admin",
            "actions": [{
              "_id": new ObjectId("58a301b880a92f3930ebfef4"),
              "pattern": "/um/*",
              "name": "um",
              "verbDelete": true,
              "verbPost": true,
              "verbPut": true,
              "verbGet": true
            }],
            "__v": 0
          });
      });
  });

  beforeEach(function() {
    return mongoose.connection.db.dropCollection(usersCollection)
      .then(function() {
        return mongoose.connection.db.collection(usersCollection)
          .insert({
            userName: username,
            password: utils.passwordHash(password),
            isActivated: true,
            roles: ['admin'],
            '__v': 1
          });
      });
  });

  describe('GET users/:id', function() {
    it('should return full object', function() {
      var id = new ObjectId();

      return mongoose.connection.db.collection(usersCollection)
        .insert({
          _id: id,
          userName: defaultUser,
          password: utils.passwordHash(password),
          isActivated: true,
          roles: ['admin'],
          email: '<EMAIL>',
          firstName: 'test',
          '__v': 1
        })
        .then(login)
        .then(function(res) {
          res.should.have.status(200);

          return chai.request(app)
            .get('/um/users/' + id)
            .set('authorization', res.text);
        })
        .then(function(res) {
          res.should.have.status(200);

          should.exist(res.body);
          res.body.should.have.property('userName', defaultUser);
          res.body.should.have.property('email', '<EMAIL>');
          res.body.should.have.property('firstName', 'test');
        });
    });
  });

  describe('DELETE users/:id', function() {
    it('should remove user', function() {
      var id = new ObjectId();

      return mongoose.connection.db.collection(usersCollection)
        .insert({
          _id: id,
          userName: defaultUser,
          password: <PASSWORD>(password),
          isActivated: true,
          roles: ['admin'],
          email: '<EMAIL>',
          firstName: 'test',
          '__v': 1
        })
        .then(login)
        .then(function(res) {
          res.should.have.status(200);

          return chai.request(app)
            .delete('/um/users/' + id)
            .set('authorization', res.text);
        })
        .then(function(res) {
          res.should.have.status(200);

          should.exist(res.body);
          res.body.should.have.property('success', true);

          return findUser(id);
        })
        .then(function (user) {
          should.not.exist(user);
        });
    });
  });

  describe('PUT users/:id/info', function() {
    it('should update', function() {
      var id = new ObjectId();

      return mongoose.connection.db.collection(usersCollection)
        .insert({
          _id: id,
          userName: defaultUser,
          password: <PASSWORD>.<PASSWORD>(password),
          isActivated: true,
          roles: ['admin'],
{'fraction_non_alphanumeric': 0.15163124073158676, 'fraction_numerical': 0.007661888284725655, 'mean_word_length': 2.0074321813452247, 'pattern_counts': {'":': 20, '<': 17, '<?xml version=': 0, '>': 17, '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': '7119824', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2316, 'n_words': 459}