forked from strongloop/loopback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail.test.js
103 lines (87 loc) · 2.71 KB
/
email.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
// Node module: loopback
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var loopback = require('../');
var MyEmail;
var assert = require('assert');
var MailConnector = require('../lib/connectors/mail');
describe('Email connector', function() {
it('should set up SMTP', function() {
var connector = new MailConnector({ transports: [
{ type: 'smtp', service: 'gmail' },
] });
assert(connector.transportForName('smtp'));
});
it('should set up DIRECT', function() {
var connector = new MailConnector({ transports: [
{ type: 'direct', name: 'localhost' },
] });
assert(connector.transportForName('direct'));
});
it('should set up STUB', function() {
var connector = new MailConnector({ transports: [
{ type: 'stub', service: 'gmail' },
] });
assert(connector.transportForName('stub'));
});
it('should set up a single transport for SMTP', function() {
var connector = new MailConnector({ transport:
{ type: 'smtp', service: 'gmail' },
});
assert(connector.transportForName('smtp'));
});
it('should set up a aliased transport for SMTP', function() {
var connector = new MailConnector({ transport:
{ type: 'smtp', service: 'ses-us-east-1', alias: 'ses-smtp' },
});
assert(connector.transportForName('ses-smtp'));
});
});
describe('Email and SMTP', function() {
beforeEach(function() {
MyEmail = loopback.Email.extend('my-email');
var ds = loopback.createDataSource('email', {
connector: loopback.Mail,
transports: [{ type: 'STUB' }],
});
MyEmail.attachTo(ds);
});
it('should have a send method', function() {
assert(typeof MyEmail.send === 'function');
assert(typeof MyEmail.prototype.send === 'function');
});
describe('MyEmail', function() {
it('MyEmail.send(options, callback)', function(done) {
var options = {
to: '[email protected]',
from: '[email protected]',
subject: 'subject',
text: 'text',
html: '<h1>html</h1>',
};
MyEmail.send(options, function(err, mail) {
assert(!err);
assert(mail.response);
assert(mail.envelope);
assert(mail.messageId);
done(err);
});
});
it('myEmail.send(callback)', function(done) {
var message = new MyEmail({
to: '[email protected]',
from: '[email protected]',
subject: 'subject',
text: 'text',
html: '<h1>html</h1>',
});
message.send(function(err, mail) {
assert(mail.response);
assert(mail.envelope);
assert(mail.messageId);
done(err);
});
});
});
});