2019-09-02 14:29:19 +03:00
|
|
|
defmodule Mix.Tasks.SendTrialNotificationsTest do
|
|
|
|
use Plausible.DataCase
|
|
|
|
use Bamboo.Test
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
Mix.Tasks.SendTrialNotifications.execute()
|
|
|
|
|
|
|
|
assert_no_emails_delivered()
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with site and pageviews" do
|
|
|
|
test "sends a reminder 14 days before trial ends (16 days after user signed up)" do
|
2020-03-18 17:27:46 +03:00
|
|
|
user = insert(:user, trial_expiry_date: Timex.now |> Timex.shift(days: 14))
|
2019-09-02 14:29:19 +03:00
|
|
|
site = insert(:site, members: [user])
|
2020-02-04 16:44:13 +03:00
|
|
|
insert(:pageview, domain: site.domain)
|
2019-09-02 14:29:19 +03:00
|
|
|
|
|
|
|
Mix.Tasks.SendTrialNotifications.execute()
|
|
|
|
|
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_two_week_reminder(user))
|
|
|
|
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))
|
2019-09-02 14:29:19 +03:00
|
|
|
site = insert(:site, members: [user])
|
2020-02-04 16:44:13 +03:00
|
|
|
insert(:pageview, domain: site.domain)
|
2019-09-02 14:29:19 +03:00
|
|
|
|
|
|
|
Mix.Tasks.SendTrialNotifications.execute()
|
|
|
|
|
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_upgrade_email(user, "tomorrow", 1))
|
|
|
|
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())
|
|
|
|
site = insert(:site, members: [user])
|
|
|
|
insert(:pageview, domain: site.domain)
|
|
|
|
|
|
|
|
Mix.Tasks.SendTrialNotifications.execute()
|
|
|
|
|
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_upgrade_email(user, "today", 1))
|
|
|
|
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))
|
|
|
|
site = insert(:site, members: [user])
|
|
|
|
insert(:pageview, domain: site.domain)
|
|
|
|
|
|
|
|
Mix.Tasks.SendTrialNotifications.execute()
|
|
|
|
|
|
|
|
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-03-18 17:27:46 +03:00
|
|
|
user1 = insert(:user, trial_expiry_date: Timex.now |> Timex.shift(days: 14))
|
2019-09-02 14:29:19 +03:00
|
|
|
site1 = insert(:site, members: [user1])
|
2020-02-04 16:44:13 +03:00
|
|
|
insert(:pageview, domain: site1.domain)
|
2020-03-18 17:27:46 +03:00
|
|
|
user2 = insert(:user, trial_expiry_date: Timex.now |> Timex.shift(days: 1))
|
2019-09-02 14:29:19 +03:00
|
|
|
site2 = insert(:site, members: [user2])
|
2020-02-04 16:44:13 +03:00
|
|
|
insert(:pageview, domain: site2.domain)
|
2019-09-02 14:29:19 +03:00
|
|
|
|
|
|
|
insert(:subscription, user: user1)
|
|
|
|
insert(:subscription, user: user2)
|
|
|
|
|
|
|
|
Mix.Tasks.SendTrialNotifications.execute()
|
|
|
|
|
|
|
|
assert_no_emails_delivered()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|