2020-06-02 13:37:38 +03:00
|
|
|
defmodule Plausible.Workers.SendSiteSetupEmailsTest do
|
2022-05-06 10:30:38 +03:00
|
|
|
use Plausible.DataCase, async: true
|
2020-03-23 12:34:25 +03:00
|
|
|
use Bamboo.Test
|
2021-04-26 11:32:18 +03:00
|
|
|
use Oban.Testing, repo: Plausible.Repo
|
2022-10-24 10:34:02 +03:00
|
|
|
|
2020-06-02 13:37:38 +03:00
|
|
|
alias Plausible.Workers.SendSiteSetupEmails
|
|
|
|
|
2020-03-23 12:34:25 +03:00
|
|
|
describe "when user has not managed to set up the site" do
|
|
|
|
test "does not send an email 47 hours after site creation" do
|
|
|
|
user = insert(:user)
|
|
|
|
insert(:site, members: [user], inserted_at: hours_ago(47))
|
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
2020-03-23 12:34:25 +03:00
|
|
|
|
|
|
|
assert_no_emails_delivered()
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sends a setup help email 48 hours after site has been created" do
|
|
|
|
user = insert(:user)
|
|
|
|
insert(:site, members: [user], inserted_at: hours_ago(49))
|
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
2020-03-23 12:34:25 +03:00
|
|
|
|
|
|
|
assert_email_delivered_with(
|
|
|
|
to: [{user.name, user.email}],
|
|
|
|
subject: "Your Plausible setup: Waiting for the first page views"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "does not send an email more than 72 hours after signup" do
|
|
|
|
user = insert(:user)
|
|
|
|
insert(:site, members: [user], inserted_at: hours_ago(73))
|
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
2020-03-23 12:34:25 +03:00
|
|
|
|
|
|
|
assert_no_emails_delivered()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when user has managed to set up their site" do
|
|
|
|
test "sends the setup completed email as soon as possible" do
|
|
|
|
user = insert(:user)
|
2020-06-08 10:35:13 +03:00
|
|
|
insert(:site, members: [user], domain: "test-site.com")
|
2020-03-23 12:34:25 +03:00
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
2020-03-23 12:34:25 +03:00
|
|
|
|
|
|
|
assert_email_delivered_with(
|
|
|
|
to: [{user.name, user.email}],
|
|
|
|
subject: "Plausible is now tracking your website stats"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sends the setup completed email after the help email has been sent" do
|
|
|
|
user = insert(:user)
|
|
|
|
site = insert(:site, members: [user], inserted_at: hours_ago(49))
|
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
2020-03-23 12:34:25 +03:00
|
|
|
|
|
|
|
assert_email_delivered_with(
|
|
|
|
to: [{user.name, user.email}],
|
|
|
|
subject: "Your Plausible setup: Waiting for the first page views"
|
|
|
|
)
|
|
|
|
|
2020-05-22 12:33:17 +03:00
|
|
|
create_pageviews([%{domain: site.domain}])
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
2020-03-23 12:34:25 +03:00
|
|
|
|
|
|
|
assert_email_delivered_with(
|
|
|
|
to: [{user.name, user.email}],
|
|
|
|
subject: "Plausible is now tracking your website stats"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "trial user who has not set up a website" do
|
|
|
|
test "does not send an email before 48h have passed" do
|
|
|
|
insert(:user, inserted_at: hours_ago(47))
|
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
2020-03-23 12:34:25 +03:00
|
|
|
|
|
|
|
assert_no_emails_delivered()
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sends the create site email after 48h" do
|
|
|
|
user = insert(:user, inserted_at: hours_ago(49))
|
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
2020-03-23 12:34:25 +03:00
|
|
|
|
|
|
|
assert_email_delivered_with(
|
|
|
|
to: [{user.name, user.email}],
|
|
|
|
subject: "Your Plausible setup: Add your website details"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp hours_ago(hours) do
|
|
|
|
NaiveDateTime.utc_now()
|
|
|
|
|> NaiveDateTime.truncate(:second)
|
|
|
|
|> Timex.shift(hours: -hours)
|
|
|
|
end
|
|
|
|
end
|