<commit_before>// Fix Sinon bug when using 'FakeXMLHttpRequest' in Node
// https://github.com/cjohansen/Sinon.JS/issues/319
if (navigator.userAgent.indexOf('PhantomJS') !== -1){
  window.ProgressEvent = function (type, params) {
    params = params || {};

    this.lengthComputable = params.lengthComputable || false;
    this.loaded = params.loaded || 0;
    this.total = params.total || 0;
  };
}
 
beforeEach(function(){
  this.xhr = sinon.useFakeXMLHttpRequest();
  var requests = this.requests = [];

  this.xhr.onCreate = function (xhr) {
    requests.push(xhr);
  };
});

afterEach(function(){
  this.xhr.restore();
})

describe('Get', function(){
  it('should do an AJAX request', function(done){
    ajxr.get('/users').then(function(response){
      response.should.have.lengthOf(1);
      response[0].should.have.property('username', 'tomtheun');

      done();
    }).done();

    this.requests[0].respond(200, {}, '[{ "username": "tomtheun"}]');
  });

  it('should reject promise when AJAX request returns a 404', function(done){
    ajxr.get('/users/non-existing-user').fail(function(response){
      response.should.have.property('message', 'Status code was 404');
      
      done();
    }).done();

    this.requests[0].respond(404);
  })
});

describe('Post', function(){
  it('should do an AJAX request', function(done){
    ajxr.post('/users', {'username': 'tomtheun'}).then(function(response){
      response.should.have.property('username', 'tomtheun');

      done();
    }).done();

    this.requests[0].respond(201, {}, '{ "username": "tomtheun"}');
  });
});<commit_msg>Added a post rejection test<commit_after>describe('ajxr', function() {
  // Fix Sinon bug when using 'FakeXMLHttpRequest' in Node
  // https://github.com/cjohansen/Sinon.JS/issues/319
  if (navigator.userAgent.indexOf('PhantomJS') !== -1){
    window.ProgressEvent = function (type, params) {
      params = params || {};

      this.lengthComputable = params.lengthComputable || false;
      this.loaded = params.loaded || 0;
      this.total = params.total || 0;
    };
  }

  beforeEach(function(){
    this.xhr = sinon.useFakeXMLHttpRequest();
    var requests = this.requests = [];

    this.xhr.onCreate = function (xhr) {
      requests.push(xhr);
    };
  });

  afterEach(function(){
    this.xhr.restore();
  });

  describe('Get', function(){
    it('should do an AJAX request', function(done){
      ajxr.get('/users').then(function(response){
        response.should.have.lengthOf(1);
        response[0].should.have.property('username', 'tomtheun');

        done();
      }).done();

      this.requests[0].respond(200, {}, '[{ "username": "tomtheun"}]');
    });

    it('should reject promise when AJAX request returns a 404', function(done){
      ajxr.get('/users/non-existing-user').fail(function(response){
        response.should.have.property('message', 'Status code was 404');
        done();
      }).done();

      this.requests[0].respond(404);
    });
  });

  describe('Post', function(){
    it('should do an AJAX request', function(done){
      ajxr.post('/users', {'username': 'tomtheun'}).then(function(response){
        response.should.have.property('username', 'tomtheun');
        done();
      }).done();

      this.requests[0].respond(201, {}, '{ "username": "tomtheun"}');
    });

    it('should reject promise when AJAX request returns a 400', function(done) {
      ajxr.post('/users', {'usrname': 'tomtheun'}).fail(function(response) {
        response.should.have.property('message', 'Status code was 400');
        done();
      });

      this.requests[0].respond(400);
    });
  });
});
{'fraction_non_alphanumeric': 0.19185246352876412, 'fraction_numerical': 0.01706578585191302, 'mean_word_length': 3.357314148681055, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2175937', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1121, 'n_words': 213}