<commit_before>'use strict';

var chai = require('chai');
var htmlToText = require('../src/nodemailer-html-to-text').htmlToText;

var expect = chai.expect;
chai.config.includeStack = true;

describe('nodemailer-html-to-text tests', function() {

    it('should set text from html string', function(done) {
        var plugin = htmlToText();
        var mail = {
            data: {
                html: '<p>Tere, tere</p><p>vana kere!</p>'
            },
            resolveContent: function(obj, key, cb) {
                cb(null, obj[key]);
            }
        };
        plugin(mail, function(err) {
            expect(err).to.not.exist;
            expect(mail.data.text).to.equal(
                'Tere, tere\n\nvana kere!'
            );
            done();
        });
    });

    it('should remove the inlined picture reference including the empty space behind a line break', function(done) {
        var plugin = htmlToText();
        var mail = {
            data: {
                html: '<p>Tere, tere</p><p><img src="cid:nodemailerLogo"/>vana kere!</p>'
            },
            resolveContent: function(obj, key, cb) {
                cb(null, obj[key]);
            }
        };
        plugin(mail, function(err) {
            expect(err).to.not.exist;
            expect(mail.data.text).to.equal(
                'Tere, tere\n\nvana kere!'
            );
            done();
        });
    });

    it('should remove the inlined picture reference and keep the empty space without line break', function(done) {
        var plugin = htmlToText();
        var mail = {
            data: {
                html: '<p>Tere,<img src="cid:nodemailerLogo"/> tere</p><p>vana kere!</p>'
            },
            resolveContent: function(obj, key, cb) {
                cb(null, obj[key]);
            }
        };
        plugin(mail, function(err) {
            expect(err).to.not.exist;
            expect(mail.data.text).to.equal(
                'Tere, tere\n\nvana kere!'
            );
            done();
        });
    });

    it('should set text from html buffer', function(done) {
        var plugin = htmlToText();
        var mail = {
            data: {
                html: Buffer.from('<p>Tere, tere</p><p>vana kere!</p>')
            },
            resolveContent: function(obj, key, cb) {
                cb(null, obj[key]);
            }
        };
        plugin(mail, function(err) {
            expect(err).to.not.exist;
            expect(mail.data).to.deep.equal({
                html: Buffer.from('<p>Tere, tere</p><p>vana kere!</p>'),
                text: 'Tere, tere\n\nvana kere!'
            });
            done();
        });
    });

    it('should return an error', function(done) {
        var plugin = htmlToText();
        var mail = {<commit_msg>Reverted Buffer.from it's not compatible with node 4<commit_after>'use strict';

var chai = require('chai');
var htmlToText = require('../src/nodemailer-html-to-text').htmlToText;

var expect = chai.expect;
chai.config.includeStack = true;

describe('nodemailer-html-to-text tests', function() {

    it('should set text from html string', function(done) {
        var plugin = htmlToText();
        var mail = {
            data: {
                html: '<p>Tere, tere</p><p>vana kere!</p>'
            },
            resolveContent: function(obj, key, cb) {
                cb(null, obj[key]);
            }
        };
        plugin(mail, function(err) {
            expect(err).to.not.exist;
            expect(mail.data.text).to.equal(
                'Tere, tere\n\nvana kere!'
            );
            done();
        });
    });

    it('should remove the inlined picture reference including the empty space behind a line break', function(done) {
        var plugin = htmlToText();
        var mail = {
            data: {
                html: '<p>Tere, tere</p><p><img src="cid:nodemailerLogo"/>vana kere!</p>'
            },
            resolveContent: function(obj, key, cb) {
                cb(null, obj[key]);
            }
        };
        plugin(mail, function(err) {
            expect(err).to.not.exist;
            expect(mail.data.text).to.equal(
                'Tere, tere\n\nvana kere!'
            );
            done();
        });
    });

    it('should remove the inlined picture reference and keep the empty space without line break', function(done) {
        var plugin = htmlToText();
        var mail = {
            data: {
                html: '<p>Tere,<img src="cid:nodemailerLogo"/> tere</p><p>vana kere!</p>'
            },
            resolveContent: function(obj, key, cb) {
                cb(null, obj[key]);
            }
        };
        plugin(mail, function(err) {
            expect(err).to.not.exist;
            expect(mail.data.text).to.equal(
                'Tere, tere\n\nvana kere!'
            );
            done();
        });
    });

    it('should set text from html buffer', function(done) {
        var plugin = htmlToText();
        var mail = {
            data: {
                html: new Buffer('<p>Tere, tere</p><p>vana kere!</p>')
            },
            resolveContent: function(obj, key, cb) {
                cb(null, obj[key]);
            }
        };
        plugin(mail, function(err) {
            expect(err).to.not.exist;
            expect(mail.data).to.deep.equal({
                html: new Buffer('<p>Tere, tere</p><p>vana kere!</p>'),
                text: 'Tere, tere\n\nvana kere!'
            });
            done();
        });
    });

    it('should return an error', function(done) {
        var plugin = htmlToText();
        var mail = {
{'fraction_non_alphanumeric': 0.14992025518341306, 'fraction_numerical': 0.000177210703526493, 'mean_word_length': 1.534351145038168, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '4537574', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1676, 'n_words': 355}