diff options
author | Sorin Baba <sorin.baba@sendgrid.com> | 2014-12-17 22:19:55 +0200 |
---|---|---|
committer | Sorin Baba <sorin.baba@sendgrid.com> | 2014-12-17 23:14:55 +0200 |
commit | 6a573a11e15edf140b8f7bc6b5a76d71ba2ff08e (patch) | |
tree | 58bde0c33c64f53e86f48846209172d650714580 | |
parent | 6437cd1caf39c5dfe92110a8de437821bcd7b073 (diff) | |
download | sendgrid-nodejs-6a573a11e15edf140b8f7bc6b5a76d71ba2ff08e.zip sendgrid-nodejs-6a573a11e15edf140b8f7bc6b5a76d71ba2ff08e.tar.gz sendgrid-nodejs-6a573a11e15edf140b8f7bc6b5a76d71ba2ff08e.tar.bz2 |
Fix: The date is not sent
-rw-r--r-- | README.md | 14 | ||||
-rw-r--r-- | lib/email.js | 8 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | test/integration/sendgrid.test.js | 12 | ||||
-rw-r--r-- | test/lib/email.test.js | 19 | ||||
-rw-r--r-- | test/lib/sendgrid.test.js | 2 |
6 files changed, 50 insertions, 7 deletions
@@ -29,7 +29,7 @@ Add the following to your `package.json` file: ... "dependencies": { ... - "sendgrid": "1.3.0" + "sendgrid": "1.5.0" } } ``` @@ -125,7 +125,7 @@ var params = { bcc: [], cc: [], replyto: '', - date: new Date(), + date: '', files: [ { filename: '', // required only if file.content is used. @@ -221,11 +221,19 @@ email.setHtml('<h1>Some html</h1>'); sendgrid.send(email, function(err, json) { }); ``` +#### setDate + +```javascript +var email = new sendgrid.Email(); +email.setDate('Wed, 17 Dec 2014 19:21:16 +0000'); +sendgrid.send(email, function(err, json) { }); +``` + #### setSendAt ```javascript var email = new sendgrid.Email(); -email.setSendAt(1409348513'); +email.setSendAt(1409348513); sendgrid.send(email, function(err, json) { }); ``` diff --git a/lib/email.js b/lib/email.js index 4b1c933..83c6d08 100644 --- a/lib/email.js +++ b/lib/email.js @@ -18,7 +18,7 @@ function Email(params) { this.bcc = params.bcc || []; this.cc = params.cc || []; this.replyto = params.replyto || ''; - this.date = params.date || new Date(); + this.date = params.date || ''; this.headers = params.headers || {}; if(params.toname !== null) { @@ -120,7 +120,6 @@ Email.prototype.setSections = function(object_literal) { this.smtpapi.setSections(object_literal); }; - Email.prototype.addFilter = function(filter, setting, val) { this.smtpapi.addFilter(filter, setting, val); }; @@ -133,6 +132,10 @@ Email.prototype.addFile = function(file_object) { this.files.push(new FileHandler(file_object)); }; +Email.prototype.setDate = function(date) { + this.date = date; +}; + Email.prototype.setSendAt = function(send_at) { this.smtpapi.setSendAt(send_at); }; @@ -162,6 +165,7 @@ Email.prototype.toWebFormat = function() { if (this.toname) { web.toname = this.toname; } if (this.fromname) { web.fromname = this.fromname; } if (this.replyto) { web.replyto = this.replyto; } + if (this.date) { web.date = this.date; } if (this.smtpapi.to && this.smtpapi.to.length) { web.to = ""; } this.updateMissingTo(web); diff --git a/package.json b/package.json index 3c5053a..e2e43ef 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ ], "name": "sendgrid", "description": "Official SendGrid NodeJS library.", - "version": "1.4.0", + "version": "1.5.0", "homepage": "http://sendgrid.com", "repository": { "type": "git", diff --git a/test/integration/sendgrid.test.js b/test/integration/sendgrid.test.js index 53c7a90..2fa871b 100644 --- a/test/integration/sendgrid.test.js +++ b/test/integration/sendgrid.test.js @@ -357,6 +357,18 @@ describe('SendGrid #skip', function () { }); }); + it('handles the date param', function(done) { + payload.subject += "handles the date param"; + + var email = new Email(payload); + email.setDate('Wed, 17 Dec 2014 19:21:16 +0000'); + sendgrid.send(email, function(err, json) { + expect(err).to.be.null; + expect(json.message).to.equal('success'); + done(); + }); + }); + it('handles the send_at scheduling param', function(done) { payload.subject += "handles the send_at scheduling param"; diff --git a/test/lib/email.test.js b/test/lib/email.test.js index 20f99ca..549ad61 100644 --- a/test/lib/email.test.js +++ b/test/lib/email.test.js @@ -134,6 +134,18 @@ describe('Email', function () { expect(format.fromname).to.equal('Tester T. Testerson'); }); + it("should set a date if one is provided", function() { + var payload = Object.create(default_payload); + var email = new Email({from: 'test@test.com', fromname:'Tester T. Testerson', subject: 'testing', text: 'testing', date: 'Wed, 17 Dec 2014 19:21:16 +0000'}); + var format = email.toWebFormat(); + + expect(format.date).to.equal('Wed, 17 Dec 2014 19:21:16 +0000'); + + email.setDate('Wed, 17 Dec 2013 19:21:16 +0000'); + format = email.toWebFormat(); + expect(format.date).to.equal('Wed, 17 Dec 2013 19:21:16 +0000'); + }); + it("should set a toname if one is provided", function() { var payload = Object.create(default_payload); var email = new Email({from: 'test@test.com', to:'test@test.com', toname:'Tester T. Testerson', subject: 'testing', text: 'testing'}); @@ -189,6 +201,13 @@ describe('Email', function () { expect(email.smtpapi.header.unique_args).to.eql({unique_arg1: 'value', unique_arg2: 'value'}); }); + it('should be possible to setDate', function() { + var email = new Email(); + expect(email.date).to.be.empty; + email.setDate('Wed, 17 Dec 2014 19:21:16 +0000'); + expect(email.date).to.eql('Wed, 17 Dec 2014 19:21:16 +0000'); + }); + it('should be possible to setSendAt', function() { var email = new Email(); expect(email.smtpapi.header.send_at).to.be.empty; diff --git a/test/lib/sendgrid.test.js b/test/lib/sendgrid.test.js index 218660f..8ddfea2 100644 --- a/test/lib/sendgrid.test.js +++ b/test/lib/sendgrid.test.js @@ -15,7 +15,7 @@ describe('SendGrid', function () { }); it('version should be set', function() { - expect(sendgrid.version).to.equal("1.4.0"); + expect(sendgrid.version).to.equal("1.5.0"); }); it('should attach a options object to self', function() { |