2023-10-11 15:40:01 +03:00
|
|
|
defmodule PlausibleWeb.Components.BillingTest do
|
|
|
|
use Plausible.DataCase
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
alias PlausibleWeb.Components.Billing
|
|
|
|
|
2023-10-18 11:29:13 +03:00
|
|
|
test "premium_feature_notice/1 renders a message when user is on trial" do
|
2023-10-11 15:40:01 +03:00
|
|
|
me = insert(:user)
|
|
|
|
|
2023-10-18 11:29:13 +03:00
|
|
|
assert render_component(&Billing.premium_feature_notice/1,
|
2023-10-11 23:24:16 +03:00
|
|
|
billable_user: me,
|
2023-10-11 15:40:01 +03:00
|
|
|
current_user: me,
|
|
|
|
feature_mod: Plausible.Billing.Feature.Props
|
|
|
|
) =~
|
|
|
|
"Custom Properties is part of the Plausible Business plan. You can access it during your trial"
|
|
|
|
end
|
|
|
|
|
2023-10-18 11:29:13 +03:00
|
|
|
test "premium_feature_notice/1 renders an upgrade link when user is the site owner and does not have access to the feature" do
|
2023-10-18 11:48:47 +03:00
|
|
|
me = insert(:user, subscription: build(:growth_subscription))
|
2023-10-11 15:40:01 +03:00
|
|
|
|
|
|
|
rendered =
|
2023-10-18 11:29:13 +03:00
|
|
|
render_component(&Billing.premium_feature_notice/1,
|
2023-10-11 23:24:16 +03:00
|
|
|
billable_user: me,
|
2023-10-11 15:40:01 +03:00
|
|
|
current_user: me,
|
|
|
|
feature_mod: Plausible.Billing.Feature.Props
|
|
|
|
)
|
|
|
|
|
2023-11-08 17:59:03 +03:00
|
|
|
assert rendered =~ "This account does not have access to Custom Properties"
|
2023-10-11 15:40:01 +03:00
|
|
|
assert rendered =~ "upgrade your subscription"
|
2023-11-08 19:57:20 +03:00
|
|
|
assert rendered =~ "/billing/choose-plan"
|
2023-10-11 15:40:01 +03:00
|
|
|
end
|
|
|
|
|
2023-10-18 11:29:13 +03:00
|
|
|
test "premium_feature_notice/1 does not render an upgrade link when user is not the site owner" do
|
2023-10-11 15:40:01 +03:00
|
|
|
me = insert(:user)
|
2023-10-18 11:48:47 +03:00
|
|
|
owner = insert(:user, subscription: build(:growth_subscription))
|
2023-10-11 15:40:01 +03:00
|
|
|
|
|
|
|
rendered =
|
2023-10-18 11:29:13 +03:00
|
|
|
render_component(&Billing.premium_feature_notice/1,
|
2023-10-11 23:24:16 +03:00
|
|
|
billable_user: owner,
|
2023-10-11 15:40:01 +03:00
|
|
|
current_user: me,
|
|
|
|
feature_mod: Plausible.Billing.Feature.Funnels
|
|
|
|
)
|
|
|
|
|
2023-11-08 17:59:03 +03:00
|
|
|
assert rendered =~ "This account does not have access to Funnels"
|
|
|
|
assert rendered =~ "please reach out to the site owner to upgrade their subscription"
|
2023-10-11 15:40:01 +03:00
|
|
|
end
|
|
|
|
|
2023-10-18 11:29:13 +03:00
|
|
|
test "premium_feature_notice/1 does not render a notice when the user has access to the feature" do
|
2023-10-18 11:48:47 +03:00
|
|
|
me = insert(:user, subscription: build(:business_subscription))
|
2023-10-11 15:40:01 +03:00
|
|
|
|
|
|
|
rendered =
|
2023-10-18 11:29:13 +03:00
|
|
|
render_component(&Billing.premium_feature_notice/1,
|
2023-10-11 23:24:16 +03:00
|
|
|
billable_user: me,
|
2023-10-11 15:40:01 +03:00
|
|
|
current_user: me,
|
|
|
|
feature_mod: Plausible.Billing.Feature.Funnels
|
|
|
|
)
|
|
|
|
|
|
|
|
assert rendered == ""
|
|
|
|
end
|
2023-11-08 16:24:30 +03:00
|
|
|
|
|
|
|
test "limit_exceeded_notice/1 when billable user is on growth displays upgrade link" do
|
|
|
|
me = insert(:user, subscription: build(:growth_subscription))
|
|
|
|
|
|
|
|
rendered =
|
|
|
|
render_component(&Billing.limit_exceeded_notice/1,
|
|
|
|
billable_user: me,
|
|
|
|
current_user: me,
|
|
|
|
limit: 10,
|
|
|
|
resource: "users"
|
|
|
|
)
|
|
|
|
|
2023-11-08 17:59:03 +03:00
|
|
|
assert rendered =~ "This account is limited to 10 users. To increase this limit"
|
2023-11-08 16:24:30 +03:00
|
|
|
assert rendered =~ "upgrade your subscription"
|
2023-11-08 19:57:20 +03:00
|
|
|
assert rendered =~ "/billing/choose-plan"
|
2023-11-08 16:24:30 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "limit_exceeded_notice/1 when billable user is on growth but is not current user does not display upgrade link" do
|
|
|
|
me = insert(:user, subscription: build(:growth_subscription))
|
|
|
|
|
|
|
|
rendered =
|
|
|
|
render_component(&Billing.limit_exceeded_notice/1,
|
|
|
|
billable_user: me,
|
|
|
|
current_user: insert(:user),
|
|
|
|
limit: 10,
|
|
|
|
resource: "users"
|
|
|
|
)
|
|
|
|
|
2023-11-08 17:59:03 +03:00
|
|
|
assert rendered =~ "This account is limited to 10 users"
|
|
|
|
assert rendered =~ "please reach out to the site owner to upgrade their subscription"
|
2023-11-08 16:24:30 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "limit_exceeded_notice/1 when billable user is on trial displays upgrade link" do
|
|
|
|
me = insert(:user)
|
|
|
|
|
|
|
|
rendered =
|
|
|
|
render_component(&Billing.limit_exceeded_notice/1,
|
|
|
|
billable_user: me,
|
|
|
|
current_user: me,
|
|
|
|
limit: 10,
|
|
|
|
resource: "users"
|
|
|
|
)
|
|
|
|
|
2023-11-08 17:59:03 +03:00
|
|
|
assert rendered =~ "This account is limited to 10 users"
|
2023-11-08 16:24:30 +03:00
|
|
|
assert rendered =~ "upgrade your subscription"
|
2023-11-08 19:57:20 +03:00
|
|
|
assert rendered =~ "/billing/choose-plan"
|
2023-11-08 16:24:30 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "limit_exceeded_notice/1 when billable user is on an enterprise plan displays support email" do
|
|
|
|
me =
|
|
|
|
insert(:user,
|
|
|
|
enterprise_plan: build(:enterprise_plan, paddle_plan_id: "123321"),
|
|
|
|
subscription: build(:subscription, paddle_plan_id: "123321")
|
|
|
|
)
|
|
|
|
|
|
|
|
rendered =
|
|
|
|
render_component(&Billing.limit_exceeded_notice/1,
|
|
|
|
billable_user: me,
|
|
|
|
current_user: me,
|
|
|
|
limit: 10,
|
|
|
|
resource: "users"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert rendered =~
|
|
|
|
"Your account is limited to 10 users. To increase this limit, please contact support@plausible.io about the Enterprise plan"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "limit_exceeded_notice/1 when billable user is on a business plan displays support email" do
|
|
|
|
me = insert(:user, subscription: build(:business_subscription))
|
|
|
|
|
|
|
|
rendered =
|
|
|
|
render_component(&Billing.limit_exceeded_notice/1,
|
|
|
|
billable_user: me,
|
|
|
|
current_user: me,
|
|
|
|
limit: 10,
|
|
|
|
resource: "users"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert rendered =~
|
|
|
|
"Your account is limited to 10 users. To increase this limit, please contact support@plausible.io about the Enterprise plan"
|
|
|
|
end
|
2023-10-11 15:40:01 +03:00
|
|
|
end
|