2020-06-02 13:37:38 +03:00
|
|
|
defmodule Plausible.Workers.SendTrialNotificationsTest do
|
2019-09-02 14:29:19 +03:00
|
|
|
use Plausible.DataCase
|
|
|
|
use Bamboo.Test
|
2021-04-26 11:32:18 +03:00
|
|
|
use Oban.Testing, repo: Plausible.Repo
|
|
|
|
alias Plausible.Workers.SendTrialNotifications
|
2020-06-02 13:37:38 +03:00
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
test "does not send a notification if user didn't set up their site" do
|
2020-06-08 10:35:13 +03:00
|
|
|
insert(:user, inserted_at: Timex.now() |> Timex.shift(days: -14))
|
|
|
|
insert(:user, inserted_at: Timex.now() |> Timex.shift(days: -29))
|
|
|
|
insert(:user, inserted_at: Timex.now() |> Timex.shift(days: -30))
|
|
|
|
insert(:user, inserted_at: Timex.now() |> Timex.shift(days: -31))
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendTrialNotifications, %{})
|
2019-09-02 14:29:19 +03:00
|
|
|
|
|
|
|
assert_no_emails_delivered()
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with site and pageviews" do
|
2020-03-23 12:34:25 +03:00
|
|
|
test "sends a reminder 7 days before trial ends (16 days after user signed up)" do
|
2020-06-08 10:35:13 +03:00
|
|
|
user = insert(:user, trial_expiry_date: Timex.now() |> Timex.shift(days: 7))
|
2020-05-22 12:33:17 +03:00
|
|
|
insert(:site, domain: "test-site.com", members: [user])
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendTrialNotifications, %{})
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2020-03-23 12:34:25 +03:00
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_one_week_reminder(user))
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "sends an upgrade email the day before the trial ends" do
|
2020-06-08 10:35:13 +03:00
|
|
|
user = insert(:user, trial_expiry_date: Timex.now() |> Timex.shift(days: 1))
|
2020-05-22 12:33:17 +03:00
|
|
|
insert(:site, domain: "test-site.com", members: [user])
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendTrialNotifications, %{})
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2021-01-15 17:28:57 +03:00
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_upgrade_email(user, "tomorrow", {3, 0}))
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
2020-03-18 17:27:46 +03:00
|
|
|
test "sends an upgrade email the day the trial ends" do
|
|
|
|
user = insert(:user, trial_expiry_date: Timex.today())
|
2020-05-22 12:33:17 +03:00
|
|
|
insert(:site, domain: "test-site.com", members: [user])
|
2020-03-18 17:27:46 +03:00
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendTrialNotifications, %{})
|
2020-03-18 17:27:46 +03:00
|
|
|
|
2021-01-15 17:28:57 +03:00
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_upgrade_email(user, "today", {3, 0}))
|
|
|
|
end
|
|
|
|
|
|
|
|
test "does not include custom event note if user has not used custom events" do
|
|
|
|
user = insert(:user, trial_expiry_date: Timex.today())
|
|
|
|
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {9_000, 0})
|
|
|
|
|
|
|
|
assert email.html_body =~
|
|
|
|
"In the last month, your account has used 9,000 billable pageviews."
|
|
|
|
end
|
|
|
|
|
|
|
|
test "includes custom event note if user has used custom events" do
|
|
|
|
user = insert(:user, trial_expiry_date: Timex.today())
|
|
|
|
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {9_000, 100})
|
|
|
|
|
|
|
|
assert email.html_body =~
|
|
|
|
"In the last month, your account has used 9,100 billable pageviews and custom events in total."
|
2020-03-18 17:27:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "sends a trial over email the day after the trial ends" do
|
|
|
|
user = insert(:user, trial_expiry_date: Timex.today() |> Timex.shift(days: -1))
|
2020-05-22 12:33:17 +03:00
|
|
|
insert(:site, domain: "test-site.com", members: [user])
|
2020-03-18 17:27:46 +03:00
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendTrialNotifications, %{})
|
2020-03-18 17:27:46 +03:00
|
|
|
|
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_over_email(user))
|
|
|
|
end
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
test "does not send a notification if user has a subscription" do
|
2020-06-08 10:35:13 +03:00
|
|
|
user = insert(:user, trial_expiry_date: Timex.now() |> Timex.shift(days: 7))
|
2020-05-22 12:33:17 +03:00
|
|
|
insert(:site, domain: "test-site.com", members: [user])
|
|
|
|
insert(:subscription, user: user)
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2021-04-26 11:32:18 +03:00
|
|
|
perform_job(SendTrialNotifications, %{})
|
2019-09-02 14:29:19 +03:00
|
|
|
|
|
|
|
assert_no_emails_delivered()
|
|
|
|
end
|
|
|
|
end
|
2020-06-25 12:31:54 +03:00
|
|
|
|
|
|
|
describe "Suggested plans" do
|
|
|
|
test "suggests 10k/mo plan" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2021-01-15 17:28:57 +03:00
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {9_000, 0})
|
2021-05-13 12:42:01 +03:00
|
|
|
assert email.html_body =~ "we recommend you select the 10k/mo plan."
|
2020-06-25 12:31:54 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "suggests 100k/mo plan" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2021-01-15 17:28:57 +03:00
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {90_000, 0})
|
2021-05-13 12:42:01 +03:00
|
|
|
assert email.html_body =~ "we recommend you select the 100k/mo plan."
|
2020-06-25 12:31:54 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "suggests 200k/mo plan" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2021-01-15 17:28:57 +03:00
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {180_000, 0})
|
2021-05-13 12:42:01 +03:00
|
|
|
assert email.html_body =~ "we recommend you select the 200k/mo plan."
|
2020-06-25 12:31:54 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "suggests 500k/mo plan" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2021-01-15 17:28:57 +03:00
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {450_000, 0})
|
2021-05-13 12:42:01 +03:00
|
|
|
assert email.html_body =~ "we recommend you select the 500k/mo plan."
|
2020-06-25 12:31:54 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "suggests 1m/mo plan" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2021-01-15 17:28:57 +03:00
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {900_000, 0})
|
2021-05-13 12:42:01 +03:00
|
|
|
assert email.html_body =~ "we recommend you select the 1M/mo plan."
|
2020-06-25 12:31:54 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "suggests 2m/mo plan" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2021-01-15 17:28:57 +03:00
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {1_800_000, 0})
|
2021-05-13 12:42:01 +03:00
|
|
|
assert email.html_body =~ "we recommend you select the 2M/mo plan."
|
2020-06-25 12:31:54 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "suggests 5m/mo plan" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2021-01-15 17:28:57 +03:00
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {4_500_000, 0})
|
2021-05-13 12:42:01 +03:00
|
|
|
assert email.html_body =~ "we recommend you select the 5M/mo plan."
|
2020-06-25 12:31:54 +03:00
|
|
|
end
|
|
|
|
|
2021-02-12 11:17:53 +03:00
|
|
|
test "suggests 10m/mo plan" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {9_000_000, 0})
|
2021-05-13 12:42:01 +03:00
|
|
|
assert email.html_body =~ "we recommend you select the 10M/mo plan."
|
2021-02-12 11:17:53 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "suggests 20m/mo plan" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {19_000_000, 0})
|
2021-05-13 12:42:01 +03:00
|
|
|
assert email.html_body =~ "we recommend you select the 20M/mo plan."
|
2021-02-12 11:17:53 +03:00
|
|
|
end
|
|
|
|
|
2020-06-25 12:31:54 +03:00
|
|
|
test "does not suggest a plan above that" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2021-02-12 11:17:53 +03:00
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {50_000_000, 0})
|
2020-06-25 12:31:54 +03:00
|
|
|
assert email.html_body =~ "please reply back to this email to get a quote for your volume"
|
|
|
|
end
|
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|