-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates_test.go
202 lines (177 loc) · 3.86 KB
/
templates_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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package emailtemplates
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestValidate(t *testing.T) {
tests := []struct {
name string
data EmailData
wantErr bool
}{
{
name: "valid data",
data: EmailData{
Subject: "Test Subject",
Recipient: Recipient{
Email: "test@example.com",
},
},
wantErr: false,
},
{
name: "missing subject",
data: EmailData{
Recipient: Recipient{
Email: "test@example.com",
},
},
wantErr: true,
},
{
name: "missing recipient email",
data: EmailData{
Subject: "Test Subject",
Recipient: Recipient{
Email: "",
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.data.Validate()
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}
func TestVerify(t *testing.T) {
data := VerifyEmailData{
EmailData: EmailData{
Subject: "Verify Email",
Recipient: Recipient{
Email: "test@example.com",
},
Config: Config{
CompanyName: "Test Company",
},
},
}
email, err := verify(data)
require.NoError(t, err)
require.NotNil(t, email)
assert.Equal(t, "Please verify your email address to login to Test Company", email.Subject)
}
func TestWelcome(t *testing.T) {
data := WelcomeData{
EmailData: EmailData{
Subject: "Welcome",
Recipient: Recipient{
Email: "test@example.com",
},
Config: Config{
CompanyName: "Test Company",
},
},
Organization: "Test Org",
}
email, err := welcome(data)
require.NoError(t, err)
require.NotNil(t, email)
assert.Equal(t, "Welcome to Test Company!", email.Subject)
}
func TestInvite(t *testing.T) {
data := InviteData{
EmailData: EmailData{
Subject: "Invite",
Recipient: Recipient{
Email: "test@example.com",
},
Config: Config{
CompanyName: "Test Company",
},
},
InviterName: "John Doe",
OrganizationName: "Test Org",
Role: "Admin",
}
email, err := invite(data)
require.NoError(t, err)
require.NotNil(t, email)
assert.Equal(t, "Join Your Teammate John Doe on Test Company!", email.Subject)
}
func TestInviteAccepted(t *testing.T) {
data := InviteData{
EmailData: EmailData{
Subject: "Invite Accepted",
Recipient: Recipient{
Email: "test@example.com",
},
Config: Config{
CompanyName: "Test Company",
},
},
}
email, err := inviteAccepted(data)
require.NoError(t, err)
require.NotNil(t, email)
assert.Equal(t, "You've been added to an Organization on Test Company", email.Subject)
}
func TestPasswordResetRequest(t *testing.T) {
data := ResetRequestData{
EmailData: EmailData{
Subject: "Password Reset Request",
Recipient: Recipient{
Email: "test@example.com",
},
Config: Config{
CompanyName: "Test Company",
},
},
}
email, err := passwordResetRequest(data)
require.NoError(t, err)
require.NotNil(t, email)
assert.Equal(t, "Test Company Password Reset - Action Required", email.Subject)
}
func TestPasswordResetSuccess(t *testing.T) {
data := ResetSuccessData{
EmailData: EmailData{
Subject: "Password Reset Success",
Recipient: Recipient{
Email: "test@example.com",
},
Config: Config{
CompanyName: "Test Company",
},
},
}
email, err := passwordResetSuccess(data)
require.NoError(t, err)
require.NotNil(t, email)
assert.Equal(t, "Test Company Password Reset Confirmation", email.Subject)
}
func TestSubscribe(t *testing.T) {
data := SubscriberEmailData{
EmailData: EmailData{
Subject: "Subscribe",
Recipient: Recipient{
Email: "test@example.com",
},
Config: Config{
CompanyName: "Test Company",
},
},
OrganizationName: "Test Org",
}
email, err := subscribe(data)
require.NoError(t, err)
require.NotNil(t, email)
assert.Equal(t, "You've been subscribed to Test Company", email.Subject)
}