forked from eddiezane/smtpapi-ruby
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest.rb
More file actions
277 lines (237 loc) · 6.76 KB
/
test.rb
File metadata and controls
277 lines (237 loc) · 6.76 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
require 'test_helper'
require 'test/unit'
require './lib/smtpapi'
#
# SmtpapiTest implementation
#
class SmtpapiTest < Test::Unit::TestCase
def test_version
assert_equal('0.1.12', Smtpapi::VERSION)
end
def test_empty
header = Smtpapi::Header.new
assert_equal('{}', header.json_string)
end
def test_add_to
header = Smtpapi::Header.new
header.add_to('you@youremail.com')
header.add_to('other@otheremail.com', 'Other Name')
assert_equal(
'{"to":["you@youremail.com","Other Name <other@otheremail.com>"]}',
header.json_string
)
end
def test_add_to_array
header = Smtpapi::Header.new
header.add_to(['you@youremail.com', 'my@myemail.com'])
assert_equal(
'{"to":["you@youremail.com","my@myemail.com"]}',
header.json_string
)
end
def test_set_tos
header = Smtpapi::Header.new
header.set_tos(['you@youremail.com', 'other@otheremail.com'])
assert_equal(
'{"to":["you@youremail.com","other@otheremail.com"]}',
header.json_string
)
end
def test_add_substitution
header = Smtpapi::Header.new
header.add_substitution('keep', ['secret'])
header.add_substitution('other', %w(one two))
assert_equal(
'{"sub":{"keep":["secret"],"other":["one","two"]}}',
header.json_string
)
end
def test_set_substitutions
header = Smtpapi::Header.new
header.set_substitutions('keep' => ['secret'])
assert_equal('{"sub":{"keep":["secret"]}}', header.json_string)
end
def test_add_section
header = Smtpapi::Header.new
header.add_section('-charge-', 'This ship is useless.')
header.add_section('-bomber-', 'Only for sad vikings.')
assert_equal(
'{"section":'\
'{"-charge-":"This ship is useless.",'\
'"-bomber-":"Only for sad vikings."}}',
header.json_string
)
end
def test_set_sections
header = Smtpapi::Header.new
header.set_sections('-charge-' => 'This ship is useless.')
assert_equal(
'{"section":{"-charge-":"This ship is useless."}}',
header.json_string
)
end
def test_add_unique_arg
header = Smtpapi::Header.new
header.add_unique_arg('cat', 'dogs')
assert_equal('{"unique_args":{"cat":"dogs"}}', header.json_string)
end
def test_set_unique_args
header = Smtpapi::Header.new
header.set_unique_args('cow' => 'chicken')
header.set_unique_args('dad' => 'proud')
assert_equal('{"unique_args":{"dad":"proud"}}', header.json_string)
end
def test_add_category
header = Smtpapi::Header.new
header.add_category('tactics')
header.add_category('advanced')
assert_equal('{"category":["tactics","advanced"]}', header.json_string)
end
def test_set_categories
header = Smtpapi::Header.new
header.set_categories(%w(tactics advanced))
assert_equal('{"category":["tactics","advanced"]}', header.json_string)
end
def test_add_filter
header = Smtpapi::Header.new
header.add_filter('footer', 'enable', 1)
header.add_filter('footer', 'text/html', '<strong>boo</strong>')
assert_equal(
'{"filters":'\
'{"footer":'\
'{"settings":'\
'{"enable":1,'\
'"text/html":"<strong>boo</strong>"'\
'}'\
'}'\
'}'\
'}',
header.json_string
)
end
def test_set_filters
header = Smtpapi::Header.new
filter = {
'footer' => {
'setting' => {
'enable' => 1,
'text/plain' => 'You can haz footers!'
}
}
}
header.set_filters(filter)
assert_equal(
'{"filters":'\
'{"footer":'\
'{"setting":'\
'{"enable":1,"text/plain":"You can haz footers!"}'\
'}'\
'}'\
'}',
header.json_string
)
end
def test_add_category_unicode
header = Smtpapi::Header.new
header.add_category('Martí')
header.add_category('天破活殺')
header.add_category('天翔十字鳳')
assert_equal(
'{"category":'\
'["Mart\\u00ed",'\
'"\\u5929\\u7834\\u6d3b\\u6bba",'\
'"\\u5929\\u7fd4\\u5341\\u5b57\\u9cf3"]}',
header.json_string
)
header.add_category('鼖')
assert_equal(
'{"category":'\
'["Mart\\u00ed",'\
'"\\u5929\\u7834\\u6d3b\\u6bba",'\
'"\\u5929\\u7fd4\\u5341\\u5b57\\u9cf3",'\
'"\\ud87e\\ude1b"]}',
header.json_string
)
end
def test_sent_send_at
header = Smtpapi::Header.new
localtime = Time.local(2014, 8, 29, 17, 56, 35)
header.set_send_at(localtime)
assert_equal("{\"send_at\":#{localtime.to_i}}", header.json_string)
end
def test_send_each_at
header = Smtpapi::Header.new
localtime1 = Time.local(2014, 8, 29, 17, 56, 35)
localtime2 = Time.local(2013, 12, 31, 0, 0, 0)
localtime3 = Time.local(2015, 9, 1, 4, 5, 6)
header.set_send_each_at([localtime1, localtime2, localtime3])
assert_equal(
'{"send_each_at":'\
"[#{localtime1.to_i},#{localtime2.to_i},#{localtime3.to_i}]"\
'}',
header.json_string
)
end
def test_asm_group_id
header = Smtpapi::Header.new
header.set_asm_group(2)
assert_equal('{"asm_group_id":2}', header.json_string)
end
def test_ip_pool
header = Smtpapi::Header.new
header.set_ip_pool('test_pool')
assert_equal('{"ip_pool":"test_pool"}', header.json_string)
end
# def test_docker_exists
# assert(File.file?('./Dockerfile') || File.file?('./docker/Dockerfile'))
# end
# def test_docker_compose_exists
# assert(
# File.file?('./docker-compose.yml') ||
# File.file?('./docker/docker-compose.yml')
# )
# end
def test_env_sample_exists
assert(File.file?('./.env_sample'))
end
def test_gitignore_exists
assert(File.file?('./.gitignore'))
end
def test_github_actions_exists
assert(File.file?('./.github/workflows/test-and-deploy.yml'))
end
def test_changelog_exists
assert(File.file?('./CHANGELOG.md'))
end
def test_code_of_conduct_exists
assert(File.file?('./CODE_OF_CONDUCT.md'))
end
def test_contributing_exists
assert(File.file?('./CONTRIBUTING.md'))
end
def test_license_exists
assert(File.file?('./LICENSE'))
end
def test_pull_request_template_exists
assert(File.file?('./PULL_REQUEST_TEMPLATE.md'))
end
def test_readme_exists
assert(File.file?('./README.md'))
end
def test_troubleshooting_exists
assert(File.file?('./TROUBLESHOOTING.md'))
end
# def test_usage_exists
# assert(File.file?('./USAGE.md'))
# end
# def test_use_cases_exists
# assert(File.file?('./USE_CASES.md'))
# end
def test_license_date_is_updated
license_year = IO.read('LICENSE').match(
/Copyright \(C\) (\d{4}), Twilio SendGrid/
)[1]
current_year = Time.new.year
assert_equal(current_year, license_year.to_i)
end
end