summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorelbuo8 <yamil.asusta@sendgrid.com>2014-12-09 18:46:08 -0400
committerelbuo8 <yamil.asusta@sendgrid.com>2014-12-09 18:46:08 -0400
commitc61fa29ad2fbffcbecd73e7492037c316ca5c2bb (patch)
treefebfffffa1898d59bfdf6e4fa170af340049c5e9
parent92688d09c0320a0c1392839db4f87688a17be357 (diff)
parent57bc8892cb4d84af8692a80f44c2fc379cd88ec1 (diff)
downloadsendgrid-nodejs-c61fa29ad2fbffcbecd73e7492037c316ca5c2bb.zip
sendgrid-nodejs-c61fa29ad2fbffcbecd73e7492037c316ca5c2bb.tar.gz
sendgrid-nodejs-c61fa29ad2fbffcbecd73e7492037c316ca5c2bb.tar.bz2
Merge branch 'bsorin-Support-CC'
-rw-r--r--README.md22
-rw-r--r--lib/email.js10
-rw-r--r--test/integration/sendgrid.test.js16
-rw-r--r--test/lib/email.test.js54
4 files changed, 93 insertions, 9 deletions
diff --git a/README.md b/README.md
index 337baaf..80fbebc 100644
--- a/README.md
+++ b/README.md
@@ -123,6 +123,7 @@ var params = {
text: '',
html: '',
bcc: [],
+ cc: [],
replyto: '',
date: new Date(),
files: [
@@ -175,6 +176,27 @@ email.setFrom('foo@bar.com');
sendgrid.send(email, function(err, json) { });
```
+#### addCc
+
+You can add one or multiple CC addresses using `addCc`.
+
+```javascript
+var email = new sendgrid.Email();
+email.addCc('foo@bar.com');
+email.addCc('another@another.com');
+sendgrid.send(email, function(err, json) { });
+```
+
+#### setCcs
+
+You can multiple CC addresses using `setCcs`.
+
+```javascript
+var email = new sendgrid.Email();
+email.setCcs(['foo@bar.com', 'another@another.com');
+sendgrid.send(email, function(err, json) { });
+```
+
#### setSubject
```javascript
diff --git a/lib/email.js b/lib/email.js
index 27880fa..701da9d 100644
--- a/lib/email.js
+++ b/lib/email.js
@@ -16,6 +16,7 @@ function Email(params) {
this.text = params.text || '';
this.html = params.html || '';
this.bcc = params.bcc || [];
+ this.cc = params.cc || [];
this.replyto = params.replyto || '';
this.date = params.date || new Date();
this.headers = params.headers || {};
@@ -67,6 +68,14 @@ Email.prototype.setFrom = function(from) {
this.from = from;
};
+Email.prototype.addCc = function(cc) {
+ this.cc.push(cc);
+};
+
+Email.prototype.setCcs = function(cc) {
+ this.cc = cc;
+};
+
Email.prototype.setSubject = function(subject) {
this.subject = subject;
};
@@ -136,6 +145,7 @@ Email.prototype.toWebFormat = function() {
};
if (this.bcc) { web.bcc = this.bcc; }
+ if (this.cc) { web.cc = this.cc; }
if (this.html) { web.html = this.html; }
if (this.toname) { web.toname = this.toname; }
if (this.fromname) { web.fromname = this.fromname; }
diff --git a/test/integration/sendgrid.test.js b/test/integration/sendgrid.test.js
index 4182cbe..18b8ad7 100644
--- a/test/integration/sendgrid.test.js
+++ b/test/integration/sendgrid.test.js
@@ -51,6 +51,7 @@ describe('SendGrid #skip', function () {
sendgrid.send(payload, function(err, json) {
expect(err).to.be.null;
+ expect(json.message).to.equal('success');
done();
});
@@ -62,6 +63,7 @@ describe('SendGrid #skip', function () {
sendgrid.send(payload, function(err, json) {
expect(err).to.be.null;
+ expect(json.message).to.equal('success');
done();
});
@@ -76,6 +78,7 @@ describe('SendGrid #skip', function () {
sendgrid.send(email, function(err, json) {
expect(err).to.be.null;
+ expect(json.message).to.equal('success');
done();
});
@@ -87,6 +90,19 @@ describe('SendGrid #skip', function () {
sendgrid.send(payload, function(err, json) {
expect(err).to.be.null;
+ expect(json.message).to.equal('success');
+
+ done();
+ });
+ });
+
+ it('has array of CCs', function(done) {
+ payload.subject += "has array of CCs";
+ payload.cc = ['sendgrid-nodejs@mailinator.com']
+
+ sendgrid.send(payload, function(err, json) {
+ expect(err).to.be.null;
+ expect(json.message).to.equal('success');
done();
});
diff --git a/test/lib/email.test.js b/test/lib/email.test.js
index 57f6ced..e5aab66 100644
--- a/test/lib/email.test.js
+++ b/test/lib/email.test.js
@@ -11,7 +11,7 @@ var default_payload = {
var files = [
__dirname + '/../assets/logo.png',
__dirname + '/../assets/sendgrid.txt'
-]
+];
describe('Email', function () {
it('should allow attributes to be set in the constructor', function() {
@@ -66,6 +66,15 @@ describe('Email', function () {
expect(format.bcc).to.equal(payload.bcc);
});
+ it('should have multiple CCs if as an array', function() {
+ var payload = Object.create(default_payload);
+ payload.cc = ['david.tomberlin@sendgrid.com', 'otherguy@sendgrid.com'];
+ var email = new Email(payload);
+ var format = email.toWebFormat();
+
+ expect(format.cc).to.equal(payload.cc);
+ });
+
it('should not have a field for undefined file', function() {
var payload = Object.create(default_payload);
var email = new Email(payload);
@@ -81,11 +90,11 @@ describe('Email', function () {
});
it('should not have a field for undefined file even with Array prototype overridden', function() {
-
- Array.prototype['testMethod'] = function() {
+
+ Array.prototype.testMethod = function() {
return 'testMethod';
};
-
+
var payload = Object.create(default_payload);
var email = new Email(payload);
var format = email.toWebFormat();
@@ -98,10 +107,10 @@ describe('Email', function () {
expect(format.toname).to.be.empty;
expect(format['files[undefined]']).to.be.undefined;
});
-
+
it('should not have a to address if there is no to or no smtpapi.', function() {
var payload = Object.create(default_payload);
- var email = new Email({from: 'test@test.com', subject: 'testing', text: 'testing'});
+ var email = new Email({from: 'test@test.com', subject: 'testing', text: 'testing'});
var format = email.toWebFormat();
expect(format.to).to.be.empty;
});
@@ -114,7 +123,7 @@ describe('Email', function () {
var format = email.toWebFormat();
expect(JSON.parse(format['x-smtpapi']).to).to.not.be.empty;
- expect(format.to).to.not.be.empty;
+ expect(format.to).to.not.be.empty;
});
it("should set a fromname if one is provided", function() {
@@ -198,6 +207,33 @@ describe('Email', function () {
expect(email.smtpapi.header.unique_args).to.eql({unique_arg1: 'value', unique_arg2: 'value'});
});
+ it('should be possible to addCc', function() {
+ var email = new Email();
+ expect(email.cc).to.eql([]);
+ email.addCc('sorin@domain.com');
+ expect(email.cc).to.eql(['sorin@domain.com']);
+ email.addCc('sorin2@domain.com');
+ expect(email.cc).to.eql(['sorin@domain.com', 'sorin2@domain.com']);
+ });
+
+ it('should be possible to setCcs', function() {
+ var email = new Email();
+ expect(email.cc).to.eql([]);
+ email.setCcs(['sorin@domain.com']);
+ expect(email.cc).to.eql(['sorin@domain.com']);
+ email.setCcs(['sorin2@domain.com']);
+ expect(email.cc).to.eql(['sorin2@domain.com']);
+ });
+
+ it('should be possible to setCcs and addCc', function() {
+ var email = new Email();
+ expect(email.cc).to.eql([]);
+ email.setCcs(['sorin@domain.com']);
+ expect(email.cc).to.eql(['sorin@domain.com']);
+ email.addCc('sorin2@domain.com');
+ expect(email.cc).to.eql(['sorin@domain.com', 'sorin2@domain.com']);
+ });
+
describe('files', function() {
it('should support adding attachments via path', function() {
var email = new Email();
@@ -335,8 +371,8 @@ describe('Email', function () {
it('should be able to add filters', function(done) {
var email = new Email();
- email.addFilter('subscriptiontrack', 'enable', 1)
- email.addFilter('subscriptiontrack', "text/plain", "If you would like to unsubscribe and stop receiving these emails click here: <% %>.")
+ email.addFilter('subscriptiontrack', 'enable', 1);
+ email.addFilter('subscriptiontrack', "text/plain", "If you would like to unsubscribe and stop receiving these emails click here: <% %>.");
expect(email.smtpapi.jsonString()).to.eql("{\"filters\":{\"subscriptiontrack\":{\"settings\":{\"enable\":1,\"text/plain\":\"If you would like to unsubscribe and stop receiving these emails click here: <% %>.\"}}}}");