-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
98 lines (87 loc) · 2.13 KB
/
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
'use strict'
const t = require('tap')
const Fastify = require('fastify')
const nodemailer = require('./')
t.jobs = 4
t.test('nodemailer exists', t => {
const fastify = Fastify()
fastify
.register(nodemailer, {
jsonTransport: true
})
.ready(err => {
t.error(err)
t.ok(fastify.nodemailer)
fastify.close()
t.end()
})
})
t.test('createTransport error', t => {
const fastify = Fastify()
fastify
.register(nodemailer, 'this will throw')
.ready(err => {
t.ok(err instanceof Error)
t.match(err.message, /Cannot create property 'mailer'/)
fastify.close()
t.end()
})
})
t.test('nodemailer#sendMail', t => {
const fastify = Fastify()
fastify
.register(nodemailer, {
jsonTransport: true
})
.ready(err => {
t.error(err)
const { nodemailer } = fastify
nodemailer.sendMail({
from: 'sender@example.com',
to: 'recipient@example.com',
subject: 'foo',
text: 'bar'
}, (err, info) => {
t.error(err)
t.equal(info.envelope.from, 'sender@example.com')
t.equal(info.envelope.to[0], 'recipient@example.com')
t.ok(~info.message.indexOf('"subject":"foo"'))
t.ok(~info.message.indexOf('"text":"bar"'))
fastify.close()
t.end()
})
})
})
t.test('customTransport', t => {
const fastify = Fastify()
const transport = {
name: 'minimal',
version: '0.1.0',
send: (mail, callback) => {
const envelope = mail.message.getEnvelope()
const messageId = mail.message.messageId()
callback(null, {
envelope,
messageId
})
}
}
fastify
.register(nodemailer, transport)
.ready(err => {
t.error(err)
const { nodemailer } = fastify
nodemailer.sendMail({
from: 'sender@example.com',
to: 'recipient@example.com',
subject: 'foo',
text: 'bar'
}, (err, info) => {
t.error(err)
t.equal(info.envelope.from, 'sender@example.com')
t.equal(info.envelope.to[0], 'recipient@example.com')
fastify.close()
t.end()
})
})
})