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
|
|
|
|
|
2020-06-02 13:37:38 +03:00
|
|
|
defp perform() do
|
|
|
|
Plausible.Workers.SendTrialNotifications.new(%{}) |> Oban.insert!()
|
|
|
|
Oban.drain_queue(:trial_notification_emails)
|
|
|
|
end
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
test "does not send a notification if user didn't set up their site" do
|
|
|
|
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))
|
|
|
|
|
2020-06-02 13:37:38 +03:00
|
|
|
perform()
|
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
|
|
|
|
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
|
|
|
|
2020-06-02 13:37:38 +03:00
|
|
|
perform()
|
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-03-18 17:27:46 +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
|
|
|
|
2020-06-02 13:37:38 +03:00
|
|
|
perform()
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2020-05-22 12:33:17 +03:00
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_upgrade_email(user, "tomorrow", 3))
|
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
|
|
|
|
2020-06-02 13:37:38 +03:00
|
|
|
perform()
|
2020-03-18 17:27:46 +03:00
|
|
|
|
2020-05-22 12:33:17 +03:00
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_upgrade_email(user, "today", 3))
|
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
|
|
|
|
2020-06-02 13:37:38 +03:00
|
|
|
perform()
|
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-05-22 12:33:17 +03:00
|
|
|
user = insert(:user, trial_expiry_date: Timex.now |> Timex.shift(days: 7))
|
|
|
|
insert(:site, domain: "test-site.com", members: [user])
|
|
|
|
insert(:subscription, user: user)
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2020-06-02 13:37:38 +03:00
|
|
|
perform()
|
2019-09-02 14:29:19 +03:00
|
|
|
|
|
|
|
assert_no_emails_delivered()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|