<commit_before>'use strict';

var Promise = require('bluebird');
var redis = require('redis');
var childProcess = Promise.promisifyAll(require('child_process'), {
  multiArgs: true
});
var assert = require('chai').assert;
var fantastiq = require('..');

describe('cli', function () {
  this.timeout(10000);

  var client = redis.createClient({
    host: process.env.REDIS_HOST
  });
  var queue = fantastiq(client);

  it('should add a job', function () {
    return childProcess.execAsync(`fantastiq -r tcp://${process.env.REDIS_HOST}:6379 add -j job-1`)
      .spread(function (stdout) {
        var id = stdout;
        return queue.get(id);
      })
      .then(function (job) {
        assert.ok(job);
        assert.propertyVal(job, 'data', 'job-1');
        assert.propertyVal(job, 'priority', 0);
      });
  });

  it('should add a json job', function () {
    return childProcess.execAsync(`fantastiq -r tcp://${process.env.REDIS_HOST}:6379 add -j '{"hello": "world"}'`)
      .spread(function (stdout) {
        var id = stdout;
        return queue.get(id);
      })
      .then(function (job) {
        assert.ok(job);
        assert.deepEqual(job.data, {hello: 'world'});
      });
  });

  it('should add multiple jobs', function () {
    return childProcess.execAsync(`fantastiq -r tcp://${process.env.REDIS_HOST}:6379 add -j job-2 -j='-3' -j '{"job": 4}'`)
      .spread(function (stdout) {
        var ids = stdout.split(/\s/);
        return queue.getN(ids);
      })
      .spread(function (job1, job2, job3) {
        assert.ok(job1);
        assert.ok(job2);
        assert.ok(job3);
        assert.propertyVal(job1, 'data', 'job-2');
        assert.propertyVal(job2, 'data', -3);
        assert.deepEqual(job3.data, {job: 4});
      });
  });

  it('should add jobs from stdin', function () {
    return childProcess.execAsync(`printf "job-5\\n{\\"job\\": 6}\\njob-7" | fantastiq -r tcp://${process.env.REDIS_HOST}:6379 add`)
      .spread(function (stdout) {
        var ids = stdout.split(/\s/);
        return queue.getN(ids);
      })
      .spread(function (job1, job2, job3) {
        assert.ok(job1);
        assert.ok(job2);
        assert.ok(job3);
        assert.propertyVal(job1, 'data', 'job-5');
        assert.deepEqual(job2.data, {job: 6});
        assert.propertyVal(job3, 'data', 'job-7');
      });
  });

  it('should use batch size', function () {
    return childProcess.execAsync(`printf "a\\nb\\nc\\nd\\ne" | fantastiq -r tcp://${process.env.REDIS_HOST}:6379 add -b 2`)
      .spread(function (stdout) {
        var ids = stdout.split(/\s/);
        return queue.getN(ids);
      })
      .then(function (jobs) {
        assert.deepEqual(jobs.map(function (job) {
          return job.data;
        }), ['a', 'b', 'c', 'd', 'e']);
      });
  });

  it('should add a job with priority', function () {
    return childProcess.execAsync(`fantastiq -r tcp://${process.env.REDIS_HOST}:6379 add -j job-8 -p 15`)
      .spread(function (stdout) {
        var id = stdout;
        return queue.get(id);
      })
      .then(function (job) {
        assert.ok(job);
        assert.propertyVal(job, 'data', 'job-8');
        assert.propertyVal(job, 'priority', 15);
      });
  });

  it('should get a job', function () {
    return queue.add('the-job')
      .then(function (id) {
        return childProcess.execAsync(`fantastiq -r tcp://${process.env.REDIS_HOST}:6379 get ${id}`);
      })
      .spread(function (stdout) {
        var job = JSON.parse(stdout);
        assert.propertyVal(job, 'data', 'the-job');
      });
  });

});<commit_msg>fix missing env var on travis<commit_after>'use strict';

var Promise = require('bluebird');
var redis = require('redis');
var childProcess = Promise.promisifyAll(require('child_process'), {
  multiArgs: true
});
var assert = require('chai').assert;
var fantastiq = require('..');

var REDIS_HOST = process.env.REDIS_HOST || '127.0.0.1';

describe('cli', function () {
  this.timeout(10000);

  var client = redis.createClient({
    host: REDIS_HOST
  });
  var queue = fantastiq(client);

  it('should add a job', function () {
    return childProcess.execAsync(`fantastiq -r tcp://${REDIS_HOST}:6379 add -j job-1`)
      .spread(function (stdout) {
        var id = stdout;
        return queue.get(id);
      })
      .then(function (job) {
        assert.ok(job);
        assert.propertyVal(job, 'data', 'job-1');
        assert.propertyVal(job, 'priority', 0);
      });
  });

  it('should add a json job', function () {
    return childProcess.execAsync(`fantastiq -r tcp://${REDIS_HOST}:6379 add -j '{"hello": "world"}'`)
      .spread(function (stdout) {
        var id = stdout;
        return queue.get(id);
      })
      .then(function (job) {
        assert.ok(job);
        assert.deepEqual(job.data, {hello: 'world'});
      });
  });

  it('should add multiple jobs', function () {
    return childProcess.execAsync(`fantastiq -r tcp://${REDIS_HOST}:6379 add -j job-2 -j='-3' -j '{"job": 4}'`)
      .spread(function (stdout) {
        var ids = stdout.split(/\s/);
        return queue.getN(ids);
      })
      .spread(function (job1, job2, job3) {
        assert.ok(job1);
        assert.ok(job2);
        assert.ok(job3);
        assert.propertyVal(job1, 'data', 'job-2');
        assert.propertyVal(job2, 'data', -3);
        assert.deepEqual(job3.data, {job: 4});
      });
  });

  it('should add jobs from stdin', function () {
    return childProcess.execAsync(`printf "job-5\\n{\\"job\\": 6}\\njob-7" | fantastiq -r tcp://${REDIS_HOST}:6379 add`)
      .spread(function (stdout) {
        var ids = stdout.split(/\s/);
        return queue.getN(ids);
      })
      .spread(function (job1, job2, job3) {
        assert.ok(job1);
        assert.ok(job2);
        assert.ok(job3);
        assert.propertyVal(job1, 'data', 'job-5');
        assert.deepEqual(job2.data, {job: 6});
        assert.propertyVal(job3, 'data', 'job-7');
      });
  });

  it('should use batch size', function () {
    return childProcess.execAsync(`printf "a\\nb\\nc\\nd\\ne" | fantastiq -r tcp://${REDIS_HOST}:6379 add -b 2`)
      .spread(function (stdout) {
        var ids = stdout.split(/\s/);
        return queue.getN(ids);
      })
      .then(function (jobs) {
        assert.deepEqual(jobs.map(function (job) {
          return job.data;
        }), ['a', 'b', 'c', 'd', 'e']);
      });
  });

  it('should add a job with priority', function () {
    return childProcess.execAsync(`fantastiq -r tcp://${REDIS_HOST}:6379 add -j job-8 -p 15`)
      .spread(function (stdout) {
        var id = stdout;
        return queue.get(id);
      })
      .then(function (job) {
        assert.ok(job);
        assert.propertyVal(job, 'data', 'job-8');
        assert.propertyVal(job, 'priority', 15);
      });
  });

  it('should get a job', function () {
    return queue.add('the-job')
      .then(function (id) {
        return childProcess.execAsync(`fantastiq -r tcp://${REDIS_HOST}:6379 get ${id}`);
      })
      .spread(function (stdout) {
        var job = JSON.parse(stdout);
        assert.propertyVal(job, 'data', 'the-job');
      });
  });

});
{'fraction_non_alphanumeric': 0.18757868233319344, 'fraction_numerical': 0.02126171492516436, 'mean_word_length': 2.4878048780487805, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '2175941', 'n_tokens_mistral': 2507, 'n_tokens_neox': 2398, 'n_words': 505}