<commit_before>'use strict';

var should = require('should');
var Request = require('./request.model');
var controller = require('./request.controller');

var Actions = require('../../components/actions').actions;
var serverTest = require('../../test/utils/server');

var User = require('../user/user.model');

describe('Request Model', function() {
  var server = serverTest();
  var api = server.api;
  var auth = server.auth;
  var getToken = server.token;

  before(function(done) {
    // Clear mdphs before testing
    Request.remove().exec().then(function() {
      done();
    });
  });

  afterEach(function(done) {
    Request.remove().exec().then(function() {
      done();
    });
  });

  it('should render the right number of requests', function(done) {
    //given
    var newRequest = new Request({});

    //when
    newRequest.save(function() {

      //then
      Request.find({}, function(err, requests) {
        requests.should.have.length(1);
        done();
      });
    });
  });

  describe('When the user is authenticated', function() {

    it('should return 200', function(done) {
      //given
      var newRequest = new Request({shortId: '1234'});

      //when
      newRequest.save(function() {
        var token = getToken();

        //then
        api()
          .put('/api/requests/1234?access_token=' + token)
          .expect(200, done);
      });
    });

  });

  describe('When the user is not authenticated', function() {
    var newRequest = new Request({shortId: '1234'});

    //when
    newRequest.save(function() {

      //then
      it('should return 401', function(done) {
        api()
          .put('/api/requests/1234')
          .expect(401, done);
      });
    });
  });

});<commit_msg>check 404<commit_after>'use strict';

var should = require('should');
var Request = require('./request.model');
var controller = require('./request.controller');

var Actions = require('../../components/actions').actions;
var serverTest = require('../../test/utils/server');

var User = require('../user/user.model');

describe('Request Model', function() {
  var server = serverTest();
  var api = server.api;
  var auth = server.auth;
  var getToken = server.token;

  before(function(done) {
    // Clear mdphs before testing
    Request.remove().exec().then(function() {
      done();
    });
  });

  afterEach(function(done) {
    Request.remove().exec().then(function() {
      done();
    });
  });

  it('should render the right number of requests', function(done) {
    //given
    var newRequest = new Request({});

    //when
    newRequest.save(function() {

      //then
      Request.find({}, function(err, requests) {
        requests.should.have.length(1);
        done();
      });
    });
  });

  describe('When the user is authenticated', function() {

    it('should return 200', function(done) {
      //given
      var newRequest = new Request({shortId: '1234'});

      //when
      newRequest.save(function() {
        var token = getToken();

        //then
        api()
          .put('/api/requests/1234?access_token=' + token)
          .expect(200, done);
      });
    });

  });

  describe('When the request does not exist', function() {

    it('should return 404', function(done) {
      //given
      var newRequest = new Request({shortId: 'this_is_not_a_shortid'});

      //when
      newRequest.save(function() {
        var token = getToken();

        //then
        api()
          .put('/api/requests/1234?access_token=' + token)
          .expect(404, done);
      });
    });

  });

  describe('When the user is not authenticated', function() {
    var newRequest = new Request({shortId: '1234'});

    //when
    newRequest.save(function() {

      //then
      it('should return 401', function(done) {
        api()
          .put('/api/requests/1234')
          .expect(401, done);
      });
    });
  });

});
{'fraction_non_alphanumeric': 0.1772831926323868, 'fraction_numerical': 0.01816321309797902, 'mean_word_length': 2.388214904679376, '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': '5305659', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1125, 'n_words': 261}