Permalink
Browse files

Added tests for fromname and toname

  They may seem a bit pedantic but after making a
  mistake these tests will catch and then seeing
  an open pull with the same mistake I'm inclined
  to overdo it a bit.

Also fixed a typo in test.setup
  • Loading branch information...
1 parent cb54bf5 commit 3df4d2c9fdd63303dbea1d41583274e995d9fa50 Kav Latiolais committed May 16, 2012
Showing with 27 additions and 2 deletions.
  1. +6 −0 lib/email.js
  2. +20 −1 test/lib/email.test.js
  3. +1 −1 test/test.setup
View
@@ -38,6 +38,12 @@ function Email(params) {
this.date = params.date || new Date();
this.headers = params.headers || {};
+ if(params.toname != null) {
+ this.toname = params.toname;
+ }
+ if(params.fromname != null) {
+ this.fromname = params.fromname;
+ }
// auto handle calling the constructor for the file handler
this.files = [];
if (params.files) {
View
@@ -52,7 +52,26 @@ describe('Email', function () {
var smtpFormat = email.toSmtpFormat();
expect(smtpFormat.to).to.be.empty;
});
-
+ it("should not set a fromname if one isn't provided", function() {
+ var email = new Email({from: 'test@test.com', subject: 'testing', text: 'testing'});
+ var webFormat = email.toWebFormat();
+ expect(webFormat.fromname).to.be.empty;
+ });
+ it("should set a fromname if one is provided", function() {
+ var email = new Email({from: 'test@test.com', fromname:'Tester T. Testerson', subject: 'testing', text: 'testing'});
+ var webFormat = email.toWebFormat();
+ expect(webFormat.fromname).to.equal('Tester T. Testerson');
+ });
+ it("should not set a toname if one isn't provided", function() {
+ var email = new Email({from: 'test@test.com', subject: 'testing', text: 'testing'});
+ var webFormat = email.toWebFormat();
+ expect(webFormat.toname).to.be.empty;
+ });
+ it("should set a toname if one is provided", function() {
+ var email = new Email({from: 'test@test.com', toname:'Tester T. Testerson', subject: 'testing', text: 'testing'});
+ var webFormat = email.toWebFormat();
+ expect(webFormat.toname).to.equal('Tester T. Testerson');
+ });
describe('files', function() {
it('should support adding attachments via path', function() {
var email = new Email();
View
@@ -2,7 +2,7 @@ var test_setup = {
api_user: '<username>',
api_key: '<password/api_key>',
single_to: '<your_email>',
- multi_to: ['<your_email>, '<another_email>'],
+ multi_to: ['<your_email>', '<another_email>'],
from: '<your_email>'
}
module.exports = test_setup;

0 comments on commit 3df4d2c

Please sign in to comment.