-
Notifications
You must be signed in to change notification settings - Fork 1
/
previews_test.go
66 lines (49 loc) · 1.38 KB
/
previews_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package mailosaur
import (
"fmt"
"log"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func init() {
apiKey := os.Getenv("MAILOSAUR_API_KEY")
baseUrl := os.Getenv("MAILOSAUR_BASE_URL")
server = os.Getenv("MAILOSAUR_SERVER")
if len(apiKey) == 0 {
log.Fatal("Missing necessary environment variables - refer to README.md")
}
if len(baseUrl) == 0 {
baseUrl = "https://next.mailosaur.com/"
}
client = New(apiKey)
client.baseUrl = baseUrl
}
func TestListEmailClients(t *testing.T) {
result, err := client.Previews.ListEmailClients()
assert.NoError(t, err)
assert.True(t, len(result.Items) > 1)
}
func TestGenerateEmailPreviews(t *testing.T) {
if len(server) == 0 {
t.Skip()
}
randomString := getRandomString()
host := os.Getenv("MAILOSAUR_SMTP_HOST")
if len(host) == 0 {
host = "mailosaur.net"
}
testEmailAddress := fmt.Sprintf("%s@%s.%s", randomString, server, host)
sendEmail(client, server, testEmailAddress)
email, _ := client.Messages.Get(&MessageSearchParams{
Server: server,
}, &SearchCriteria{
SentTo: testEmailAddress,
})
request := &PreviewRequest{EmailClient: "OL2021"}
options := &PreviewRequestOptions{Previews: []*PreviewRequest{request}}
result, _ := client.Messages.GeneratePreviews(email.Id, options)
assert.True(t, len(result.Items) > 0)
bytes, _ := client.Files.GetPreview(result.Items[0].Id)
assert.True(t, len(bytes) > 1)
}