-
Notifications
You must be signed in to change notification settings - Fork 0
/
servers_test.go
97 lines (81 loc) · 3.66 KB
/
servers_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
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
package postmark
import (
"fmt"
"os"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCRUDServerIntegrationOK(t *testing.T) {
// Flakey endpoint
t.Skip()
if os.Getenv("INTEGRATION") != "true" {
t.Skip()
}
accountToken := os.Getenv("PM_ACCOUNT_TOKEN")
require.NotEmpty(t, accountToken, "PM_ACCOUNT_TOKEN not set for integration test")
c := NewClient(accountToken, "")
timestamp := time.Now().Unix()
// Create
newServer := Server{
Name: fmt.Sprintf("lib-test-name-%d", timestamp),
Color: "purple",
SMTPAPIActivated: true,
RawEmailEnabled: true,
InboundHookURL: fmt.Sprintf("https://lib-test-domain-%d.com/inboundhook", timestamp),
TrackOpens: true,
TrackLinks: "HtmlAndText",
InboundSpamThreshold: 5,
EnableSMTPAPIErrorHooks: true,
}
retSrv, err := c.CreateServer(newServer)
require.NoError(t, err, "errored creating server")
require.NotEmpty(t, retSrv, "got empty server returned")
require.NotEmpty(t, retSrv.ID, "missing server ID")
// Read
readSrv, err := c.GetServer(strconv.Itoa(retSrv.ID))
require.NoError(t, err, "error reading server")
require.NotEmpty(t, readSrv, "got empty server response on read")
assert.Equal(t, newServer.Name, readSrv.Name, "name wrong")
assert.Equal(t, newServer.Color, readSrv.Color, "color wrong")
assert.Equal(t, newServer.SMTPAPIActivated, readSrv.SMTPAPIActivated, "smtpapi wrong")
assert.Equal(t, newServer.RawEmailEnabled, readSrv.RawEmailEnabled, "rawemail wrong")
assert.Equal(t, newServer.InboundHookURL, readSrv.InboundHookURL, "hook url wrong")
assert.Equal(t, newServer.PostFirstOpenOnly, readSrv.PostFirstOpenOnly, "firstopen wrong")
assert.Equal(t, newServer.TrackOpens, readSrv.TrackOpens, "trackopens wrong")
assert.Equal(t, newServer.TrackLinks, readSrv.TrackLinks, "tracklinks wrong")
assert.Equal(t, newServer.InboundSpamThreshold, readSrv.InboundSpamThreshold, "spam threshold wrong")
assert.Equal(t, newServer.EnableSMTPAPIErrorHooks, readSrv.EnableSMTPAPIErrorHooks, "errorhooks wrong")
// Update
updatedServer := Server{
Name: newServer.Name + "-updated",
Color: "blue",
SMTPAPIActivated: false,
RawEmailEnabled: false,
InboundHookURL: newServer.InboundHookURL + "-updated",
TrackOpens: false,
TrackLinks: "TextOnly",
InboundSpamThreshold: 4,
EnableSMTPAPIErrorHooks: false,
}
err = c.UpdateServer(strconv.Itoa(readSrv.ID), updatedServer)
require.NoError(t, err, "error updating server")
// Read
readSrv, err = c.GetServer(strconv.Itoa(retSrv.ID))
require.NoError(t, err, "error reading server")
require.NotEmpty(t, readSrv, "got empty server response on read")
assert.Equal(t, updatedServer.Name, readSrv.Name, "name wrong")
assert.Equal(t, updatedServer.Color, readSrv.Color, "color wrong")
assert.Equal(t, updatedServer.SMTPAPIActivated, readSrv.SMTPAPIActivated, "smtpapi wrong")
assert.Equal(t, updatedServer.RawEmailEnabled, readSrv.RawEmailEnabled, "rawemail wrong")
assert.Equal(t, updatedServer.InboundHookURL, readSrv.InboundHookURL, "hook url wrong")
assert.Equal(t, updatedServer.TrackOpens, readSrv.TrackOpens, "trackopens wrong")
assert.Equal(t, updatedServer.TrackLinks, readSrv.TrackLinks, "tracklinks wrong")
assert.Equal(t, updatedServer.InboundSpamThreshold, readSrv.InboundSpamThreshold, "spam threshold wrong")
assert.Equal(t, updatedServer.EnableSMTPAPIErrorHooks, readSrv.EnableSMTPAPIErrorHooks, "errorhooks wrong")
// Delete
err = c.DeleteServer(strconv.Itoa(retSrv.ID))
require.NoError(t, err, "delete failed")
}