|
|
|
|
@ -118,7 +118,7 @@ defmodule Plausible.Workers.CheckUsageTest do
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "for yearly subscriptions, does not check exactly one month after last_bill_date", %{
|
|
|
|
|
test "does not check exactly one month after last_bill_date", %{
|
|
|
|
|
user: user
|
|
|
|
|
} do
|
|
|
|
|
billing_stub =
|
|
|
|
|
@ -131,38 +131,14 @@ defmodule Plausible.Workers.CheckUsageTest do
|
|
|
|
|
insert(:subscription,
|
|
|
|
|
user: user,
|
|
|
|
|
paddle_plan_id: @paddle_id_10k,
|
|
|
|
|
last_bill_date: Timex.shift(Timex.today(), months: -1)
|
|
|
|
|
last_bill_date: ~D[2021-03-28]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
CheckUsage.perform(nil, nil, billing_stub)
|
|
|
|
|
CheckUsage.perform(nil, nil, billing_stub, ~D[2021-03-28])
|
|
|
|
|
|
|
|
|
|
assert_no_emails_delivered()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "for yearly subscriptions, checks usage one month + one day after the last_bill_date", %{
|
|
|
|
|
user: user
|
|
|
|
|
} do
|
|
|
|
|
billing_stub =
|
|
|
|
|
Plausible.Billing
|
|
|
|
|
|> stub(:last_two_billing_months_usage, fn _user -> {11_000, 11_000} end)
|
|
|
|
|
|> stub(:last_two_billing_cycles, fn _user ->
|
|
|
|
|
{Date.range(Timex.today(), Timex.today()), Date.range(Timex.today(), Timex.today())}
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
insert(:subscription,
|
|
|
|
|
user: user,
|
|
|
|
|
paddle_plan_id: @paddle_id_10k,
|
|
|
|
|
last_bill_date: Timex.shift(Timex.today(), months: -1, days: -1)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
CheckUsage.perform(nil, nil, billing_stub)
|
|
|
|
|
|
|
|
|
|
assert_email_delivered_with(
|
|
|
|
|
to: [user],
|
|
|
|
|
subject: "You have outgrown your Plausible subscription tier "
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "for yearly subscriptions, checks usage multiple months + one day after the last_bill_date",
|
|
|
|
|
%{
|
|
|
|
|
user: user
|
|
|
|
|
|