@@ -7,7 +7,7 @@ require('./');
7
7
8
8
var tmpdir = path . join ( __dirname , 'tmp' , 'nodemailer' ) ;
9
9
var transport = nodemailer . createTransport ( 'MailPreview' , {
10
- dir : tmpdir ,
10
+ dir : tmpdir ,
11
11
browser : false
12
12
} ) ;
13
13
@@ -36,10 +36,49 @@ var email = {
36
36
37
37
describe ( 'MailPreview' , function ( ) {
38
38
39
- it ( 'should add itself to nodemailer\'s transports' , function ( ) {
39
+ it ( 'adds itself to nodemailer\'s transports' , function ( ) {
40
40
assert ( nodemailer . Transport . transports . MAILPREVIEW ) ;
41
41
} ) ;
42
42
43
- // TODO
43
+ describe ( '.sendMail()' , function ( ) {
44
+ var error , response ;
44
45
46
+ before ( function ( done ) {
47
+ transport . sendMail ( email , function ( e , r ) {
48
+ error = e ;
49
+ response = r ;
50
+ done ( ) ;
51
+ } ) ;
52
+ } ) ;
53
+
54
+ after ( function ( ) {
55
+ try {
56
+ // Cleanup files
57
+ fs . unlinkSync ( response . html ) ;
58
+ fs . unlinkSync ( response . text ) ;
59
+ fs . rmdirSync ( path . dirname ( response . html ) ) ;
60
+ } catch ( e ) {
61
+ console . error ( 'Could not clean up temporary files' ) ;
62
+ console . error ( e . stack || e ) ;
63
+ }
64
+ } ) ;
65
+
66
+ it ( 'does not return an error' , function ( ) {
67
+ assert ( error == null ) ;
68
+ } ) ;
69
+
70
+ it ( 'returns the details in the response' , function ( ) {
71
+ assert ( response . html && response . text ) ;
72
+ } ) ;
73
+
74
+ it ( 'writes the text part of the email to the corresponding file' , function ( ) {
75
+ var body = fs . readFileSync ( response . text , 'utf-8' ) ;
76
+ assert ( body . indexOf ( "Hey jude, don't make it bad." ) >= 0 ) ;
77
+ } ) ;
78
+
79
+ it ( 'writes the html part of the email to the corresponding file' , function ( ) {
80
+ var body = fs . readFileSync ( response . html , 'utf-8' ) ;
81
+ assert ( body . indexOf ( "<h1>Hey Jude</h1>" ) >= 0 ) ;
82
+ } ) ;
83
+ } ) ;
45
84
} ) ;
0 commit comments