<commit_before>var mercurius = require('../index.js');
var request = require('supertest');
var assert = require('assert');
var fs = require('fs');

describe('mercurius generateBarcode', function() {
  var token;

  before(function(done) {
    mercurius.ready.then(function() {
      request(mercurius.app)
      .post('/register')
      .send({
        machineId: 'machineX',
        endpoint: 'http://localhost:50005',
        key: '',
      })
      .expect(function(res) {
        token = res.body.token;
      })
      .end(done);
    });
  });

  it('generates the correct barcode', function(done) {
    request(mercurius.app)
    .get('/generateBarcode/Marco')
    .send()
    .expect(function(res) {
      assert.equal(res.status, 200);
      var expected = fs.readFileSync('test/Marco.png');
      assert(res.body.equals(expected));
    })
    .end(done);
  });<commit_msg>Test error while generating barcode. Fixes #50<commit_after>var mercurius = require('../index.js');
var request = require('supertest');
var assert = require('assert');
var fs = require('fs');
var bwipjs = require('bwip-js');

describe('mercurius generateBarcode', function() {
  var token;

  before(function(done) {
    mercurius.ready.then(function() {
      request(mercurius.app)
      .post('/register')
      .send({
        machineId: 'machineX',
        endpoint: 'http://localhost:50005',
        key: '',
      })
      .expect(function(res) {
        token = res.body.token;
      })
      .end(done);
    });
  });

  var origToBuffer = bwipjs.toBuffer;
  afterEach(function() {
    bwipjs.toBuffer = origToBuffer;
  });


  it('generates the correct barcode', function(done) {
    request(mercurius.app)
    .get('/generateBarcode/Marco')
    .send()
    .expect(function(res) {
      assert.equal(res.status, 200);
      var expected = fs.readFileSync('test/Marco.png');
      assert(res.body.equals(expected));
    })
    .end(done);
  });

  it('returns 500 when failing to generate the barcode', function(done) {
    bwipjs.toBuffer = function(obj, cb) {
      cb(new Error('Fake error.'));
    };

    request(mercurius.app)
    .get('/generateBarcode/Marco')
    .send()
    .expect(500, done);
  });
{'fraction_non_alphanumeric': 0.17181818181818181, 'fraction_numerical': 0.01090909090909091, 'mean_word_length': 2.8614035087719296, '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': '4583965', 'n_tokens_mistral': 744, 'n_tokens_neox': 718, 'n_words': 129}