mirror of
https://github.com/plausible/analytics.git
synced 2024-12-25 02:24:55 +03:00
d2f2c69387
* Remove ClickhouseSetup module This has been an implicit point of contact to many tests. From now on the goal is for each test to maintain its own, isolated setup so that no accidental clashes and implicit assumptions are relied upon. * Implement v2 schema check An environment variable V2_MIGRATION_DONE acts like a feature flag, switching plausible from using old events/sessions schemas to v2 schemas introduced by NumericIDs migration. * Run both test suites sequentially While the code for v1 and v2 schemas must be kept still, we will from now on run tests against both code paths. Secondary test run will set V2_MIGRATION_DONE=1 variable, thus making all `Plausible.v2?()` checks return `true'. * Remove unused function This is a remnant from the short period when we would check for existing events before allowing creating a new site. * Update test setups/factories with v2 migration check * Make GateKeeper return site id along with :allow * Make Billing module check for v2 schema * Make ingestion aware of v2 schema * Disable site transfers for when v2 is live In a separate changeset we will implement simplified site transfer for when v2 migration is complete. The new transfer will only rename the site domain in postgres and keep track of the original site prior to the transfer so we keep an ingestion grace period until the customers redeploy their scripting. * Make Stats base queries aware of v2 schema switch * Update breakdown with v2 conditionals * Update pageview local start with v2 check * Update current visitoris with v2 check * Update stats controller with v2 checks * Update external controller with v2 checks * Update remaining tests with proper fixtures * Rewrite redundant assignment * Remove unused alias * Mute credo, this is not the right time * Add test_helper prompt * Fetch priv dir so it works with a release * Fetch distinct partitions only * Don't limit inspect output for partitions * Ensure SQL is printed to IO * Remove redundant domain fixture
211 lines
6.5 KiB
Elixir
211 lines
6.5 KiB
Elixir
defmodule Plausible.Workers.SendTrialNotificationsTest do
|
|
use Plausible.DataCase
|
|
use Bamboo.Test
|
|
use Oban.Testing, repo: Plausible.Repo
|
|
|
|
alias Plausible.Workers.SendTrialNotifications
|
|
|
|
test "does not send a notification if user didn't create a site" do
|
|
insert(:user, trial_expiry_date: Timex.now() |> Timex.shift(days: 7))
|
|
insert(:user, trial_expiry_date: Timex.now() |> Timex.shift(days: 1))
|
|
insert(:user, trial_expiry_date: Timex.now() |> Timex.shift(days: 0))
|
|
insert(:user, trial_expiry_date: Timex.now() |> Timex.shift(days: -1))
|
|
|
|
perform_job(SendTrialNotifications, %{})
|
|
|
|
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])
|
|
|
|
perform_job(SendTrialNotifications, %{})
|
|
|
|
assert_no_emails_delivered()
|
|
end
|
|
|
|
test "does not send a notification if user is a collaborator on sites but not an owner" do
|
|
user = insert(:user, trial_expiry_date: Timex.now())
|
|
|
|
site =
|
|
insert(:site,
|
|
memberships: [
|
|
build(:site_membership, user: user, role: :admin)
|
|
]
|
|
)
|
|
|
|
populate_stats(site, [build(:pageview)])
|
|
|
|
perform_job(SendTrialNotifications, %{})
|
|
|
|
assert_no_emails_delivered()
|
|
end
|
|
|
|
describe "with site and pageviews" do
|
|
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))
|
|
site = insert(:site, members: [user])
|
|
populate_stats(site, [build(:pageview)])
|
|
|
|
perform_job(SendTrialNotifications, %{})
|
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_one_week_reminder(user))
|
|
end
|
|
|
|
test "sends an upgrade email the day before the trial ends" do
|
|
user = insert(:user, trial_expiry_date: Timex.now() |> Timex.shift(days: 1))
|
|
site = insert(:site, members: [user])
|
|
|
|
populate_stats(site, [
|
|
build(:pageview),
|
|
build(:pageview),
|
|
build(:pageview)
|
|
])
|
|
|
|
perform_job(SendTrialNotifications, %{})
|
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_upgrade_email(user, "tomorrow", {3, 0}))
|
|
end
|
|
|
|
test "sends an upgrade email the day the trial ends" do
|
|
user = insert(:user, trial_expiry_date: Timex.today())
|
|
site = insert(:site, members: [user])
|
|
|
|
populate_stats(site, [
|
|
build(:pageview),
|
|
build(:pageview),
|
|
build(:pageview)
|
|
])
|
|
|
|
perform_job(SendTrialNotifications, %{})
|
|
|
|
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."
|
|
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])
|
|
|
|
populate_stats(site, [
|
|
build(:pageview),
|
|
build(:pageview),
|
|
build(:pageview)
|
|
])
|
|
|
|
perform_job(SendTrialNotifications, %{})
|
|
|
|
assert_delivered_email(PlausibleWeb.Email.trial_over_email(user))
|
|
end
|
|
|
|
test "does not send a notification if user has a subscription" do
|
|
user = insert(:user, trial_expiry_date: Timex.now() |> Timex.shift(days: 7))
|
|
site = insert(:site, members: [user])
|
|
|
|
populate_stats(site, [
|
|
build(:pageview),
|
|
build(:pageview),
|
|
build(:pageview)
|
|
])
|
|
|
|
insert(:subscription, user: user)
|
|
|
|
perform_job(SendTrialNotifications, %{})
|
|
|
|
assert_no_emails_delivered()
|
|
end
|
|
end
|
|
|
|
describe "Suggested plans" do
|
|
test "suggests 10k/mo plan" do
|
|
user = insert(:user)
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {9_000, 0})
|
|
assert email.html_body =~ "we recommend you select the 10k/mo plan."
|
|
end
|
|
|
|
test "suggests 100k/mo plan" do
|
|
user = insert(:user)
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {90_000, 0})
|
|
assert email.html_body =~ "we recommend you select the 100k/mo plan."
|
|
end
|
|
|
|
test "suggests 200k/mo plan" do
|
|
user = insert(:user)
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {180_000, 0})
|
|
assert email.html_body =~ "we recommend you select the 200k/mo plan."
|
|
end
|
|
|
|
test "suggests 500k/mo plan" do
|
|
user = insert(:user)
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {450_000, 0})
|
|
assert email.html_body =~ "we recommend you select the 500k/mo plan."
|
|
end
|
|
|
|
test "suggests 1m/mo plan" do
|
|
user = insert(:user)
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {900_000, 0})
|
|
assert email.html_body =~ "we recommend you select the 1M/mo plan."
|
|
end
|
|
|
|
test "suggests 2m/mo plan" do
|
|
user = insert(:user)
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {1_800_000, 0})
|
|
assert email.html_body =~ "we recommend you select the 2M/mo plan."
|
|
end
|
|
|
|
test "suggests 5m/mo plan" do
|
|
user = insert(:user)
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {4_500_000, 0})
|
|
assert email.html_body =~ "we recommend you select the 5M/mo plan."
|
|
end
|
|
|
|
test "suggests 10m/mo plan" do
|
|
user = insert(:user)
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {9_000_000, 0})
|
|
assert email.html_body =~ "we recommend you select the 10M/mo plan."
|
|
end
|
|
|
|
test "does not suggest a plan above that" do
|
|
user = insert(:user)
|
|
|
|
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {20_000_000, 0})
|
|
assert email.html_body =~ "please reply back to this email to get a quote for your volume"
|
|
end
|
|
end
|
|
end
|