Skip to content

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

Update plan calculator to account for SSO (#5577)

Adrian Gruntkowski08b4b0be07ab
diff --git a/extra/lib/plausible/customer_support/enterprise_plan.ex b/extra/lib/plausible/customer_support/enterprise_plan.ex
index 4e12a1c671..d5c0140e48 100644
--- a/extra/lib/plausible/customer_support/enterprise_plan.ex
+++ b/extra/lib/plausible/customer_support/enterprise_plan.ex
@@ -24,8 +24,7 @@ defmodule Plausible.CustomerSupport.EnterprisePlan do
sites_rate =
sites_rate(sites_limit)
- team_members_rate =
- team_members_rate(team_members_limit)
+ team_members_rate = team_members_rate(team_members_limit)
api_calls_rate =
api_calls_rate(api_calls_limit)
@@ -71,13 +70,20 @@ defmodule Plausible.CustomerSupport.EnterprisePlan do
def sites_rate(n) when n <= 50, do: 0
def sites_rate(n), do: n * 0.1
- def team_members_rate(n) when n > 10, do: (n - 10) * 5
+ def team_members_rate(n) when n > 10, do: (n - 10) * 15
def team_members_rate(_), do: 0
def api_calls_rate(n) when n <= 600, do: 0
def api_calls_rate(n) when n > 600, do: round(n / 1_000) * 100
- def features_rate(f) do
- if "sites_api" in f, do: 99, else: 0
+ @feature_rates %{
+ "sites_api" => 99,
+ "sso" => 299
+ }
+
+ def features_rate(features) do
+ features
+ |> Enum.map(&Map.get(@feature_rates, &1, 0))
+ |> Enum.sum()
end
end
diff --git a/test/plausible/customer_support/enterprise_plan_test.exs b/test/plausible/customer_support/enterprise_plan_test.exs
index ff3e77b778..5c9bdcb7a1 100644
--- a/test/plausible/customer_support/enterprise_plan_test.exs
+++ b/test/plausible/customer_support/enterprise_plan_test.exs
@@ -18,7 +18,21 @@ defmodule Plausible.CustomerSupport.EnterprisePlanTest do
["sites_api"]
)
- assert result == Decimal.new("1038.00")
+ assert result == Decimal.new("1238.00")
+ end
+
+ test "calculates cost for business plan with monthly billing, SSO enabled and extra members" do
+ result =
+ EnterprisePlan.estimate(
+ "monthly",
+ 20_000_000,
+ 1000,
+ 30,
+ 1_000,
+ ["sites_api", "sso"]
+ )
+
+ assert result == Decimal.new("1537.00")
end
test "bugfix - from float" do
@@ -46,7 +60,7 @@ defmodule Plausible.CustomerSupport.EnterprisePlanTest do
[]
)
- assert result == Decimal.new("94.00")
+ assert result == Decimal.new("144.00")
end
test "calculates cost for business plan with yearly billing" do
@@ -60,7 +74,7 @@ defmodule Plausible.CustomerSupport.EnterprisePlanTest do
["sites_api"]
)
- assert result == Decimal.new("10380.00")
+ assert result == Decimal.new("12380.00")
end
end
@@ -99,8 +113,8 @@ defmodule Plausible.CustomerSupport.EnterprisePlanTest do
test "calculates rate based on number of team members" do
assert EnterprisePlan.team_members_rate(5) == 0
assert EnterprisePlan.team_members_rate(10) == 0
- assert EnterprisePlan.team_members_rate(15) == 25
- assert EnterprisePlan.team_members_rate(20) == 50
+ assert EnterprisePlan.team_members_rate(15) == 75
+ assert EnterprisePlan.team_members_rate(20) == 150
end
end
@@ -120,6 +134,9 @@ defmodule Plausible.CustomerSupport.EnterprisePlanTest do
describe "features_rate/1" do
test "returns correct rate based on features" do
assert EnterprisePlan.features_rate(["sites_api"]) == 99
+ assert EnterprisePlan.features_rate(["sso"]) == 299
+ assert EnterprisePlan.features_rate(["sso", "sites_api"]) == 398
+ assert EnterprisePlan.features_rate(["funnels"]) == 0
assert EnterprisePlan.features_rate([]) == 0
end
end
diff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exs
index e2372f6f3f..71a83af29b 100644
--- a/test/plausible_web/live/customer_support/teams_test.exs
+++ b/test/plausible_web/live/customer_support/teams_test.exs
@@ -149,7 +149,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
})
html = render(lv)
- assert text_of_attr(html, ~s|#cost-estimate|, "value") == "10380.00"
+ assert text_of_attr(html, ~s|#cost-estimate|, "value") == "12380.00"
end
test "saves custom plan", %{conn: conn, user: user} do