-
Notifications
You must be signed in to change notification settings - Fork 30
Attachments support #36
base: master
Are you sure you want to change the base?
Changes from 6 commits
dfd7238
2f79706
fd9d5c6
4e0832a
602ee3c
a911282
518d131
6da1d06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^2.4.5", | ||
"nodemailer": "^2.2.1", | ||
"sinon": "^1.17.3" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
'use strict'; | ||
|
||
var sinon = require('sinon'); | ||
var expect = require('chai').expect; | ||
|
||
var mandrillTransport = require('../'); | ||
|
||
var packageData = require('../package.json'); | ||
var sinon = require('sinon'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sry for changing the project style, just happened out of habit |
||
expect = require('chai').expect, | ||
mandrillTransport = require('../'), | ||
packageData = require('../package.json'); | ||
|
||
describe('MandrillTransport', function() { | ||
it('should expose name and version', function() { | ||
|
@@ -14,7 +12,7 @@ describe('MandrillTransport', function() { | |
expect(transport.version).to.equal(packageData.version); | ||
}); | ||
|
||
describe('#send', function(done) { | ||
describe('#send', function() { | ||
var transport = mandrillTransport(); | ||
var client = transport.mandrillClient; | ||
|
||
|
@@ -165,4 +163,71 @@ describe('MandrillTransport', function() { | |
}); | ||
}); | ||
}); | ||
|
||
describe('#send attachments usage', function() { | ||
var nodemailer = require('nodemailer'), | ||
transport = mandrillTransport(), | ||
client = transport.mandrillClient, | ||
wrappedTransport = nodemailer.createTransport(transport), | ||
sendOptions; | ||
|
||
before(function() { | ||
sinon.stub(client.messages, 'send', function(options, cb) { | ||
sendOptions = options; | ||
cb([]); | ||
}); | ||
}); | ||
|
||
beforeEach(function() { | ||
sendOptions = {}; | ||
}); | ||
|
||
after(function() { | ||
client.messages.send.restore(); | ||
}); | ||
|
||
it('attachments object', function(done) { | ||
wrappedTransport.sendMail({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont merge yet, i thought of something that needs to be tested: i should call sendMail with full details (from, to etc...) and make sure that it doesn't somehow interfere with the attachments logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done already. |
||
attachments: [ | ||
{ | ||
filename: 'bufferIsABase64.txt', | ||
content: new Buffer('hello world!', 'utf-8') | ||
}, | ||
{ | ||
filename: 'text.csv', | ||
content: new Buffer('hello;world!\n1;2','utf-8'), | ||
contentType: 'text/csv' | ||
}, | ||
{ | ||
filename: 'encoded.txt', | ||
content: new Buffer('i am base64', 'utf-8').toString('base64'), | ||
encoding: 'base64' | ||
}, | ||
{ // data uri as an attachment | ||
path: 'data:text/plain;base64,' + new Buffer('HELLOWORLD', 'utf-8').toString('base64') | ||
} | ||
] | ||
}, function(err) { | ||
expect(err).to.be.null; | ||
expect(sendOptions.message.attachments).to.have.lengthOf(4); | ||
|
||
expect(sendOptions.message.attachments[0].name).to.equal('bufferIsABase64.txt'); | ||
expect(sendOptions.message.attachments[0].type).to.equal('text/plain'); | ||
expect(new Buffer(sendOptions.message.attachments[0].content, 'base64').toString('utf-8')).to.equal('hello world!'); | ||
|
||
expect(sendOptions.message.attachments[1].name).to.equal('text.csv'); | ||
expect(sendOptions.message.attachments[1].type).to.equal('text/csv'); | ||
expect(new Buffer(sendOptions.message.attachments[1].content, 'base64').toString('utf-8')).to.equal('hello;world!\n1;2'); | ||
|
||
expect(sendOptions.message.attachments[2].name).to.equal('encoded.txt'); | ||
expect(sendOptions.message.attachments[2].type).to.equal('text/plain'); | ||
expect(new Buffer(sendOptions.message.attachments[2].content, 'base64').toString('utf-8')).to.equal('i am base64'); | ||
|
||
expect(sendOptions.message.attachments[3].name).to.equal('attachment-4.txt'); | ||
expect(sendOptions.message.attachments[3].type).to.equal('text/plain'); | ||
expect(new Buffer(sendOptions.message.attachments[3].content, 'base64').toString('utf-8')).to.equal('HELLOWORLD'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[].find
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there could be multiple attachments, so find wont fit.
can use filter for that though, will give it a quick try and if good will push it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually find should work, just noticed now this happens in the forEach of child nodes.
will use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried it and it failed for me, im running node 0.10.x, on which Array.prototype.find is not available.
i use nvm, so tried changing to nodejs 4.x and worked there.
but for sake of compatibility i left code as is, your'e welcome to refactor if you want to.