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

#setupObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 9

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

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

#test_authentication_resultsObject



192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 192

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



255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 255

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



20
21
22
23
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 20

def 
  @client.
  refute_nil @client.
end

#test_custom_tracking_domainObject



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 206

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



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 228

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



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 143

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



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

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



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

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



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

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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 25

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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 74

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



244
245
246
247
248
249
250
251
252
253
# File 'lib/mailsocio_qa/mailsocio_test.rb', line 244

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