@@ -4,21 +4,13 @@ var testUtils = require('../../utils'),
44 should = require ( 'should' ) ,
55 config = require ( '../../../server/config' ) ,
66 mailer = require ( '../../../server/mail' ) ,
7- i18n = require ( '../../../../core/server/i18n' ) ,
7+ i18n = require ( '../../../../core/server/i18n' ) ,
88
99 // Stuff we are testing
1010 MailAPI = require ( '../../../server/api/mail' ) ,
11- mailDataNoDomain = {
12- mail : [ {
13- message : {
14- to : 'joe@doesntexistexample091283zalgo.com' ,
15- subject : 'testemail' ,
16- html : '<p>This</p>'
17- } ,
18- options : { }
19- } ]
20- } ,
21- mailDataNoServer = {
11+
12+ // test data
13+ mailData = {
2214 mail : [ {
2315 message : {
2416 to : 'joe@example.com' ,
@@ -27,15 +19,6 @@ var testUtils = require('../../utils'),
2719 } ,
2820 options : { }
2921 } ]
30- } ,
31- mailDataIncomplete = {
32- mail : [ {
33- message : {
34- subject : 'testemail' ,
35- html : '<p>This</p>'
36- } ,
37- options : { }
38- } ]
3922 } ;
4023i18n . init ( ) ;
4124
@@ -46,106 +29,34 @@ describe('Mail API', function () {
4629
4730 should . exist ( MailAPI ) ;
4831
49- describe ( 'Nothing configured' , function ( ) {
50- it ( 'return no email configured' , function ( done ) {
51- MailAPI . send ( mailDataNoServer , testUtils . context . internal ) . then ( function ( response ) {
52- /*jshint unused:false */
53- done ( ) ;
54- } ) . catch ( function ( error ) {
55- error . message . should . eql ( 'Error: No email transport configured.' ) ;
56- error . errorType . should . eql ( 'EmailError' ) ;
57- done ( ) ;
58- } ) . catch ( done ) ;
59- } ) ;
60-
61- it ( 'return no email configured even when sending incomplete data' , function ( done ) {
62- MailAPI . send ( mailDataIncomplete , testUtils . context . internal ) . then ( function ( response ) {
63- /*jshint unused:false */
64- done ( ) ;
65- } ) . catch ( function ( error ) {
66- error . message . should . eql ( 'Error: No email transport configured.' ) ;
67- error . errorType . should . eql ( 'EmailError' ) ;
68- done ( ) ;
69- } ) . catch ( done ) ;
70- } ) ;
71- } ) ;
72-
73- describe ( 'Mail API Direct' , function ( ) {
74- before ( function ( done ) {
75- config . set ( { mail : { } } ) ;
32+ it ( 'returns a success' , function ( done ) {
33+ config . set ( { mail : { transport : 'stub' } } ) ;
7634
77- mailer . init ( ) . then ( function ( ) {
78- done ( ) ;
79- } ) ;
80- } ) ;
35+ mailer . init ( ) . then ( function ( ) {
36+ mailer . transport . transportType . should . eql ( 'STUB' ) ;
37+ return MailAPI . send ( mailData , testUtils . context . internal ) ;
38+ } ) . then ( function ( response ) {
39+ should . exist ( response . mail ) ;
40+ should . exist ( response . mail [ 0 ] . message ) ;
41+ should . exist ( response . mail [ 0 ] . status ) ;
8142
82- it ( 'return correct failure message for domain doesn\'t exist' , function ( done ) {
83- mailer . transport . transportType . should . eql ( 'DIRECT' ) ;
84- return MailAPI . send ( mailDataNoDomain , testUtils . context . internal ) . then ( function ( ) {
85- done ( new Error ( 'Error message not shown.' ) ) ;
86- } , function ( error ) {
87- error . message . should . startWith ( 'Error: Failed to send email' ) ;
88- error . errorType . should . eql ( 'EmailError' ) ;
89- done ( ) ;
90- } ) . catch ( done ) ;
91- } ) ;
92-
93- // This test doesn't work properly - it times out locally
94- it . skip ( 'return correct failure message for no mail server at this address' , function ( done ) {
95- mailer . transport . transportType . should . eql ( 'DIRECT' ) ;
96- MailAPI . send ( mailDataNoServer , testUtils . context . internal ) . then ( function ( ) {
97- done ( new Error ( 'Error message not shown.' ) ) ;
98- } , function ( error ) {
99- error . message . should . eql ( 'Error: Failed to send email.' ) ;
100- error . errorType . should . eql ( 'EmailError' ) ;
101- done ( ) ;
102- } ) . catch ( done ) ;
103- } ) ;
104-
105- it ( 'return correct failure message for incomplete data' , function ( done ) {
106- mailer . transport . transportType . should . eql ( 'DIRECT' ) ;
107-
108- MailAPI . send ( mailDataIncomplete , testUtils . context . internal ) . then ( function ( ) {
109- done ( new Error ( 'Error message not shown.' ) ) ;
110- } , function ( error ) {
111- error . message . should . eql ( 'Error: Incomplete message data.' ) ;
112- error . errorType . should . eql ( 'EmailError' ) ;
113- done ( ) ;
114- } ) . catch ( done ) ;
115- } ) ;
43+ response . mail [ 0 ] . message . subject . should . eql ( 'testemail' ) ;
44+ done ( ) ;
45+ } ) . catch ( done ) ;
11646 } ) ;
11747
118- describe . skip ( 'Stub' , function ( ) {
119- it ( 'returns a success' , function ( done ) {
120- config . set ( { mail : { transport : 'stub' } } ) ;
121-
122- mailer . init ( ) . then ( function ( ) {
123- mailer . transport . transportType . should . eql ( 'STUB' ) ;
124- return MailAPI . send ( mailDataNoServer , testUtils . context . internal ) ;
125- } ) . then ( function ( response ) {
126- should . exist ( response . mail ) ;
127- should . exist ( response . mail [ 0 ] . message ) ;
128- should . exist ( response . mail [ 0 ] . status ) ;
129- response . mail [ 0 ] . status . should . eql ( { message : 'Message Queued' } ) ;
130- response . mail [ 0 ] . message . subject . should . eql ( 'testemail' ) ;
131- done ( ) ;
132- } ) . catch ( done ) ;
133- } ) ;
134-
135- it ( 'returns a boo boo' , function ( done ) {
136- config . set ( { mail : { transport : 'stub' , error : 'Stub made a boo boo :(' } } ) ;
137-
138- mailer . init ( ) . then ( function ( ) {
139- mailer . transport . transportType . should . eql ( 'STUB' ) ;
140- return MailAPI . send ( mailDataNoServer , testUtils . context . internal ) ;
141- } ) . then ( function ( response ) {
142- console . log ( 'res' , response . mail [ 0 ] ) ;
143- done ( new Error ( 'Stub did not error' ) ) ;
144- } , function ( error ) {
145- error . message . should . startWith ( 'Error: Failed to send email - no mail server found at' ) ;
146- error . errorType . should . eql ( 'EmailError' ) ;
147- done ( ) ;
148- } ) . catch ( done ) ;
149- } ) ;
48+ it ( 'returns a boo boo' , function ( done ) {
49+ config . set ( { mail : { transport : 'stub' , options : { error : 'Stub made a boo boo :(' } } } ) ;
50+
51+ mailer . init ( ) . then ( function ( ) {
52+ mailer . transport . transportType . should . eql ( 'STUB' ) ;
53+ return MailAPI . send ( mailData , testUtils . context . internal ) ;
54+ } ) . then ( function ( ) {
55+ done ( new Error ( 'Stub did not error' ) ) ;
56+ } ) . catch ( function ( error ) {
57+ error . message . should . startWith ( 'Error: Stub made a boo boo :(' ) ;
58+ error . errorType . should . eql ( 'EmailError' ) ;
59+ done ( ) ;
60+ } ) . catch ( done ) ;
15061 } ) ;
15162} ) ;
0 commit comments