<commit_before>var _ = require('underscore');
var chai = require('chai');
var Goodtables = require('./index');
var request = require('superagent');
var should = require('chai').should();
var spies = require('chai-spies');
var queryString = require('query-string');


chai.use(spies);

describe('Goodtables API wrapper', function() {
  it('throw error if data file is not passed in params', function(done, err) {
    if(err) done(err);

    try {
      (new Goodtables()).run();
    } catch(exception) {
      exception.message.should.be.not.empty;
      exception.message.should.be.a('string');
      done();
      return;
    }

    done('Exception not thrown');
  });

  it('respect passed param for request method', function(done, err) {
    var goodtables;
    var spyGet;
    var spyPost;


    if(err) done(err);

    spyGet = chai.spy.on(request, 'get');
    spyPost = chai.spy.on(request, 'post');
    goodtables = new Goodtables({method: 'get'});

    goodtables.run('data').then(function() {
      goodtables = new Goodtables({method: 'post'});

      goodtables.run('data').then(function() {
        spyGet.should.have.been.called();
        spyPost.should.have.been.called();
        done();
      });
    });

  });

  it('provide default values for all params', function(done, err) {
    var goodtables;
    var spyQuery;


    if(err) done(err);

    goodtables = new Goodtables();

    require('superagent-mock')(request, [{
      callback: function (match, data) {
        _.isEqual(queryString.parse(match[0].split('?')[1]), {
          fail_fast        : 'true',
          format           : 'csv',
          ignore_empty_rows: 'false',
          report_limit     : '1000',
          row_limit        : '20000'
        }).should.be.true;

        done();

        return {text: ''};
      },<commit_msg>Code formatting<commit_after>var _ = require('underscore');
var chai = require('chai');
var Goodtables = require('./index');
var request = require('superagent');
var should = require('chai').should();
var spies = require('chai-spies');
var queryString = require('query-string');


chai.use(spies);

describe('Goodtables API wrapper', function() {
  it('throw error if data file is not passed in params', function(done, err) {
    if(err) done(err);

    try {
      (new Goodtables()).run();
    } catch(exception) {
      exception.message.should.be.not.empty;
      exception.message.should.be.a('string');
      done();
      return;
    }

    done('Exception not thrown');
  });

  it('respect passed param for request method', function(done, err) {
    var goodtables;
    var spyGet;
    var spyPost;


    if(err) done(err);

    spyGet = chai.spy.on(request, 'get');
    spyPost = chai.spy.on(request, 'post');
    goodtables = new Goodtables({method: 'get'});

    goodtables.run('data').then(function() {
      goodtables = new Goodtables({method: 'post'});

      goodtables.run('data').then(function() {
        spyGet.should.have.been.called();
        spyPost.should.have.been.called();
        done();
      });
    });
  });

  it('provide default values for all params', function(done, err) {
    var goodtables;
    var spyQuery;


    if(err) done(err);

    goodtables = new Goodtables();

    require('superagent-mock')(request, [{
      callback: function (match, data) {
        _.isEqual(queryString.parse(match[0].split('?')[1]), {
          fail_fast        : 'true',
          format           : 'csv',
          ignore_empty_rows: 'false',
          report_limit     : '1000',
          row_limit        : '20000'
        }).should.be.true;

        done();

        return {text: ''};
      },
{'fraction_non_alphanumeric': 0.16515775034293553, 'fraction_numerical': 0.006035665294924554, 'mean_word_length': 2.679112008072654, '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': '2551006', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1113, 'n_words': 245}