forked from gsamokovarov/sg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparkpost_test.go
46 lines (37 loc) · 1.51 KB
/
sparkpost_test.go
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
package sg
import (
"testing"
"github.com/gsamokovarov/assert"
)
var sparkPost = &SparkPostService{}
func TestSparkPostService(t *testing.T) {
t.Run("without subscriptions", func(t *testing.T) {
buf, err := sparkPost.Serialize(&Mail{
TemplateID: "e0d26988-d1d7-41ad-b1eb-4c4b37125893",
To: "[email protected]",
})
assert.Nil(t, err)
assert.Equal(t, `{"recipients":[{"address":"[email protected]"}],"content":{"template_id":"e0d26988-d1d7-41ad-b1eb-4c4b37125893"}}`, string(buf))
})
t.Run("with subscriptions", func(t *testing.T) {
buf, err := sparkPost.Serialize(&Mail{
TemplateID: "e0d26988-d1d7-41ad-b1eb-4c4b37125893",
To: "[email protected]",
Substitutions: H{"SUB": "value"},
})
assert.Nil(t, err)
assert.Equal(t, `{"recipients":[{"address":"[email protected]"}],"substitution_data":{"SUB":"value"},"content":{"template_id":"e0d26988-d1d7-41ad-b1eb-4c4b37125893"}}`, string(buf))
})
t.Run("with inline template", func(t *testing.T) {
buf, err := sparkPost.Serialize(&Mail{
From: "[email protected]",
FromName: "Genadi Samokovarov",
To: "[email protected]",
Subject: "Test Email",
TemplateInline: `Testing 1, 2, 3...`,
Substitutions: H{"SUB": "value"},
})
assert.Nil(t, err)
assert.Equal(t, `{"recipients":[{"address":"[email protected]"}],"substitution_data":{"SUB":"value"},"content":{"from":{"email":"[email protected]","name":"Genadi Samokovarov"},"html":"Testing 1, 2, 3...","subject":"Test Email"}}`, string(buf))
})
}