Class: MailsocioQA::MailsocioTest

Inherits:
Minitest::Test show all
Defined in:
lib/mailsocio_qa/mailsocio_test.rb

Instance Method Summary collapse

Methods inherited from Minitest::Test

runnable_methods

Instance Method Details

#settingsObject



9
10
11
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 9

def settings
  @settings ||= Settings.new(ENV.fetch("CONFIG_FILE", File.expand_path('../../../settings.yml', __FILE__)))
end

#setupObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 13

def setup
  @base_domain = Regexp.escape(settings.mailsocio.base_domain)
  @track_domain = "track.#{settings.mailsocio.base_domain}"
  @client = TestClient.new(settings)

  addresses = settings.trap.addresses
  @john = addresses.john
  @jane = addresses.jane
  @invalid = addresses.invalid
end

#test_authentication_resultsObject



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 196

def test_authentication_results
  @client.
  @client.clean_messages
  @client.deliver('X-To' => "[\"#{@john}\"]")

  message = @client.read_message
  auth_results = message['Authentication-Results'].value
  assert_match /spf=pass/, auth_results
  assert_match /dkim=pass/, auth_results

  assert_match "@#{@track_domain}", message.return_path
  assert_match "d=#{@track_domain}", message['DKIM-Signature'].try(:value)
end

#test_bulk_routingObject



259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 259

def test_bulk_routing
  @client.
  @client.clean_messages
  @client.deliver(
    'Precedence' => 'bulk',
    'X-To' => "[\"#{@john}\"]"
  )

  received = @client.read_message.received
  assert_match /^from (smtp[1-9]\d*\.#{@base_domain}) \(\1\. /, received[-3].value
  assert_match 'from localhost.localdomain (localhost ', received[-2].value
  assert_match 'from localhost.localdomain (localhost ', received[-1].value
end

#test_create_accountObject



24
25
26
27
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 24

def 
  @client.
  refute_nil @client.
end

#test_custom_tracking_domainObject



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 210

def test_custom_tracking_domain
  domain = settings.trap.custom_tracking_domain
  attrs = @client.(custom_tracking_domain: domain)
  @client.custom_tracking_domain = domain
  assert_wont_raise('Could not read account via custom tracking domain URL') do
    @client.
  end
  assert attrs['custom_tracking_enabled'], 'Custom tracking is disabled'
  assert attrs['custom_signing_enabled'], 'Custom signing is disabled'

  @client.clean_messages
  @client.deliver('X-To' => "[\"#{@john}\"]")

  message = @client.read_message
  auth_results = message['Authentication-Results'].value
  assert_match /spf=pass/, auth_results
  assert_match /dkim=pass/, auth_results

  assert_match "@#{domain}", message.return_path
  assert_match "d=#{domain}", message['DKIM-Signature'].try(:value)
end

#test_custom_tracking_hard_bounceObject



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 232

def test_custom_tracking_hard_bounce
  domain = settings.trap.custom_tracking_domain
  @client.(custom_tracking_domain: domain)

  @client.clean_messages
  @client.deliver(
    'X-Newsletter-Id' => '15',
    'X-To' => "[\"#{@invalid}\"]"
  )
  sleep 90

  stat = @client.newsletter_statistics('15')
  assert_equal 1, stat['queued']
  assert_equal 1, stat['hard_bounced']
end

#test_hard_bounceObject



147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 147

def test_hard_bounce
  @client.
  @client.deliver(
    'X-Newsletter-Id' => '15',
    'X-To' => "[\"#{@invalid}\"]"
  )
  sleep 90

  stat = @client.newsletter_statistics('15')
  assert_equal 1, stat['queued']
  assert_equal 1, stat['hard_bounced']
end

#test_newsletter_trackingObject



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
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 93

def test_newsletter_tracking
  @client.
  @client.clean_messages('john')
  @client.clean_messages('jane')

  @client.deliver(
    'X-Newsletter-Id' => '15',
    'X-To' => "[\"#{@john}\",\"#{@jane}\"]",
    'X-Track' => 'yes',
    'Content-Type' => 'text/html',
    'Body' => '<a href="http://google.com/search">Search</a>'
  )

  message = @client.read_message('john')
  page = TestHtmlPage.new(message.body.raw_source)

  stat = @client.newsletter_statistics('15')
  assert_equal 2, stat['queued']
  assert_equal 2, stat['sent']
  assert_equal 0, stat['viewed']
  assert_equal 0, stat['clicked']

  page.load
  stat = @client.newsletter_statistics('15')
  assert_equal 2, stat['queued']
  assert_equal 2, stat['sent']
  assert_equal 1, stat['viewed']
  assert_equal 0, stat['clicked']

  assert_equal 'http://google.com/search', page.click
  stat = @client.newsletter_statistics('15')
  assert_equal 2, stat['queued']
  assert_equal 2, stat['sent']
  assert_equal 1, stat['viewed']
  assert_equal 1, stat['clicked']

  message = @client.read_message('jane')
  page = TestHtmlPage.new(message.body.raw_source)

  page.load
  stat = @client.newsletter_statistics('15')
  assert_equal 2, stat['queued']
  assert_equal 2, stat['sent']
  assert_equal 2, stat['viewed']
  assert_equal 1, stat['clicked']

  assert_equal 'http://google.com/search', page.click
  stat = @client.newsletter_statistics('15')
  assert_equal 2, stat['queued']
  assert_equal 2, stat['sent']
  assert_equal 2, stat['viewed']
  assert_equal 2, stat['clicked']
end

#test_newsletter_tracking_subsequent_failuresObject



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
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 160

def test_newsletter_tracking_subsequent_failures
  skip("still not in production")

  @client.

  @client.deliver(
    'X-Newsletter-Id' => '15',
    'X-To' => "[\"#{@invalid}\"]",
  )

  sleep 90

  stat = @client.newsletter_statistics('15')
  assert_equal 0, stat['new']
  assert_equal 1, stat['queued']
  assert_equal 1, stat['hard_bounced']
  assert_equal 0, stat['skipped']
  assert_equal 1, stat['sent']
  assert_equal 0, stat['delivered']

  @client.deliver(
    'X-Newsletter-Id' => '16',
    'X-To' => "[\"#{@invalid}\"]",
  )

  sleep 30

  stat = @client.newsletter_statistics('16')
  assert_equal 0, stat['new']
  assert_equal 1, stat['queued']
  assert_equal 1, stat['hard_bounced']
  assert_equal 1, stat['skipped']
  assert_equal 1, stat['sent']
  assert_equal 0, stat['delivered']
end

#test_nonascii_mail_css_and_trackingObject



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
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 44

def test_nonascii_mail_css_and_tracking
  @client.
  @client.clean_messages

  @client.deliver(
    'X-To' => "[\"#{@john}\"]",
    'X-Inline-Css' => 1,
    'X-Track' => 1,
    'Content-Type' => 'text/html; charset=ISO-8859-1',
    'Content-Transfer-Encoding' => 'quoted-printable',
    'Subject' => 'Hello',
    'Body' => <<NONASCIIHTML
<html>
  <head>
<style type=3D"text/css">
  body, .wrapper {
    height: 20px;
  }
</style>
  </head>
  <body>
<p>English Caf=E9</p>
  </body>
</html>
NONASCIIHTML
  )

  message = @client.read_message
  assert_equal 'Hello', message.subject
  assert_match /\s*<body style=3D"height:20px">\r\n/, message.body.raw_source.strip, 'No inlined css styles'
  assert_match /\s*<p>English Caf=E9<\/p>\r\n/, message.body.raw_source.strip, 'Not original quoted-printable'
  assert_match /<img src=3D".*\/assets\/dot\.png\?token=3D/, message.body.raw_source.strip, 'No tracking image injected'
end

#test_send_mailObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 29

def test_send_mail
  @client.
  @client.clean_messages

  @client.deliver(
    'X-To' => "{\"#{@john}\":{\"name\":\"John Doe\"}}",
    'Subject' => 'Hello',
    'Body' => 'Hello, __NAME__'
  )

  message = @client.read_message
  assert_equal 'Hello', message.subject
  assert_equal 'Hello, John Doe', message.body.raw_source.strip
end

#test_send_newsletterObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 78

def test_send_newsletter
  @client.
  @client.clean_messages('john')
  @client.clean_messages('jane')

  @client.deliver(
    'X-Newsletter-Id' => '15',
    'X-To' => "[\"#{@john}\", \"#{@jane}\"]"
  )

  @client.read_message
  stat = @client.newsletter_statistics('15')
  assert_equal 2, stat['queued']
end

#test_transactional_routingObject



248
249
250
251
252
253
254
255
256
257
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 248

def test_transactional_routing
  @client.
  @client.clean_messages
  @client.deliver('X-To' => "[\"#{@john}\"]")

  received = @client.read_message.received
  assert_match /from (smtp0\.#{@base_domain}) \(\1\. /, received[-3].value
  assert_match 'from localhost.localdomain (localhost ', received[-2].value
  assert_match 'from localhost.localdomain (localhost ', received[-1].value
end