Skip to content

Commit

Permalink
add full text_body test
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Dec 6, 2024
1 parent 1405b23 commit aa64bfa
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 40 deletions.
6 changes: 2 additions & 4 deletions test/plausible/imported/csv_importer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,8 @@ defmodule Plausible.Imported.CSVImporterTest do
assert email.html_body =~
~s[Please click <a href="http://localhost:8000/#{URI.encode_www_form(exported_site.domain)}/download/export">here</a>]

if Plausible.ce?() do
assert email.text_body =~
~r[Please click here \(http://localhost:8000/#{URI.encode_www_form(exported_site.domain)}/download/export\) to start the download process.]
end
assert email.text_body =~
~r[Please click here \(http://localhost:8000/#{URI.encode_www_form(exported_site.domain)}/download/export\) to start the download process.]

# download archive
on_ee do
Expand Down
103 changes: 71 additions & 32 deletions test/plausible_web/email_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ defmodule PlausibleWeb.EmailTest do
})

assert email.html_body =~ "Hey John,"

if Plausible.ce?() do
assert email.text_body =~ "Hey John,"
end
assert email.text_body =~ "Hey John,"
end

test "greets impersonally when user not in template assigns" do
Expand All @@ -26,10 +23,7 @@ defmodule PlausibleWeb.EmailTest do
|> Email.render("welcome_email.html")

assert email.html_body =~ "Hey,"

if Plausible.ce?() do
assert email.text_body =~ "Hey,"
end
assert email.text_body =~ "Hey,"
end

test "renders plausible link" do
Expand All @@ -38,10 +32,7 @@ defmodule PlausibleWeb.EmailTest do
|> Email.render("welcome_email.html")

assert email.html_body =~ plausible_link()

if Plausible.ce?() do
assert email.text_body =~ plausible_url()
end
assert email.text_body =~ plausible_url()
end

@tag :ee_only
Expand All @@ -63,10 +54,8 @@ defmodule PlausibleWeb.EmailTest do
refute email.html_body =~ "Hey John,"
refute email.html_body =~ plausible_link()

if Plausible.ce?() do
refute email.text_body =~ "Hey John,"
refute email.text_body =~ plausible_url()
end
refute email.text_body =~ "Hey John,"
refute email.text_body =~ plausible_url()
end
end

Expand All @@ -91,10 +80,7 @@ defmodule PlausibleWeb.EmailTest do
})

assert email.html_body =~ "Hey John,"

if Plausible.ce?() do
assert email.text_body =~ "Hey John,"
end
assert email.text_body =~ "Hey John,"
end

test "greets impersonally when user not in template assigns" do
Expand All @@ -105,10 +91,7 @@ defmodule PlausibleWeb.EmailTest do
})

assert email.html_body =~ "Hey,"

if Plausible.ce?() do
assert email.text_body =~ "Hey,"
end
assert email.text_body =~ "Hey,"
end

test "renders plausible link" do
Expand All @@ -119,10 +102,7 @@ defmodule PlausibleWeb.EmailTest do
})

assert email.html_body =~ plausible_link()

if Plausible.ce?() do
assert email.text_body =~ plausible_url()
end
assert email.text_body =~ plausible_url()
end

test "does not render unsubscribe placeholder" do
Expand All @@ -145,10 +125,8 @@ defmodule PlausibleWeb.EmailTest do
refute email.html_body =~ "Hey John,"
refute email.html_body =~ plausible_link()

if Plausible.ce?() do
refute email.text_body =~ "Hey John,"
refute email.text_body =~ plausible_url()
end
refute email.text_body =~ "Hey John,"
refute email.text_body =~ plausible_url()
end
end

Expand Down Expand Up @@ -347,6 +325,67 @@ defmodule PlausibleWeb.EmailTest do
end
end

describe "text_body" do
test "renders text version of the email" do

Check failure on line 329 in test/plausible_web/email_test.exs

View workflow job for this annotation

GitHub Actions / Build and test (ce_test, postgres:16)

test text_body renders text version of the email (PlausibleWeb.EmailTest)
email =
Email.base_email()
|> Email.render("welcome_email.html", %{
user: build(:user, name: "John Doe"),
code: "123"
})

assert email.text_body == """
Hey John,
We are building Plausible to provide a simple and ethical approach to tracking website visitors.
We're super excited to have you on board!\s
Here's how to get the most out of your Plausible experience:\s
*
Enable email reports (https://plausible.io/docs/email-reports) and notifications for
traffic spikes (https://plausible.io/docs/traffic-spikes)
*
Integrate with Search Console (https://plausible.io/docs/google-search-console-integration) to get keyword phrases people find your site with
* Invite team members and other collaborators (https://plausible.io/docs/users-roles)
* Set up easy goals including
404 error pages (https://plausible.io/docs/error-pages-tracking-404),
file downloads (https://plausible.io/docs/file-downloads-tracking) and
outbound link clicks (https://plausible.io/docs/outbound-link-click-tracking)
* Opt out from counting your own visits (https://plausible.io/docs/excluding)
* If you're concerned about adblockers,
set up a proxy to bypass them (https://plausible.io/docs/proxy/introduction)
Then you're ready to start exploring your fast loading, ethical and actionable
Plausible dashboard (https://plausible.io/sites).\s
Have a question, feedback or need some guidance? Do reply back to this email.
Regards,
The Plausible Team 💌\s
--\s
http://localhost:8000
{{{ pm:unsubscribe }}}
"""
end
end

def plausible_url do
PlausibleWeb.EmailView.plausible_url()
end
Expand Down
5 changes: 1 addition & 4 deletions test/workers/notify_exported_analytics_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ defmodule Plausible.Workers.NotifyExportedAnalyticsTest do

assert_receive {:delivered_email, email}
assert email.html_body =~ "was unsuccessful."

if Plausible.ce?() do
assert email.text_body =~ "was unsuccessful."
end
assert email.text_body =~ "was unsuccessful."
end
end
end

0 comments on commit aa64bfa

Please sign in to comment.