-
Notifications
You must be signed in to change notification settings - Fork 56
/
email_test.go
121 lines (93 loc) · 2.83 KB
/
email_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package management
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/auth0/go-auth0"
)
func TestEmailManager_Create(t *testing.T) {
setupHTTPRecordings(t)
emailProvider := &Email{
Name: auth0.String("smtp"),
Enabled: auth0.Bool(true),
DefaultFromAddress: auth0.String("no-reply@example.com"),
Credentials: &EmailCredentials{
SMTPHost: auth0.String("smtp.example.com"),
SMTPPort: auth0.Int(587),
SMTPUser: auth0.String("user"),
SMTPPass: auth0.String("pass"),
},
}
err := m.Email.Create(emailProvider)
assert.NoError(t, err)
t.Cleanup(func() {
cleanupEmailProvider(t)
})
}
func TestEmailManager_Read(t *testing.T) {
setupHTTPRecordings(t)
expectedEmailProvider := givenAnEmailProvider(t)
actualEmailProvider, err := m.Email.Read()
assert.NoError(t, err)
assert.Equal(t, expectedEmailProvider.GetName(), actualEmailProvider.GetName())
assert.Equal(t, expectedEmailProvider.GetEnabled(), actualEmailProvider.GetEnabled())
assert.Equal(t, expectedEmailProvider.GetDefaultFromAddress(), actualEmailProvider.GetDefaultFromAddress())
assert.Equal(
t,
expectedEmailProvider.GetCredentials().GetSMTPUser(),
actualEmailProvider.GetCredentials().GetSMTPUser(),
)
assert.Equal(
t,
"",
actualEmailProvider.GetCredentials().GetSMTPPass(),
) // Passwords are not returned from the Auth0 API.
}
func TestEmailManager_Update(t *testing.T) {
setupHTTPRecordings(t)
emailProvider := givenAnEmailProvider(t)
emailProvider.Enabled = auth0.Bool(false)
emailProvider.DefaultFromAddress = auth0.String("info@example.com")
err := m.Email.Update(emailProvider)
assert.NoError(t, err)
actualEmailProvider, err := m.Email.Read()
assert.NoError(t, err)
assert.False(t, actualEmailProvider.GetEnabled())
assert.Equal(t, "info@example.com", actualEmailProvider.GetDefaultFromAddress())
}
func TestEmailManager_Delete(t *testing.T) {
setupHTTPRecordings(t)
givenAnEmailProvider(t)
err := m.Email.Delete()
assert.NoError(t, err)
_, err = m.Email.Read()
assert.Error(t, err)
assert.Implements(t, (*Error)(nil), err)
assert.Equal(t, http.StatusNotFound, err.(Error).Status())
}
func givenAnEmailProvider(t *testing.T) *Email {
t.Helper()
emailProvider := &Email{
Name: auth0.String("smtp"),
Enabled: auth0.Bool(true),
DefaultFromAddress: auth0.String("no-reply@example.com"),
Credentials: &EmailCredentials{
SMTPHost: auth0.String("smtp.example.com"),
SMTPPort: auth0.Int(587),
SMTPUser: auth0.String("user"),
SMTPPass: auth0.String("pass"),
},
}
err := m.Email.Create(emailProvider)
require.NoError(t, err)
t.Cleanup(func() {
cleanupEmailProvider(t)
})
return emailProvider
}
func cleanupEmailProvider(t *testing.T) {
t.Helper()
err := m.Email.Delete()
require.NoError(t, err)
}