forked from Wylio/meteor-mandrill
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.js
99 lines (84 loc) · 2.77 KB
/
tests.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
// Set MANDRILL_API_USER and MANDRILL_API_KEY to your Mandrill credentials.
// You'll receive emails as part of the test.
Mandrill.config({
username: process.env.MANDRILL_API_USER,
key: process.env.MANDRILL_API_KEY
});
Tinytest.add('users.ping', function (test) {
try {
var result = Mandrill.users.ping();
test.equal(result.data, 'PONG!');
} catch (error) {
test.fail('Invalid API key' + error.toString()); // TODO should bail out here, but unclear how to do that from Tinytest
}
});
Tinytest.add('templates.add', function (test) {
var result = Mandrill.templates.add({
name: 'Meteor package test template',
from_email: process.env.MANDRILL_API_USER,
from_name: 'Meteor package tester',
subject: 'Testing Meteor package wylio:mandrill',
code: '<html><body><p mc:edit="body">Test: is this mc:edit section replaced?</p><p>Test: is this merge var replaced? *|REPLACEME|*</p></body></html>',
text: 'Text part of the email',
publish: true
});
test.equal(result.data.slug, 'meteor-package-test-template');
});
Tinytest.add('templates.render', function (test) {
var result = Mandrill.templates.render({
template_name: 'meteor-package-test-template',
template_content: [
{
name: 'body',
content: 'Replacing mc:edit worked'
}
],
merge_vars: [
{
name: 'REPLACEME',
content: 'Replacing global merge var worked.'
}
]
});
test.equal(result.data.html, '<html><body><p>Replacing mc:edit worked</p><p>Test: is this merge var replaced? Replacing global merge var worked.</p></body></html>');
});
Tinytest.add('messages.sendTemplate', function (test) {
var result = Mandrill.messages.sendTemplate({
template_name: 'meteor-package-test-template',
template_content: [
{
name: 'body',
content: 'Replacing mc:edit worked'
}
],
message: {
subject: 'Meteor package test philly',
from_email: process.env.MANDRILL_API_USER,
to: [
{email: process.env.MANDRILL_API_USER}
],
global_merge_vars: [
{
name: 'REPLACEME',
content: 'Replacing global merge var worked.'
}
]
}
});
test.equal(result.data[0].email, process.env.MANDRILL_API_USER);
test.equal(result.data[0].status, 'sent');
});
// test async calls too
Tinytest.addAsync('templates.delete', function (test, done) {
Mandrill.templates.delete({
name: 'Meteor package test template'
}, function callback(error, result) {
if (error) {
test.fail(error.toString());
} else {
test.equal(result.data.slug, 'meteor-package-test-template');
}
done();
});
});
// templates.search-time-series is laggy - it won't return anything for a minute or two after sending the first emails matching the query