Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Fix trial notifications

Uku Tahtd2dc06ec969a
diff --git a/lib/workers/send_trial_notifications.ex b/lib/workers/send_trial_notifications.ex
index 36361eba87..e5a84a2236 100644
--- a/lib/workers/send_trial_notifications.ex
+++ b/lib/workers/send_trial_notifications.ex
@@ -14,6 +14,7 @@ defmodule Plausible.Workers.SendTrialNotifications do
from u in Plausible.Auth.User,
left_join: s in Plausible.Billing.Subscription,
on: s.user_id == u.id,
+ where: not is_nil(u.trial_expiry_date),
where: is_nil(s.id),
order_by: u.inserted_at
)
diff --git a/test/workers/send_trial_notifications_test.exs b/test/workers/send_trial_notifications_test.exs
index 58c7cec468..b647ca2c9f 100644
--- a/test/workers/send_trial_notifications_test.exs
+++ b/test/workers/send_trial_notifications_test.exs
@@ -16,6 +16,15 @@ defmodule Plausible.Workers.SendTrialNotificationsTest do
assert_no_emails_delivered()
end
+ test "does not send a notification if user does not have a trial" do
+ user = insert(:user, trial_expiry_date: nil)
+ insert(:site, members: [user])
+
+ perform_job(SendTrialNotifications, %{})
+
+ assert_no_emails_delivered()
+ end
+
test "does not send a notification if user created a site but there are no pageviews" do
user = insert(:user, trial_expiry_date: Timex.now() |> Timex.shift(days: 7))
insert(:site, members: [user])