Leon4gr45 commited on
Commit
99856fc
·
verified ·
1 Parent(s): 9978cda

Delete test/plausible_web/email_test.exs with huggingface_hub

Browse files
Files changed (1) hide show
  1. test/plausible_web/email_test.exs +0 -451
test/plausible_web/email_test.exs DELETED
@@ -1,451 +0,0 @@
1
- defmodule PlausibleWeb.EmailTest do
2
- use Plausible.DataCase, async: true
3
-
4
- import Plausible.Factory
5
-
6
- alias PlausibleWeb.Email
7
-
8
- describe "base_email layout" do
9
- test "greets user by first name if user in template assigns" do
10
- email =
11
- Email.base_email()
12
- |> Email.render("welcome_email.html", %{
13
- user: build(:user, name: "John Doe"),
14
- code: "123"
15
- })
16
-
17
- assert email.html_body =~ "Hey John,"
18
- assert email.text_body =~ "Hey John,"
19
- end
20
-
21
- test "greets impersonally when user not in template assigns" do
22
- email =
23
- Email.base_email()
24
- |> Email.render("welcome_email.html")
25
-
26
- assert email.html_body =~ "Hey,"
27
- assert email.text_body =~ "Hey,"
28
- end
29
-
30
- test "renders plausible link" do
31
- email =
32
- Email.base_email()
33
- |> Email.render("welcome_email.html")
34
-
35
- assert email.html_body =~ plausible_link()
36
- assert email.text_body =~ plausible_url()
37
- end
38
-
39
- @tag :ee_only
40
- test "renders unsubscribe placeholder" do
41
- email =
42
- Email.base_email()
43
- |> Email.render("welcome_email.html")
44
-
45
- assert email.html_body =~ "{{{ pm:unsubscribe }}}"
46
- end
47
-
48
- test "can be disabled with a nil layout" do
49
- email =
50
- Email.base_email(%{layout: nil})
51
- |> Email.render("welcome_email.html", %{
52
- user: build(:user, name: "John Doe")
53
- })
54
-
55
- refute email.html_body =~ "Hey John,"
56
-
57
- refute email.text_body =~ "Hey John,"
58
- end
59
- end
60
-
61
- describe "priority email layout" do
62
- @tag :ee_only
63
- test "uses the `priority` message stream in Postmark in EE" do
64
- email =
65
- Email.priority_email()
66
- |> Email.render("activation_email.html", %{
67
- user: build(:user, name: "John Doe"),
68
- code: "123"
69
- })
70
-
71
- assert %{"MessageStream" => "priority"} = email.private[:message_params]
72
- end
73
-
74
- @tag :ce_build_only
75
- test "doesn't use the `priority` message stream in Postmark in CE" do
76
- email =
77
- Email.priority_email()
78
- |> Email.render("activation_email.html", %{
79
- user: build(:user, name: "John Doe"),
80
- code: "123"
81
- })
82
-
83
- refute email.private[:message_params]["MessageStream"]
84
- end
85
-
86
- test "greets user by first name if user in template assigns" do
87
- email =
88
- Email.priority_email()
89
- |> Email.render("activation_email.html", %{
90
- user: build(:user, name: "John Doe"),
91
- code: "123"
92
- })
93
-
94
- assert email.html_body =~ "Hey John,"
95
- assert email.text_body =~ "Hey John,"
96
- end
97
-
98
- test "greets impersonally when user not in template assigns" do
99
- email =
100
- Email.priority_email()
101
- |> Email.render("password_reset_email.html", %{
102
- reset_link: "imaginary"
103
- })
104
-
105
- assert email.html_body =~ "Hey,"
106
- assert email.text_body =~ "Hey,"
107
- end
108
-
109
- test "renders plausible link" do
110
- email =
111
- Email.priority_email()
112
- |> Email.render("password_reset_email.html", %{
113
- reset_link: "imaginary"
114
- })
115
-
116
- assert email.html_body =~ plausible_link()
117
- assert email.text_body =~ plausible_url()
118
- end
119
-
120
- test "does not render unsubscribe placeholder" do
121
- email =
122
- Email.priority_email()
123
- |> Email.render("password_reset_email.html", %{
124
- reset_link: "imaginary"
125
- })
126
-
127
- refute email.html_body =~ "{{{ pm:unsubscribe }}}"
128
- end
129
-
130
- test "can be disabled with a nil layout" do
131
- email =
132
- Email.priority_email(%{layout: nil})
133
- |> Email.render("password_reset_email.html", %{
134
- reset_link: "imaginary"
135
- })
136
-
137
- refute email.html_body =~ "Hey John,"
138
- refute email.html_body =~ plausible_link()
139
-
140
- refute email.text_body =~ "Hey John,"
141
- refute email.text_body =~ plausible_url()
142
- end
143
- end
144
-
145
- describe "over_limit_email/3" do
146
- test "renders usage, suggested plan, and links to upgrade and account settings" do
147
- user = build(:user)
148
- team = build(:team, identifier: Ecto.UUID.generate())
149
- penultimate_cycle = Date.range(~D[2023-03-01], ~D[2023-03-31])
150
- last_cycle = Date.range(~D[2023-04-01], ~D[2023-04-30])
151
-
152
- usage = %{
153
- penultimate_cycle: %{date_range: penultimate_cycle, total: 12_300},
154
- last_cycle: %{date_range: last_cycle, total: 32_100}
155
- }
156
-
157
- %{html_body: html_body, subject: subject} =
158
- PlausibleWeb.Email.over_limit_email(user, team, usage, "100k")
159
-
160
- assert subject == "[Action required] You have outgrown your Plausible subscription tier"
161
-
162
- assert html_body =~ PlausibleWeb.TextHelpers.format_date_range(last_cycle)
163
- assert html_body =~ "We recommend you upgrade to the 100k pageviews/month plan"
164
- assert html_body =~ "your account recorded 32,100 billable pageviews"
165
-
166
- assert html_body =~
167
- "cycle before that (#{PlausibleWeb.TextHelpers.format_date_range(penultimate_cycle)}), your account used 12,300 billable pageviews"
168
-
169
- assert text_of_element(
170
- html_body,
171
- ~s|a[href$="/billing/choose-plan?__team=#{team.identifier}"]|
172
- ) ==
173
- "Click here to upgrade your subscription"
174
-
175
- assert text_of_element(
176
- html_body,
177
- ~s|a[href$="/settings/billing/subscription?__team=#{team.identifier}"]|
178
- ) ==
179
- "account settings"
180
-
181
- assert html_body =~
182
- PlausibleWeb.Router.Helpers.billing_url(PlausibleWeb.Endpoint, :choose_plan) <>
183
- "?__team=#{team.identifier}"
184
- end
185
-
186
- test "asks enterprise level usage to contact us" do
187
- user = build(:user)
188
- team = build(:team, identifier: Ecto.UUID.generate())
189
- penultimate_cycle = Date.range(~D[2023-03-01], ~D[2023-03-31])
190
- last_cycle = Date.range(~D[2023-04-01], ~D[2023-04-30])
191
- suggested_plan = :enterprise
192
-
193
- usage = %{
194
- penultimate_cycle: %{date_range: penultimate_cycle, total: 12_300},
195
- last_cycle: %{date_range: last_cycle, total: 32_100}
196
- }
197
-
198
- %{html_body: html_body} =
199
- PlausibleWeb.Email.over_limit_email(user, team, usage, suggested_plan)
200
-
201
- refute html_body =~ "Click here to upgrade your subscription"
202
- assert html_body =~ "Your usage exceeds our standard plans, so please reply back"
203
- end
204
- end
205
-
206
- describe "dashboard_locked/3" do
207
- test "renders usage, suggested plan, and links to upgrade and account settings" do
208
- user = build(:user)
209
- team = build(:team, identifier: Ecto.UUID.generate())
210
- penultimate_cycle = Date.range(~D[2023-03-01], ~D[2023-03-31])
211
- last_cycle = Date.range(~D[2023-04-01], ~D[2023-04-30])
212
-
213
- usage = %{
214
- penultimate_cycle: %{date_range: penultimate_cycle, total: 12_300},
215
- last_cycle: %{date_range: last_cycle, total: 32_100}
216
- }
217
-
218
- %{html_body: html_body, subject: subject} =
219
- PlausibleWeb.Email.dashboard_locked(user, team, usage, "100k")
220
-
221
- assert subject == "[Action required] Your Plausible dashboard is now locked"
222
-
223
- assert html_body =~ PlausibleWeb.TextHelpers.format_date_range(last_cycle)
224
- assert html_body =~ "We recommend you upgrade to the 100k pageviews/month plan"
225
- assert html_body =~ "your account recorded 32,100 billable pageviews"
226
-
227
- assert html_body =~
228
- "cycle before that (#{PlausibleWeb.TextHelpers.format_date_range(penultimate_cycle)}), the usage was 12,300 billable pageviews"
229
-
230
- assert text_of_element(
231
- html_body,
232
- ~s|a[href$="/billing/choose-plan?__team=#{team.identifier}"]|
233
- ) ==
234
- "Click here to upgrade your subscription"
235
-
236
- assert text_of_element(
237
- html_body,
238
- ~s|a[href$="/settings/billing/subscription?__team=#{team.identifier}"]|
239
- ) ==
240
- "account settings"
241
-
242
- assert html_body =~
243
- PlausibleWeb.Router.Helpers.billing_url(PlausibleWeb.Endpoint, :choose_plan) <>
244
- "?__team=#{team.identifier}"
245
- end
246
-
247
- test "asks enterprise level usage to contact us" do
248
- user = build(:user)
249
- team = build(:team, identifier: Ecto.UUID.generate())
250
- penultimate_cycle = Date.range(~D[2023-03-01], ~D[2023-03-31])
251
- last_cycle = Date.range(~D[2023-04-01], ~D[2023-04-30])
252
- suggested_plan = :enterprise
253
-
254
- usage = %{
255
- penultimate_cycle: %{date_range: penultimate_cycle, total: 12_300},
256
- last_cycle: %{date_range: last_cycle, total: 32_100}
257
- }
258
-
259
- %{html_body: html_body} =
260
- PlausibleWeb.Email.dashboard_locked(user, team, usage, suggested_plan)
261
-
262
- refute html_body =~ "Click here to upgrade your subscription"
263
- assert html_body =~ "Your usage exceeds our standard plans, so please reply back"
264
- end
265
- end
266
-
267
- describe "enterprise_over_limit_internal_email/4" do
268
- test "renders pageview usage by billing cycles + sites usage/limit" do
269
- user = build(:user)
270
- penultimate_cycle = Date.range(~D[2023-03-01], ~D[2023-03-31])
271
- last_cycle = Date.range(~D[2023-04-01], ~D[2023-04-30])
272
-
273
- pageview_usage = %{
274
- penultimate_cycle: %{date_range: penultimate_cycle, total: 100_141_888},
275
- last_cycle: %{date_range: last_cycle, total: 100_222_999}
276
- }
277
-
278
- %{html_body: html_body, subject: subject} =
279
- PlausibleWeb.Email.enterprise_over_limit_internal_email(user, pageview_usage, 80, 50)
280
-
281
- assert subject == "#{user.email} has outgrown their enterprise plan"
282
-
283
- assert html_body =~
284
- "Last billing cycle: #{PlausibleWeb.TextHelpers.format_date_range(last_cycle)}"
285
-
286
- assert html_body =~ "Last cycle pageview usage: 100,222,999 billable pageviews"
287
-
288
- assert html_body =~
289
- "Penultimate billing cycle: #{PlausibleWeb.TextHelpers.format_date_range(penultimate_cycle)}"
290
-
291
- assert html_body =~ "Penultimate cycle pageview usage: 100,141,888 billable pageviews"
292
- assert html_body =~ "Site usage: 80 / 50 allowed sites"
293
- end
294
- end
295
-
296
- describe "approaching accept_traffic_until" do
297
- test "renders first warning" do
298
- user = build(:user, id: 123, name: "John Doe")
299
- team = build(:team, identifier: Ecto.UUID.generate())
300
-
301
- notification = %{
302
- id: user.id,
303
- email: user.email,
304
- deadline: Date.add(Date.utc_today(), 7),
305
- site_ids: [1, 2, 3],
306
- name: user.name,
307
- team: team
308
- }
309
-
310
- %{html_body: body, subject: subject} =
311
- PlausibleWeb.Email.approaching_accept_traffic_until(notification)
312
-
313
- assert subject == "Your stats stop collecting soon"
314
- assert body =~ plausible_link(team: team, label: "start a Plausible subscription")
315
- assert body =~ "Hey John,"
316
-
317
- assert body =~
318
- "Your sites are still sending us data, but your account is no longer active. We'll stop counting your stats next week."
319
- end
320
-
321
- test "renders final warning" do
322
- user = build(:user, id: 123, name: "John Doe")
323
- team = build(:team, identifier: Ecto.UUID.generate())
324
-
325
- notification = %{
326
- id: user.id,
327
- email: user.email,
328
- deadline: Date.add(Date.utc_today(), 1),
329
- site_ids: [1, 2, 3],
330
- name: user.name,
331
- team: team
332
- }
333
-
334
- %{html_body: body, subject: subject} =
335
- PlausibleWeb.Email.approaching_accept_traffic_until_tomorrow(notification)
336
-
337
- assert subject == "Your stats stop tomorrow"
338
- assert body =~ plausible_link(team: team, label: "start a Plausible subscription")
339
-
340
- assert body =~
341
- "Your sites are still sending us data, but your account is no longer active. We'll stop counting your stats tomorrow."
342
- end
343
- end
344
-
345
- describe "site setup emails" do
346
- setup do
347
- trial_user = new_user(trial_expiry_date: Date.add(Date.utc_today(), 100))
348
- site = new_site(owner: trial_user)
349
-
350
- emails = [
351
- PlausibleWeb.Email.create_site_email(trial_user),
352
- PlausibleWeb.Email.site_setup_help(trial_user, site.team, site),
353
- PlausibleWeb.Email.site_setup_success(trial_user, site)
354
- ]
355
-
356
- {:ok, emails: emails, user: trial_user, site: site}
357
- end
358
-
359
- test "create site email", %{user: user} do
360
- email = PlausibleWeb.Email.create_site_email(user)
361
-
362
- assert email.html_body =~
363
- "You’ve created your Plausible account but haven’t added a site yet."
364
- end
365
-
366
- test "site setup help email", %{user: user, site: site} do
367
- email = PlausibleWeb.Email.site_setup_help(user, site.team, site)
368
-
369
- assert email.html_body =~
370
- "We haven't recorded any traffic for #{site.domain} yet."
371
- end
372
-
373
- test "site setup success email", %{user: user, site: site} do
374
- email = PlausibleWeb.Email.site_setup_success(user, site)
375
-
376
- assert email.html_body =~ "Your first visitor is now visible in Plausible."
377
- end
378
- end
379
-
380
- describe "import emails" do
381
- setup do
382
- user = new_user()
383
- site = new_site(owner: user)
384
-
385
- {:ok, user: user, site: site}
386
- end
387
-
388
- for {source, success_phrase, failure_phrase} <- [
389
- {:google_analytics_4, "Your Google Analytics import has completed successfully",
390
- "Unfortunately, your Google Analytics import for"},
391
- {:universal_analytics, "Your Google Analytics import has completed successfully",
392
- "Unfortunately, your Google Analytics import for"},
393
- {:csv, "Your CSV import has completed successfully",
394
- "Unfortunately, your CSV import for"}
395
- ] do
396
- test "success email for #{source}", %{user: user, site: site} do
397
- site_import = insert(:site_import, site: site, source: unquote(source))
398
- PlausibleWeb.Email.import_success(site_import, user)
399
-
400
- email = PlausibleWeb.Email.import_success(site_import, user)
401
-
402
- assert email.text_body =~ unquote(success_phrase)
403
- end
404
-
405
- test "failure email for #{source}", %{user: user, site: site} do
406
- site_import = insert(:site_import, site: site, source: unquote(source))
407
-
408
- email = PlausibleWeb.Email.import_failure(site_import, user)
409
-
410
- assert email.text_body =~ unquote(failure_phrase)
411
- end
412
- end
413
- end
414
-
415
- describe "text_body" do
416
- test "welcome email" do
417
- email =
418
- Email.base_email()
419
- |> Email.render("welcome_email.html", %{
420
- user: build(:user, name: "John Doe"),
421
- code: "123"
422
- })
423
-
424
- assert email.text_body =~ "Welcome to Plausible."
425
- end
426
- end
427
-
428
- def plausible_url do
429
- PlausibleWeb.EmailView.plausible_url()
430
- end
431
-
432
- def plausible_link(opts \\ []) do
433
- suffix =
434
- if team = Keyword.get(opts, :team) do
435
- "?__team=#{team.identifier}"
436
- else
437
- ""
438
- end
439
-
440
- plausible_url = plausible_url()
441
-
442
- label =
443
- if label = Keyword.get(opts, :label) do
444
- label
445
- else
446
- plausible_url
447
- end
448
-
449
- "<a href=\"#{plausible_url <> suffix}\">#{label}</a>"
450
- end
451
- end