<commit_before>var should = require('should');
var parseEmail = require('../');

var email = require('./fixtures/email.json');
var emailGroup = require('./fixtures/email-group.json');

describe('parseEmail', function() {


  it('should parse the google email data to a usable object', function(done) {
    parseEmail(email, function(err, data) {
      should(err).equal(null);
      should.exist(data);
      should.exist(data.from.name);
      should.exist(data.from.address);
      should.exist(data.to);
      should.exist(data.to[0]);
      should.exist(data.message);
      should.exist(data.snippet);
      should.exist(data.attachments);

      done();
    });
  });

  it('should correctly parse CCs', function(done) {
    parseEmail(email, function(err, data) {
      should.exist(data.cc);
      should.exist(data.cc[0]);
      should.exist(data.cc[1]);
      should.exist(data.cc[0].address);
      should.exist(data.cc[0].name);
      should(data.cc[0].address).equal('<EMAIL>');
      should(data.cc[0].address).equal('<EMAIL>');

      done();
    });
  });

  it('should correctly parse subject and message', function(done) {
    parseEmail(email, function(err, data) {
      should.exist(data.message);
      should.exist(data.subject);
      should.equal(data.subject, 'Subject here');
      should(data.message).be.type('string');

      done();
    });
  });

  it('should correctly place attachments', function(done) {
    parseEmail(email, function(err, data) {
      should.exist(data.attachments['2']);
      should.exist(data.attachments['2'].filename);
      should(data.attachments['2'].filename).equal('great-websites.md');
      should(data.attachments['2'].attachmentId).equal('SUCHIDHERE');

      done();
    });
  });

  it('should correctly parse to groups', function(done) {
    parseEmail(emailGroup, function(err, data) {
      should.exist(data.to);
      should.exist(data.to[0]);
      should.exist(data.to[1]);
      should.exist(data.to[2]);

      done();
    });
  });

});


describe('parseEmail: Errors', function() {

  it('should return an error if no email', function(done) {
    parseEmail(null, function(err) {
      should.exist(err);
      should.exist(err.message);
      should(err.message).equal('email required');

      done();
    });
  });

  it('should return an error if no email payload', function(done) {
    parseEmail({}, function(err) {
      should.exist(err);
      should.exist(err.message);
      should(err.message).equal('email payload required');

      done();
    });
  });

  it('should return an error if no email headers', function(done) {
    parseEmail({payload: {}}, function(err) {
      should.exist(err);
      should.exist(err.message);
      should(err.message).equal('email headers required');

      done();
    });
  });

});
<commit_msg>add from  + to test<commit_after>var should = require('should');
var parseEmail = require('../');

var email = require('./fixtures/email.json');
var emailGroup = require('./fixtures/email-group.json');

describe('parseEmail', function() {


  it('should parse the google email data to a usable object', function(done) {
    parseEmail(email, function(err, data) {
      // console.log(data);
      should(err).equal(null);
      should.exist(data);
      should.exist(data.from.name);
      should.exist(data.from.address);
      should.exist(data.to);
      should.exist(data.to[0]);
      should.exist(data.message);
      should.exist(data.snippet);
      should.exist(data.attachments);

      done();
    });
  });

  it('should correctly parse CCs', function(done) {
    parseEmail(email, function(err, data) {
      should.exist(data.cc);
      should.exist(data.cc[0]);
      should.exist(data.cc[1]);
      should.exist(data.cc[0].address);
      should.exist(data.cc[0].name);
      should(data.cc[0].address).equal('<EMAIL>');
      should(data.cc[0].address).equal('<EMAIL>');

      done();
    });
  });

  it('should correctly parse subject and message', function(done) {
    parseEmail(email, function(err, data) {
      should.exist(data.message);
      should.exist(data.subject);
      should.equal(data.subject, 'Subject here');
      should(data.message).be.type('string');

      done();
    });
  });

  it('should correctly parse from', function(done) {
    parseEmail(email, function(err, data) {
      should.exist(data.from);
      should.equal(data.from.address, '<EMAIL>');
      should.equal(data.from.name, '<NAME>');

      done();
    });
  });

  it('should correctly parse to', function(done) {
    parseEmail(email, function(err, data) {
      should.exist(data.to);
      should.equal(data.to[0].address, '<EMAIL>');
      should.equal(data.to[0].name, '<NAME>');

      done();
    });
  });

  it('should correctly place attachment ids and filenames', function(done) {
    parseEmail(email, function(err, data) {
      should.exist(data.attachments['2']);
      should.exist(data.attachments['2'].filename);
      should(data.attachments['2'].filename).equal('great-websites.md');
      should(data.attachments['2'].attachmentId).equal('SUCHIDHERE');

      done();
    });
  });

  it('should correctly parse to groups', function(done) {
    parseEmail(emailGroup, function(err, data) {
      should.exist(data.to);
      should.exist(data.to[0]);
      should.exist(data.to[1]);
      should.exist(data.to[2]);

      done();
    });
  });

});


describe('parseEmail: Errors', function() {

  it('should return an error if no email', function(done) {
    parseEmail(null, function(err) {
      should.exist(err);
      should.exist(err.message);
      should(err.message).equal('email required');

      done();
    });
  });

  it('should return an error if no email payload', function(done) {
    parseEmail({}, function(err) {
      should.exist(err);
      should.exist(err.message);
      should(err.message).equal('email payload required');

      done();
    });
  });

  it('should return an error if no email headers', function(done) {
    parseEmail({payload: {}}, function(err) {
      should.exist(err);
      should.exist(err.message);
      should(err.message).equal('email headers required');

      done();
    });
  });

});

{'fraction_non_alphanumeric': 0.18145226211560136, 'fraction_numerical': 0.004830140074062148, 'mean_word_length': 3.1579651941097726, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7339917', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1905, 'n_words': 335}