mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 17:44:43 +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
104 lines
2.9 KiB
Elixir
104 lines
2.9 KiB
Elixir
defmodule Plausible.Workers.SendSiteSetupEmailsTest do
|
|
use Plausible.DataCase, async: true
|
|
use Bamboo.Test
|
|
use Oban.Testing, repo: Plausible.Repo
|
|
|
|
alias Plausible.Workers.SendSiteSetupEmails
|
|
|
|
describe "when user has not managed to set up the site" do
|
|
test "does not send an email 47 hours after site creation" do
|
|
user = insert(:user)
|
|
insert(:site, members: [user], inserted_at: hours_ago(47))
|
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
|
|
|
assert_no_emails_delivered()
|
|
end
|
|
|
|
test "sends a setup help email 48 hours after site has been created" do
|
|
user = insert(:user)
|
|
insert(:site, members: [user], inserted_at: hours_ago(49))
|
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
|
|
|
assert_email_delivered_with(
|
|
to: [{user.name, user.email}],
|
|
subject: "Your Plausible setup: Waiting for the first page views"
|
|
)
|
|
end
|
|
|
|
test "does not send an email more than 72 hours after signup" do
|
|
user = insert(:user)
|
|
insert(:site, members: [user], inserted_at: hours_ago(73))
|
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
|
|
|
assert_no_emails_delivered()
|
|
end
|
|
end
|
|
|
|
describe "when user has managed to set up their site" do
|
|
test "sends the setup completed email as soon as possible" do
|
|
user = insert(:user)
|
|
|
|
site = insert(:site, members: [user])
|
|
|
|
populate_stats(site, [build(:pageview)])
|
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
|
|
|
assert_email_delivered_with(
|
|
to: [{user.name, user.email}],
|
|
subject: "Plausible is now tracking your website stats"
|
|
)
|
|
end
|
|
|
|
test "sends the setup completed email after the help email has been sent" do
|
|
user = insert(:user)
|
|
site = insert(:site, members: [user], inserted_at: hours_ago(49))
|
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
|
|
|
assert_email_delivered_with(
|
|
to: [{user.name, user.email}],
|
|
subject: "Your Plausible setup: Waiting for the first page views"
|
|
)
|
|
|
|
create_pageviews([%{site: site}])
|
|
perform_job(SendSiteSetupEmails, %{})
|
|
|
|
assert_email_delivered_with(
|
|
to: [{user.name, user.email}],
|
|
subject: "Plausible is now tracking your website stats"
|
|
)
|
|
end
|
|
end
|
|
|
|
describe "trial user who has not set up a website" do
|
|
test "does not send an email before 48h have passed" do
|
|
insert(:user, inserted_at: hours_ago(47))
|
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
|
|
|
assert_no_emails_delivered()
|
|
end
|
|
|
|
test "sends the create site email after 48h" do
|
|
user = insert(:user, inserted_at: hours_ago(49))
|
|
|
|
perform_job(SendSiteSetupEmails, %{})
|
|
|
|
assert_email_delivered_with(
|
|
to: [{user.name, user.email}],
|
|
subject: "Your Plausible setup: Add your website details"
|
|
)
|
|
end
|
|
end
|
|
|
|
defp hours_ago(hours) do
|
|
NaiveDateTime.utc_now()
|
|
|> NaiveDateTime.truncate(:second)
|
|
|> Timex.shift(hours: -hours)
|
|
end
|
|
end
|