-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_email.test.js
More file actions
95 lines (78 loc) · 3.24 KB
/
send_email.test.js
File metadata and controls
95 lines (78 loc) · 3.24 KB
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
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
const { default: component } = await import('./send_email.js')
describe(component.name, () => {
it('should be able to send an email without an attachment', async (testContext) => {
const accessKeyId = process.env.AWS_ACCESS_KEY_ID
if (!accessKeyId) {
testContext.skip('No `AWS_ACCESS_KEY_ID` env. var. provided, skipping email test')
return
}
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
if (!secretAccessKey) {
testContext.skip('No `AWS_SECRET_ACCESS_KEY` env. var. provided, skipping email test')
return
}
if (process.env.EMAIL_TEST_ATTACHMENT) {
testContext.skip('An `EMAIL_TEST_ATTACHMENT` was provided, so skipping "without attachment" test')
return
}
component.amazon_ses = {
"$auth": { accessKeyId, secretAccessKey },
}
component.to = process.env.EMAIL_TEST_TO
assert.ok(component.to, 'No "To Address" provided (use EMAIL_TEST_TO)')
component.from = process.env.EMAIL_TEST_FROM
assert.ok(component.from, 'No "From Address" provided (use EMAIL_TEST_FROM)')
component.subject = process.env.EMAIL_TEST_SUBJECT
assert.ok(component.subject, 'No "Subject" provided (use EMAIL_TEST_SUBJECT)')
component.body = process.env.EMAIL_TEST_BODY
assert.ok(component.body, 'No "Body" provided (use EMAIL_TEST_BODY)')
component.attachmentContent = []
const response = await component.run({
steps: { trigger: {} },
$: {}
})
assert.ok(response.MessageId, 'No MessageId was returned')
})
it('should be able to send an email with an attachment', async (testContext) => {
const accessKeyId = process.env.AWS_ACCESS_KEY_ID
if (!accessKeyId) {
testContext.skip('No `AWS_ACCESS_KEY_ID` env. var. provided, skipping email test')
return
}
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
if (!secretAccessKey) {
testContext.skip('No `AWS_SECRET_ACCESS_KEY` env. var. provided, skipping email test')
return
}
if (!process.env.EMAIL_TEST_ATTACHMENT) {
testContext.skip('No `EMAIL_TEST_ATTACHMENT` was provided, so skipping "with attachment" test')
return
}
component.amazon_ses = {
"$auth": { accessKeyId, secretAccessKey },
}
component.to = process.env.EMAIL_TEST_TO
assert.ok(component.to, 'No "To Address" provided (use EMAIL_TEST_TO)')
component.from = process.env.EMAIL_TEST_FROM
assert.ok(component.from, 'No "From Address" provided (use EMAIL_TEST_FROM)')
component.subject = process.env.EMAIL_TEST_SUBJECT
assert.ok(component.subject, 'No "Subject" provided (use EMAIL_TEST_SUBJECT)')
component.body = process.env.EMAIL_TEST_BODY
assert.ok(component.body, 'No "Body" provided (use EMAIL_TEST_BODY)')
component.attachmentFilename = ['example.csv']
component.attachmentContent = [
`Title,Genre,Author
"The Hobbit",Fantasy,"J.R.R. Tolkien"
"Pride and Prejudice",Fiction,"Jane Austen"`
]
component.attachmentType = ['text/csv']
component.attachmentEncoding = 'BASE64'
const response = await component.run({
steps: { trigger: {} },
$: {}
})
assert.ok(response.MessageId, 'No MessageId was returned')
})
})