<commit_before>var assert = require("assert");
var sinon = require("sinon");
var nodeMailer = require("nodemailer");
var SesMailer = require("../SesMailer.js");

//  This is a stub object for the transport object
//  used by nodemailer.
//
//  It's neede by our tests.
var transportStub = function() {
    this.sendMailCalled = 0;
    this.closeCalled = 0;
    this.lastMail = null;
    this.sentError = null;
    this.sentResult = null;
};
transportStub.prototype = {
    sendMail: function(mail, callback) {
        this.sendMailCalled++;
        this.lastMail = mail;
        this.lastCallback = callback;
        if(callback) { callback(this.sentError, this.sentResult); }
    },
    close: function() { this.closeCalled++; },
    getSendMailCalled: function() { return this.sendMailCalled; },
    getCloseCalled: function() { return this.closeCalled; },
    getLastMail: function() { return this.lastMail; },
    getLastCallback: function() { return this.lastCallback; },
    getSentError: function() { return this.sentError; },
    getSentResult: function() { return this.sentResult; },
    setSentError: function(value) { this.sentError = value; },
    setSentResult: function(value) { this.sentResult = value; },

    resetSendMailCalled: function() { this.sendMailCalled = 0; },
    resetCloseCalled: function() { this.closeCalled = 0; }
}

describe('SesMailer', function(){

    describe('#SendMail()', function(){
        var actualAccessKey = null;
        var actualSecretKey = null;
        var transport = new transportStub();
        var createTransportStub = sinon.stub(nodeMailer, "createTransport", function(type, options) {
            actualAccessKey = options.AWSAccessKeyID;
            actualSecretKey = options.AWSSecretKey;
            return transport; 
        });
        var mailer = new SesMailer(nodeMailer);

        beforeEach(function() {
            transport.resetSendMailCalled();
            transport.resetCloseCalled();
        });

        it('An exception should have been thrown if accessKey is null', function(){
            assert.throws(function() { mailer.SendMail(null, "test secret key", { }); }, 'accessKey');
        });
        
        it('An exception should have been thrown if secretKey is null', function() {
            assert.throws(function() { mailer.SendMail("test Access Key", null, { }); }, 'secretKey'); 
        });

        it('An exception should have been thrown if mail is null', function() {
            assert.throws(function() { mailer.SendMail("test access Key", "test secret key", null); }, 'mail');
        });<commit_msg>Test Commit for jenkins<commit_after>var assert = require("assert");
var sinon = require("sinon");
var nodeMailer = require("nodemailer");
var SesMailer = require("../SesMailer.js");

//  This is a stub object for the transport object
//  used by nodemailer.
//
//  It's neede by our tests.
var transportStub = function() {
    this.sendMailCalled = 0;
    this.closeCalled = 0;
    this.lastMail = null;
    this.sentError = null;
    this.sentResult = null;
};
transportStub.prototype = {
    sendMail: function(mail, callback) {
        this.sendMailCalled++;
        this.lastMail = mail;
        this.lastCallback = callback;
        if(callback) { callback(this.sentError, this.sentResult); }
    },
    close: function() { this.closeCalled++; },
    getSendMailCalled: function() { return this.sendMailCalled; },
    getCloseCalled: function() { return this.closeCalled; },
    getLastMail: function() { return this.lastMail; },
    getLastCallback: function() { return this.lastCallback; },
    getSentError: function() { return this.sentError; },
    getSentResult: function() { return this.sentResult; },
    setSentError: function(value) { this.sentError = value; },
    setSentResult: function(value) { this.sentResult = value; },

    resetSendMailCalled: function() { this.sendMailCalled = 0; },
    resetCloseCalled: function() { this.closeCalled = 0; }
}

describe('SesMailer', function(){

    describe('#SendMail()', function(){
        var actualAccessKey = null;
        var actualSecretKey = null;
        var transport = new transportStub();
        var createTransportStub = sinon.stub(nodeMailer, "createTransport", function(type, options) {
            actualAccessKey = options.AWSAccessKeyID;
            actualSecretKey = options.AWSSecretKey;
            return transport; 
        });
        var mailer = new SesMailer(nodeMailer);

        beforeEach(function() {
            transport.resetSendMailCalled();
            transport.resetCloseCalled();
        });

        it('An exception should have been thrown if accessKey is null', function(){
            assert.equal(false,true);
            assert.throws(function() { mailer.SendMail(null, "test secret key", { }); }, 'accessKey');
        });
        
        it('An exception should have been thrown if secretKey is null', function() {
            assert.throws(function() { mailer.SendMail("test Access Key", null, { }); }, 'secretKey'); 
        });

        it('An exception should have been thrown if mail is null', function() {
            assert.throws(function() { mailer.SendMail("test access Key", "test secret key", null); }, 'mail');
        });
{'fraction_non_alphanumeric': 0.1324818909645444, 'fraction_numerical': 0.0015249714067861228, 'mean_word_length': 3.017611026033691, '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': '7213750', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1467, 'n_words': 372}