txbr 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+ require 'support/standard_setup'
3
+
4
+ describe Txbr::EmailTemplate do
5
+ include_context 'standard setup'
6
+
7
+ let(:email_template_id) { 'abc123' }
8
+ let(:email_template) { described_class.new(project, email_template_id) }
9
+
10
+ let(:template_html) do
11
+ <<~HTML
12
+ <html>
13
+ <head>
14
+ {% assign project_slug = "my_project" %}
15
+ {% assign resource_slug = "my_resource" %}
16
+ {% assign translation_enabled = true %}
17
+ {% connected_content http://my_strings_api.com/ :save strings %}
18
+ </head>
19
+ <body>
20
+ {{strings.header | default: 'Buy our stuff!'}}
21
+ {% if user.gets_discount? %}
22
+ {{strings.discount | default: 'You get a discount'}}
23
+ {% else %}
24
+ {{strings.no_discount | default: 'You get no discount'}}
25
+ {% endif %}
26
+ </body>
27
+ </html>
28
+ HTML
29
+ end
30
+
31
+ let(:subject_html) do
32
+ <<~HTML
33
+ {% assign project_slug = "my_project" %}
34
+ {% assign resource_slug = "my_resource" %}
35
+ {% assign translation_enabled = true %}
36
+ {% connected_content http://my_strings_api.com/ :save strings %}
37
+ {{strings.meta.subject_line | default: 'You lucky duck maybe'}}
38
+ HTML
39
+ end
40
+
41
+ let(:preheader_html) do
42
+ <<~HTML
43
+ {% assign project_slug = "my_project" %}
44
+ {% assign resource_slug = "my_resource" %}
45
+ {% assign translation_enabled = true %}
46
+ {% connected_content http://my_strings_api.com/ :save strings %}
47
+ {{strings.meta.preheader | default: 'Our stuff is the bomb and you should buy it.'}}
48
+ HTML
49
+ end
50
+
51
+ describe '#each_resource' do
52
+ let(:braze_interactions) do
53
+ [{
54
+ request: { verb: 'get', url: "engagement/email_templates/#{email_template_id}" },
55
+ response: {
56
+ status: 200,
57
+ body: {
58
+ name: 'Super Slick Awesome',
59
+ template: template_html,
60
+ subject: subject_html,
61
+ preheader: preheader_html
62
+ }.to_json
63
+ }
64
+ }]
65
+ end
66
+
67
+ it 'extracts and groups all strings with the same project, resource, and prefix' do
68
+ resources = email_template.each_resource.to_a
69
+ expect(resources.size).to eq(1)
70
+
71
+ resource = resources.first
72
+
73
+ # notice how it combined strings from the subject, preheader,
74
+ # and template (i.e. HTML body)
75
+ expect(resource.phrases).to eq([
76
+ { 'key' => 'header', 'string' => 'Buy our stuff!' },
77
+ { 'key' => 'discount', 'string' => 'You get a discount' },
78
+ { 'key' => 'no_discount', 'string' => 'You get no discount' },
79
+ { 'key' => 'meta.subject_line', 'string' => 'You lucky duck maybe' },
80
+ { 'key' => 'meta.preheader', 'string' => 'Our stuff is the bomb and you should buy it.' }
81
+ ])
82
+ end
83
+
84
+ it 'constructs a txgh resource' do
85
+ resource = email_template.each_resource.to_a.first
86
+ tx_resource = resource.tx_resource
87
+
88
+ expect(tx_resource.project_slug).to eq('my_project')
89
+ expect(tx_resource.resource_slug).to eq('my_resource')
90
+ expect(tx_resource.source_file).to eq('Super Slick Awesome')
91
+ expect(tx_resource.source_lang).to eq(project.source_lang)
92
+ expect(tx_resource.type).to eq(project.strings_format)
93
+ end
94
+
95
+ context 'with translations disabled for the subject' do
96
+ let(:subject_html) do
97
+ super().tap do |subj|
98
+ subj.sub!('translation_enabled = true', 'translation_enabled = false')
99
+ end
100
+ end
101
+
102
+ it 'does not include translations for the subject line' do
103
+ expect(email_template.each_resource.to_a.first.phrases).to_not(
104
+ include({ 'key' => 'meta.subject_line', 'string' => 'You lucky duck maybe' })
105
+ )
106
+ end
107
+ end
108
+
109
+ context 'when the subject comes from a separate resource' do
110
+ let(:subject_html) do
111
+ super().tap do |subj|
112
+ subj.sub!(
113
+ 'resource_slug = "my_resource"',
114
+ 'resource_slug = "my_other_resource"'
115
+ )
116
+ end
117
+ end
118
+
119
+ it 'includes two resources' do
120
+ resources = email_template.each_resource.to_a
121
+ expect(resources.size).to eq(2)
122
+
123
+ expect(resources.first.phrases).to_not(
124
+ include({ 'key' => 'meta.subject_line', 'string' => 'You lucky duck maybe' })
125
+ )
126
+
127
+ expect(resources.last.phrases).to eq(
128
+ [{ 'key' => 'meta.subject_line', 'string' => 'You lucky duck maybe' }]
129
+ )
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,324 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://dashboard-03.braze.com/auth?email=BRAZE_EMAIL_ADDRESS
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip,deflate,identity
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Mechanize/2.7.5 Ruby/2.5.1p57 (http://github.com/sparklemotion/mechanize/)
16
+ Accept-Charset:
17
+ - ISO-8859-1,utf-8;q=0.7,*;q=0.7
18
+ Accept-Language:
19
+ - en-us,en;q=0.5
20
+ Host:
21
+ - dashboard-03.braze.com
22
+ Connection:
23
+ - keep-alive
24
+ Keep-Alive:
25
+ - '300'
26
+ response:
27
+ status:
28
+ code: 200
29
+ message: OK
30
+ headers:
31
+ Cache-Control:
32
+ - max-age=0, private, must-revalidate
33
+ Content-Encoding:
34
+ - gzip
35
+ Content-Type:
36
+ - text/html; charset=utf-8
37
+ Etag:
38
+ - W/"0350212486d4a8ab5be5221a08898626"
39
+ Server:
40
+ - nginx
41
+ Set-Cookie:
42
+ - _session_id=123abc123abc123abc123abc123abc12; path=/; secure; HttpOnly
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ X-Frame-Options:
46
+ - SAMEORIGIN
47
+ X-Request-Id:
48
+ - b8a8efff-1307-410b-b09a-ae8d74088b69
49
+ X-Runtime:
50
+ - '0.024584'
51
+ X-Xss-Protection:
52
+ - 1; mode=block
53
+ Content-Length:
54
+ - '2352'
55
+ Accept-Ranges:
56
+ - bytes
57
+ Date:
58
+ - Thu, 31 May 2018 19:51:53 GMT
59
+ Via:
60
+ - 1.1 varnish
61
+ Age:
62
+ - '0'
63
+ Connection:
64
+ - keep-alive
65
+ X-Served-By:
66
+ - cache-sjc3137-SJC
67
+ X-Cache:
68
+ - MISS
69
+ X-Cache-Hits:
70
+ - '0'
71
+ X-Timer:
72
+ - S1527796313.967896,VS0,VE103
73
+ Vary:
74
+ - Accept-Encoding
75
+ Strict-Transport-Security:
76
+ - max-age=86400; includeSubDomains
77
+ body:
78
+ encoding: ASCII-8BIT
79
+ string: !binary |-
80
+ H4sIAAAAAAAAA51YeVPcyBX/n0/RO6kKEI9G9xUYHOMFm/gCG++uTbmoPkcCjVpIPcB4vd89r1vSjDicInFhkNT97t87und/YZKqZcVRpubF3sZu/4djtreB0O6cKwxrqrL41SK/no5eylLxUlmnQDRCtH2bjhS/VbYm3kE0w3XD1XShhJWMDJciLy9RzYvpiJWNVdVccEWzEcrgaTqybXyBbyczKWcFx1XeTKicA6GmVLkq+N5bOUN5iZRE+zX+ztGP9u+u3S6bnUaGNqVThjbNqJXZqGXBm4xz1UvUBjX/tG2BGzURYEMzKbmygQTE20EUuIIQYTkuoVbAU9dKfI9YKQ8SHEZJ6AXpRLO318Y9UfDPRPoBjoUAaVEaeVaASWKRQIRWirFHAi9MuKC9yLsOHRo35yzH01FDa87LlXdxA9FobMav84ZblMRhwkgciRTHMeMJSQQnYSwiJuLEYUnipY7HSEi464gEflxKSeoKRjijbmK0QAPLTVifrEVequKUF0dltVAWdRjxeBqAEnFKIk4wDZLQjVjsuswXIqXU91MapHFCIjfBUcrTKBDwzlzHc8lKF3DJo2D9w/r8wnop5xVWOSmGeD06mHI242Oa1XLOpy7ArcV6j95RD9+NbqHEsG/EOHg3r1QuwcEr9K/xuZSLugMpw01GJK7ZZMW85YEXKpP1gNyAugO8gXGXFwJf5yBjAr96KAOhoguF9PdRB/d8jmfcvrXabxCajd1fLAtd5/ymgu2owWWulkjIGs0lyQuOSC1vGl43E2RZveGtbj3RQLubnKlsquFDuWVexjkwzHFhNRQXnfO0xKODFB3nZckZ+pQr3qBPi8pocF8KrqoipxAUWVpa7n1foF973xmotZFpFZxDiq6JlZSFyqsB/TtcgjfQIA68xBB7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Maw20EwQm433W564GBLA5jB66CUuGkgonggWwY1tshHYZ2c6v2HyQG0CpmEwAA
81
+ http_version:
82
+ recorded_at: Thu, 31 May 2018 19:51:53 GMT
83
+ - request:
84
+ method: post
85
+ uri: https://dashboard-03.braze.com/developers/sign_in
86
+ body:
87
+ encoding: UTF-8
88
+ string: utf8=%E2%9C%93&authenticity_token=Rsnzetj99fW5C6sSB7vgpn89rskQ9eMtCcss%2BjthERU38BetZTlfrGyqAodqNKalJhL3t9kqMcmHPFZ0PthjNQ%3D%3D&developer%5Bemail%5D=BRAZE_EMAIL_ADDRESS&developer%5Bpassword%5D=BRAZE_PASSWORD
89
+ headers:
90
+ Accept-Encoding:
91
+ - gzip,deflate,identity
92
+ Accept:
93
+ - "*/*"
94
+ User-Agent:
95
+ - Mechanize/2.7.5 Ruby/2.5.1p57 (http://github.com/sparklemotion/mechanize/)
96
+ Accept-Charset:
97
+ - ISO-8859-1,utf-8;q=0.7,*;q=0.7
98
+ Accept-Language:
99
+ - en-us,en;q=0.5
100
+ Cookie:
101
+ - _session_id=123abc123abc123abc123abc123abc12
102
+ Host:
103
+ - dashboard-03.braze.com
104
+ Referer:
105
+ - https://dashboard-03.braze.com/auth?email=BRAZE_EMAIL_ADDRESS
106
+ Content-Type:
107
+ - application/x-www-form-urlencoded
108
+ Content-Length:
109
+ - '219'
110
+ Connection:
111
+ - keep-alive
112
+ Keep-Alive:
113
+ - '300'
114
+ response:
115
+ status:
116
+ code: 302
117
+ message: Found
118
+ headers:
119
+ Cache-Control:
120
+ - no-cache
121
+ Content-Type:
122
+ - text/html; charset=utf-8
123
+ Location:
124
+ - https://dashboard-03.braze.com/dashboard
125
+ Server:
126
+ - nginx
127
+ Set-Cookie:
128
+ - _session_id=123abc123abc123abc123abc123abc12; path=/; secure; HttpOnly
129
+ - remember_login_enc_v1=HhZn20fKb8HUFr4vpxoWbw%3D%3D%24CCaTLGofO%2BnbDjIQ56p%2BhQ%3D%3D;
130
+ domain=.braze.com; path=/; expires=Wed, 30 May 2018 19:51:53 -0000
131
+ X-Content-Type-Options:
132
+ - nosniff
133
+ X-Frame-Options:
134
+ - SAMEORIGIN
135
+ X-Request-Id:
136
+ - b072ed0b-b60a-4dd5-92ca-b68dbbb8b051
137
+ X-Runtime:
138
+ - '0.125571'
139
+ X-Xss-Protection:
140
+ - 1; mode=block
141
+ Content-Length:
142
+ - '0'
143
+ Accept-Ranges:
144
+ - bytes
145
+ Date:
146
+ - Thu, 31 May 2018 19:51:53 GMT
147
+ Via:
148
+ - 1.1 varnish
149
+ Connection:
150
+ - keep-alive
151
+ X-Served-By:
152
+ - cache-sjc3129-SJC
153
+ X-Cache:
154
+ - MISS
155
+ X-Cache-Hits:
156
+ - '0'
157
+ X-Timer:
158
+ - S1527796313.089966,VS0,VE414
159
+ Strict-Transport-Security:
160
+ - max-age=86400; includeSubDomains
161
+ body:
162
+ encoding: UTF-8
163
+ string: ''
164
+ http_version:
165
+ recorded_at: Thu, 31 May 2018 19:51:53 GMT
166
+ - request:
167
+ method: get
168
+ uri: https://dashboard-03.braze.com/dashboard
169
+ body:
170
+ encoding: US-ASCII
171
+ string: ''
172
+ headers:
173
+ Accept-Encoding:
174
+ - gzip,deflate,identity
175
+ Accept:
176
+ - "*/*"
177
+ User-Agent:
178
+ - Mechanize/2.7.5 Ruby/2.5.1p57 (http://github.com/sparklemotion/mechanize/)
179
+ Accept-Charset:
180
+ - ISO-8859-1,utf-8;q=0.7,*;q=0.7
181
+ Accept-Language:
182
+ - en-us,en;q=0.5
183
+ Cookie:
184
+ - _session_id=123abc123abc123abc123abc123abc12
185
+ Host:
186
+ - dashboard-03.braze.com
187
+ Referer:
188
+ - https://dashboard-03.braze.com/auth?email=BRAZE_EMAIL_ADDRESS
189
+ Connection:
190
+ - keep-alive
191
+ Keep-Alive:
192
+ - '300'
193
+ response:
194
+ status:
195
+ code: 302
196
+ message: Found
197
+ headers:
198
+ Cache-Control:
199
+ - no-cache
200
+ Content-Type:
201
+ - text/html; charset=utf-8
202
+ Location:
203
+ - https://dashboard-03.braze.com/dashboard/app_usage
204
+ Server:
205
+ - nginx
206
+ X-Content-Type-Options:
207
+ - nosniff
208
+ X-Frame-Options:
209
+ - SAMEORIGIN
210
+ X-Request-Id:
211
+ - 2613eba9-0357-4080-86f6-313e17d1b227
212
+ X-Runtime:
213
+ - '0.022998'
214
+ X-Xss-Protection:
215
+ - 1; mode=block
216
+ Content-Length:
217
+ - '0'
218
+ Accept-Ranges:
219
+ - bytes
220
+ Date:
221
+ - Thu, 31 May 2018 19:51:53 GMT
222
+ Via:
223
+ - 1.1 varnish
224
+ Age:
225
+ - '0'
226
+ Connection:
227
+ - keep-alive
228
+ X-Served-By:
229
+ - cache-sjc3132-SJC
230
+ X-Cache:
231
+ - MISS
232
+ X-Cache-Hits:
233
+ - '0'
234
+ X-Timer:
235
+ - S1527796314.518727,VS0,VE102
236
+ Strict-Transport-Security:
237
+ - max-age=86400; includeSubDomains
238
+ body:
239
+ encoding: UTF-8
240
+ string: ''
241
+ http_version:
242
+ recorded_at: Thu, 31 May 2018 19:51:53 GMT
243
+ - request:
244
+ method: get
245
+ uri: https://dashboard-03.braze.com/dashboard/app_usage
246
+ body:
247
+ encoding: US-ASCII
248
+ string: ''
249
+ headers:
250
+ Accept-Encoding:
251
+ - gzip,deflate,identity
252
+ Accept:
253
+ - "*/*"
254
+ User-Agent:
255
+ - Mechanize/2.7.5 Ruby/2.5.1p57 (http://github.com/sparklemotion/mechanize/)
256
+ Accept-Charset:
257
+ - ISO-8859-1,utf-8;q=0.7,*;q=0.7
258
+ Accept-Language:
259
+ - en-us,en;q=0.5
260
+ Cookie:
261
+ - _session_id=123abc123abc123abc123abc123abc12
262
+ Host:
263
+ - dashboard-03.braze.com
264
+ Referer:
265
+ - https://dashboard-03.braze.com/auth?email=BRAZE_EMAIL_ADDRESS
266
+ Connection:
267
+ - keep-alive
268
+ Keep-Alive:
269
+ - '300'
270
+ response:
271
+ status:
272
+ code: 200
273
+ message: OK
274
+ headers:
275
+ Cache-Control:
276
+ - max-age=0, private, must-revalidate
277
+ Content-Encoding:
278
+ - gzip
279
+ Content-Type:
280
+ - text/html; charset=utf-8
281
+ Etag:
282
+ - W/"17d621ec3966c40ca1fbd8206ed65de6"
283
+ Server:
284
+ - nginx
285
+ X-Content-Type-Options:
286
+ - nosniff
287
+ X-Frame-Options:
288
+ - SAMEORIGIN
289
+ X-Request-Id:
290
+ - 97db1283-331e-4f93-8f26-7a39632b56b7
291
+ X-Runtime:
292
+ - '0.226427'
293
+ X-Xss-Protection:
294
+ - 1; mode=block
295
+ Content-Length:
296
+ - '0'
297
+ Accept-Ranges:
298
+ - bytes
299
+ Date:
300
+ - Thu, 31 May 2018 19:51:54 GMT
301
+ Via:
302
+ - 1.1 varnish
303
+ Age:
304
+ - '0'
305
+ Connection:
306
+ - keep-alive
307
+ X-Served-By:
308
+ - cache-sjc3134-SJC
309
+ X-Cache:
310
+ - MISS
311
+ X-Cache-Hits:
312
+ - '0'
313
+ X-Timer:
314
+ - S1527796314.634948,VS0,VE537
315
+ Vary:
316
+ - Accept-Encoding
317
+ Strict-Transport-Security:
318
+ - max-age=86400; includeSubDomains
319
+ body:
320
+ encoding: UTF-8
321
+ string: ''
322
+ http_version:
323
+ recorded_at: Thu, 31 May 2018 19:51:54 GMT
324
+ recorded_with: VCR 4.0.0