Delete test/plausible/billing/feature_test.exs with huggingface_hub
Browse files
test/plausible/billing/feature_test.exs
DELETED
|
@@ -1,230 +0,0 @@
|
|
| 1 |
-
defmodule Plausible.Billing.FeatureTest do
|
| 2 |
-
use Plausible.DataCase
|
| 3 |
-
|
| 4 |
-
alias Plausible.Billing.Feature.{
|
| 5 |
-
Goals,
|
| 6 |
-
SiteSegments,
|
| 7 |
-
SiteAnnotations,
|
| 8 |
-
SharedLinks,
|
| 9 |
-
Funnels,
|
| 10 |
-
RevenueGoals,
|
| 11 |
-
StatsAPI,
|
| 12 |
-
Props,
|
| 13 |
-
ConsolidatedView
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
@v1_growth_plan_id "558018"
|
| 17 |
-
@v5_growth_plan_id "910429"
|
| 18 |
-
|
| 19 |
-
describe "business features (for everyone)" do
|
| 20 |
-
for mod <- [Funnels, RevenueGoals, ConsolidatedView] do
|
| 21 |
-
test "#{mod}.check_availability/1 returns :ok when site owner is on a enterprise plan that supports #{mod}" do
|
| 22 |
-
team =
|
| 23 |
-
new_user()
|
| 24 |
-
|> subscribe_to_enterprise_plan(paddle_plan_id: "123321", features: [unquote(mod)])
|
| 25 |
-
|> team_of()
|
| 26 |
-
|
| 27 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 28 |
-
end
|
| 29 |
-
|
| 30 |
-
test "#{mod}.check_availability/1 returns error when site owner is on a enterprise plan does not support #{mod}" do
|
| 31 |
-
team =
|
| 32 |
-
new_user()
|
| 33 |
-
|> subscribe_to_enterprise_plan(paddle_plan_id: "123321", features: [Goals])
|
| 34 |
-
|> team_of()
|
| 35 |
-
|
| 36 |
-
assert {:error, :upgrade_required} == unquote(mod).check_availability(team)
|
| 37 |
-
end
|
| 38 |
-
|
| 39 |
-
test "#{mod}.check_availability/1 returns :ok when site owner is on a business plan" do
|
| 40 |
-
team = new_user() |> subscribe_to_business_plan() |> team_of()
|
| 41 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 42 |
-
end
|
| 43 |
-
|
| 44 |
-
test "#{mod}.check_availability/1 returns error when site owner is on a growth plan" do
|
| 45 |
-
team = new_user() |> subscribe_to_growth_plan() |> team_of()
|
| 46 |
-
assert {:error, :upgrade_required} == unquote(mod).check_availability(team)
|
| 47 |
-
end
|
| 48 |
-
|
| 49 |
-
test "#{mod}.check_availability/1 returns error when site owner is on an old v1 plan" do
|
| 50 |
-
team = new_user() |> subscribe_to_plan(@v1_growth_plan_id) |> team_of()
|
| 51 |
-
assert {:error, :upgrade_required} == unquote(mod).check_availability(team)
|
| 52 |
-
end
|
| 53 |
-
|
| 54 |
-
test "#{mod}.check_availability/1 returns :ok when user is on trial" do
|
| 55 |
-
team = new_user(trial_expiry_date: Date.utc_today()) |> team_of()
|
| 56 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 57 |
-
end
|
| 58 |
-
end
|
| 59 |
-
end
|
| 60 |
-
|
| 61 |
-
describe "business features (grandfathered Growth access before v4)" do
|
| 62 |
-
for mod <- [Props, StatsAPI] do
|
| 63 |
-
test "#{mod}.check_availability/1 returns :ok when site owner is on a enterprise plan that supports #{mod}" do
|
| 64 |
-
team =
|
| 65 |
-
new_user()
|
| 66 |
-
|> subscribe_to_enterprise_plan(paddle_plan_id: "123321", features: [unquote(mod)])
|
| 67 |
-
|> team_of()
|
| 68 |
-
|
| 69 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 70 |
-
end
|
| 71 |
-
|
| 72 |
-
test "#{mod}.check_availability/1 returns error when site owner is on a enterprise plan does not support #{mod}" do
|
| 73 |
-
team =
|
| 74 |
-
new_user()
|
| 75 |
-
|> subscribe_to_enterprise_plan(paddle_plan_id: "123321", features: [Goals])
|
| 76 |
-
|> team_of()
|
| 77 |
-
|
| 78 |
-
assert {:error, :upgrade_required} == unquote(mod).check_availability(team)
|
| 79 |
-
end
|
| 80 |
-
|
| 81 |
-
test "#{mod}.check_availability/1 returns :ok when site owner is on a business plan" do
|
| 82 |
-
team = new_user() |> subscribe_to_business_plan() |> team_of()
|
| 83 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 84 |
-
end
|
| 85 |
-
|
| 86 |
-
test "#{mod}.check_availability/1 returns error when site owner is on a new growth plan" do
|
| 87 |
-
team = new_user() |> subscribe_to_growth_plan() |> team_of()
|
| 88 |
-
assert {:error, :upgrade_required} == unquote(mod).check_availability(team)
|
| 89 |
-
end
|
| 90 |
-
|
| 91 |
-
test "#{mod}.check_availability/1 returns :ok when site owner is on an old plan" do
|
| 92 |
-
team = new_user() |> subscribe_to_plan(@v1_growth_plan_id) |> team_of()
|
| 93 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 94 |
-
end
|
| 95 |
-
|
| 96 |
-
test "#{mod}.check_availability/1 returns :ok when user is on trial" do
|
| 97 |
-
team = new_user(trial_expiry_date: Date.utc_today()) |> team_of()
|
| 98 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 99 |
-
end
|
| 100 |
-
end
|
| 101 |
-
end
|
| 102 |
-
|
| 103 |
-
describe "growth features" do
|
| 104 |
-
for mod <- [SharedLinks, SiteSegments, SiteAnnotations] do
|
| 105 |
-
test "#{mod}.check_availability/1 returns :ok when site owner is on a enterprise plan that supports #{mod}" do
|
| 106 |
-
team =
|
| 107 |
-
new_user()
|
| 108 |
-
|> subscribe_to_enterprise_plan(paddle_plan_id: "123321", features: [unquote(mod)])
|
| 109 |
-
|> team_of()
|
| 110 |
-
|
| 111 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 112 |
-
end
|
| 113 |
-
|
| 114 |
-
test "#{mod}.check_availability/1 returns error when site owner is on a enterprise plan does not support #{mod}" do
|
| 115 |
-
team =
|
| 116 |
-
new_user()
|
| 117 |
-
|> subscribe_to_enterprise_plan(paddle_plan_id: "123321", features: [Goals])
|
| 118 |
-
|> team_of()
|
| 119 |
-
|
| 120 |
-
assert {:error, :upgrade_required} == unquote(mod).check_availability(team)
|
| 121 |
-
end
|
| 122 |
-
|
| 123 |
-
test "#{mod}.check_availability/1 returns :ok when site owner is on a business plan" do
|
| 124 |
-
team = new_user() |> subscribe_to_business_plan() |> team_of()
|
| 125 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 126 |
-
end
|
| 127 |
-
|
| 128 |
-
test "#{mod}.check_availability/1 returns :ok when site owner is on a growth plan" do
|
| 129 |
-
team = new_user() |> subscribe_to_plan(@v5_growth_plan_id) |> team_of()
|
| 130 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 131 |
-
end
|
| 132 |
-
|
| 133 |
-
test "#{mod}.check_availability/1 returns error when site owner is on a starter plan" do
|
| 134 |
-
team = new_user() |> subscribe_to_starter_plan() |> team_of()
|
| 135 |
-
assert {:error, :upgrade_required} == unquote(mod).check_availability(team)
|
| 136 |
-
end
|
| 137 |
-
|
| 138 |
-
test "#{mod}.check_availability/1 returns :ok when user is on trial" do
|
| 139 |
-
team = new_user(trial_expiry_date: Date.utc_today()) |> team_of()
|
| 140 |
-
assert :ok == unquote(mod).check_availability(team)
|
| 141 |
-
end
|
| 142 |
-
end
|
| 143 |
-
end
|
| 144 |
-
|
| 145 |
-
test "Goals.check_availability/2 always returns :ok" do
|
| 146 |
-
t1 = new_user() |> subscribe_to_plan(@v1_growth_plan_id) |> team_of()
|
| 147 |
-
t2 = new_user() |> subscribe_to_growth_plan() |> team_of()
|
| 148 |
-
t3 = new_user() |> subscribe_to_business_plan() |> team_of()
|
| 149 |
-
t4 = new_user() |> subscribe_to_enterprise_plan(paddle_plan_id: "123321") |> team_of()
|
| 150 |
-
|
| 151 |
-
assert :ok == Goals.check_availability(t1)
|
| 152 |
-
assert :ok == Goals.check_availability(t2)
|
| 153 |
-
assert :ok == Goals.check_availability(t3)
|
| 154 |
-
assert :ok == Goals.check_availability(t4)
|
| 155 |
-
end
|
| 156 |
-
|
| 157 |
-
for {mod, property} <- [
|
| 158 |
-
{Funnels, :funnels_enabled},
|
| 159 |
-
{Props, :props_enabled}
|
| 160 |
-
] do
|
| 161 |
-
test "#{mod}.toggle/2 toggles #{property} on and off" do
|
| 162 |
-
user = new_user()
|
| 163 |
-
site = new_site([{:owner, user}, {unquote(property), false}])
|
| 164 |
-
|
| 165 |
-
{:ok, site} = unquote(mod).toggle(site, user)
|
| 166 |
-
assert Map.get(site, unquote(property))
|
| 167 |
-
assert unquote(mod).enabled?(site)
|
| 168 |
-
refute unquote(mod).opted_out?(site)
|
| 169 |
-
|
| 170 |
-
{:ok, site} = unquote(mod).toggle(site, user)
|
| 171 |
-
refute Map.get(site, unquote(property))
|
| 172 |
-
refute unquote(mod).enabled?(site)
|
| 173 |
-
assert unquote(mod).opted_out?(site)
|
| 174 |
-
end
|
| 175 |
-
|
| 176 |
-
test "#{mod}.toggle/2 accepts an override option" do
|
| 177 |
-
user = new_user()
|
| 178 |
-
site = new_site([{:owner, user}, {unquote(property), false}])
|
| 179 |
-
|
| 180 |
-
{:ok, site} = unquote(mod).toggle(site, user, override: false)
|
| 181 |
-
refute Map.get(site, unquote(property))
|
| 182 |
-
refute unquote(mod).enabled?(site)
|
| 183 |
-
end
|
| 184 |
-
|
| 185 |
-
test "#{mod}.toggle/2 errors when enabling a feature the site owner does not have access to the feature" do
|
| 186 |
-
user = new_user() |> subscribe_to_growth_plan()
|
| 187 |
-
site = new_site([{:owner, user}, {unquote(property), false}])
|
| 188 |
-
|
| 189 |
-
{:error, :upgrade_required} = unquote(mod).toggle(site, user)
|
| 190 |
-
refute unquote(mod).enabled?(site)
|
| 191 |
-
end
|
| 192 |
-
|
| 193 |
-
test "#{mod}.toggle/2 does not error when disabling a feature the site owner does not have access to" do
|
| 194 |
-
user = new_user() |> subscribe_to_growth_plan()
|
| 195 |
-
site = new_site([{:owner, user}, {unquote(property), true}])
|
| 196 |
-
|
| 197 |
-
{:ok, site} = unquote(mod).toggle(site, user)
|
| 198 |
-
assert unquote(mod).opted_out?(site)
|
| 199 |
-
end
|
| 200 |
-
end
|
| 201 |
-
|
| 202 |
-
test "Plausible.Billing.Feature.Goals.toggle/2 toggles conversions_enabled on and off" do
|
| 203 |
-
user = new_user()
|
| 204 |
-
site = new_site(owner: user, conversions_enabled: false)
|
| 205 |
-
|
| 206 |
-
{:ok, site} = Plausible.Billing.Feature.Goals.toggle(site, user)
|
| 207 |
-
assert Map.get(site, :conversions_enabled)
|
| 208 |
-
assert Plausible.Billing.Feature.Goals.enabled?(site)
|
| 209 |
-
refute Plausible.Billing.Feature.Goals.opted_out?(site)
|
| 210 |
-
|
| 211 |
-
{:ok, site} = Plausible.Billing.Feature.Goals.toggle(site, user)
|
| 212 |
-
refute Map.get(site, :conversions_enabled)
|
| 213 |
-
refute Plausible.Billing.Feature.Goals.enabled?(site)
|
| 214 |
-
assert Plausible.Billing.Feature.Goals.opted_out?(site)
|
| 215 |
-
end
|
| 216 |
-
|
| 217 |
-
for mod <- [Plausible.Billing.Feature.Funnels, Plausible.Billing.Feature.Props] do
|
| 218 |
-
test "#{mod}.enabled?/1 returns false when user does not have access to the feature even when enabled" do
|
| 219 |
-
user = new_user() |> subscribe_to_growth_plan()
|
| 220 |
-
site = new_site([{:owner, user}, {unquote(mod).toggle_field(), true}])
|
| 221 |
-
refute unquote(mod).enabled?(site)
|
| 222 |
-
end
|
| 223 |
-
|
| 224 |
-
test "#{mod}.opted_out?/1 returns false when feature toggle is enabled even when user does not have access to the feature" do
|
| 225 |
-
user = new_user() |> subscribe_to_growth_plan()
|
| 226 |
-
site = new_site([{:owner, user}, {unquote(mod).toggle_field(), true}])
|
| 227 |
-
refute unquote(mod).opted_out?(site)
|
| 228 |
-
end
|
| 229 |
-
end
|
| 230 |
-
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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