-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
84 lines (72 loc) · 2.32 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var nodemailer = require('nodemailer');
require('./');
var tmpdir = path.join(__dirname, 'tmp', 'nodemailer');
var transport = nodemailer.createTransport('MailPreview', {
dir: tmpdir,
browser: false
});
var email = {
from: "John Lennon <[email protected]>",
to: "Paul McCartney <[email protected]>, George Harrison <[email protected]>",
cc: "Ringo Starr <[email protected]>",
bcc: "Yoko Ono <[email protected]>",
replyTo: "[email protected]",
subject: "Song Idea",
charset: "utf-8",
text: [
"Hey jude, don't make it bad.",
"Take a sad song and make it better.",
"Remember to let her into your heart,",
"Then you can start to make it better."
].join('\n'),
html: [
"<h1>Hey Jude</h1>",
"<p>\nHey jude, don't make it bad.",
"Take a sad song and make it better.",
"Remember to let her into your heart,",
"Then you can start to make it better.\n</p>"
].join('<br>\n')
};
describe('MailPreview', function(){
it('adds itself to nodemailer\'s transports', function(){
assert(nodemailer.Transport.transports.MAILPREVIEW);
});
describe('.sendMail()', function(){
var error, response;
before(function(done){
transport.sendMail(email, function(e, r){
error = e;
response = r;
done();
});
});
after(function(){
try {
// Cleanup files
fs.unlinkSync(response.html);
fs.unlinkSync(response.text);
fs.rmdirSync(path.dirname(response.html));
} catch (e) {
console.error('Could not clean up temporary files');
console.error(e.stack || e);
}
});
it('does not return an error', function(){
assert(error == null);
});
it('returns the details in the response', function(){
assert(response.html && response.text);
});
it('writes the text part of the email to the corresponding file', function(){
var body = fs.readFileSync(response.text, 'utf-8');
assert(body.indexOf("Hey jude, don't make it bad.") >= 0);
});
it('writes the html part of the email to the corresponding file', function(){
var body = fs.readFileSync(response.html, 'utf-8');
assert(body.indexOf("<h1>Hey Jude</h1>") >= 0);
});
});
});