1 | var t = require('../test-lib/test.js');
|
2 | var assert = require('assert');
|
3 | var apos;
|
4 |
|
5 | describe('Email', function() {
|
6 |
|
7 | this.timeout(t.timeout);
|
8 |
|
9 | after(function(done) {
|
10 | return t.destroy(apos, done);
|
11 | });
|
12 |
|
13 | it('should be a property of the apos object', function(done) {
|
14 | this.timeout(t.timeout);
|
15 | this.slow(2000);
|
16 |
|
17 | apos = require('../index.js')({
|
18 | root: module,
|
19 | shortName: 'test',
|
20 |
|
21 | modules: {
|
22 | 'apostrophe-express': {
|
23 | port: 7900
|
24 | },
|
25 | 'apostrophe-email': {
|
26 | nodemailer: {
|
27 | streamTransport: true,
|
28 | buffer: true,
|
29 | newline: 'unix'
|
30 | }
|
31 | },
|
32 | 'email-test': {}
|
33 | },
|
34 | afterInit: function(callback) {
|
35 | assert(apos.modules['apostrophe-email']);
|
36 |
|
37 |
|
38 |
|
39 | apos.argv._ = [];
|
40 | return callback(null);
|
41 | },
|
42 | afterListen: function(err) {
|
43 | assert(!err);
|
44 | done();
|
45 | }
|
46 | });
|
47 | });
|
48 |
|
49 | it('can send email on behalf of a module', function(done) {
|
50 | apos.modules['email-test'].email(apos.tasks.getReq(),
|
51 | 'welcome',
|
52 | {
|
53 | name: 'Fred Astaire'
|
54 | },
|
55 | {
|
56 | from: 'test@example.com',
|
57 | to: 'recipient@example.com',
|
58 | subject: 'Welcome Aboard'
|
59 | },
|
60 | function(err, info) {
|
61 | assert(!err);
|
62 | assert(info);
|
63 | var message = info.message.toString();
|
64 | assert(message.match(/Fred Astaire/));
|
65 | assert(message.match(/Subject: Welcome Aboard/));
|
66 | assert(message.match(/From: test@example\.com/));
|
67 | assert(message.match(/To: recipient@example\.com/));
|
68 | assert(message.match(/\[http:\/\/example\.com\/\]/));
|
69 | done();
|
70 | }
|
71 | );
|
72 | });
|
73 | it('can do it with promises', function() {
|
74 | return apos.modules['email-test'].email(apos.tasks.getReq(),
|
75 | 'welcome',
|
76 | {
|
77 | name: 'Fred Astaire'
|
78 | },
|
79 | {
|
80 | from: 'test@example.com',
|
81 | to: 'recipient@example.com',
|
82 | subject: 'Welcome Aboard'
|
83 | }
|
84 | ).then(function(info) {
|
85 | assert(info);
|
86 | var message = info.message.toString();
|
87 | assert(message.match(/Fred Astaire/));
|
88 | assert(message.match(/Subject: Welcome Aboard/));
|
89 | assert(message.match(/From: test@example\.com/));
|
90 | assert(message.match(/To: recipient@example\.com/));
|
91 | assert(message.match(/\[http:\/\/example\.com\/\]/));
|
92 | return true;
|
93 | });
|
94 | });
|
95 | });
|