<commit_before>var utils    = require('./utils')
  , request  = require('supertest')
  , should   = require('should')
  , express  = require('express')
  , mongoose = require('mongoose');

var app = require('../app.js');
var Article  = mongoose.model('Article');

describe('Article API CURD tests', function (argument) {

  beforeEach(function (done) {
  
    article = new Article({
      title: 'How to build a Blog with Node.js?',
      text:  'You should use some frameworks like Express'
    });

    done();
  });

  it('should list articles', function (done) {
    var articlesCount = 10, articlesIndex = 10;
    for (; articlesIndex > 0; articlesIndex--) {
      new Article({
        title: articlesIndex + 'Another Article Title'
      }).save();
    }
    request(app)
      .get('/api/articles')
      .expect(200, function (errors, res) {
        (res.body.length).should.be.equal(articlesCount);
        done();
      });
  });

  it('should show an article successfully', function (done) {
    article.save();
    request(app)
      .get('/api/articles/' + article._id)
      .expect(200, function (errors, res) {
        res.body.title.should.match(article.title);
        done();
      });
  });

  it('should create an article successfully', function (done) {
    request(app)
      .post('/api/articles')<commit_msg>Be sure that save operation running synchronously.<commit_after>var utils    = require('./utils')
  , request  = require('supertest')
  , should   = require('should')
  , express  = require('express')
  , mongoose = require('mongoose');

var app = require('../app.js');
var Article  = mongoose.model('Article');

describe('Article API CURD tests', function (argument) {

  beforeEach(function (done) {
  
    article = new Article({
      title: 'How to build a Blog with Node.js?',
      text:  'You should use some frameworks like Express'
    });

    done();
  });

  it('should list articles', function (done) {
    var articlesCount = 10, articlesIndex = 10, doneCount = 0;
    while( articlesIndex-- ) {
      new Article({
        title: articlesIndex + ' Another Article Title'
      }).save(function (error, saved) {
        if ( error ) throw error;
        if ( ( ++doneCount ) == articlesCount ) {
          afterSaveAll();
        }
      });
    }
    function afterSaveAll(){
      request(app)
      .get('/api/articles')
      .expect(200, function (errors, res) {
        (res.body.length).should.match(articlesCount);
        done();
      });
    }
  });

  it('should show an article successfully', function (done) {
    article.save();
    request(app)
      .get('/api/articles/' + article._id)
      .expect(200, function (errors, res) {
        res.body.title.should.match(article.title);
        done();
      });
  });

  it('should create an article successfully', function (done) {
    request(app)
      .post('/api/articles')
{'fraction_non_alphanumeric': 0.15629322268326418, 'fraction_numerical': 0.007607192254495159, 'mean_word_length': 2.6527777777777777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1189469', 'n_tokens_mistral': 883, 'n_tokens_neox': 843, 'n_words': 219}