2023-12-15 19:59:16 +03:00
|
|
|
defmodule PlausibleWeb.Components.Billing.NoticeTest do
|
2023-10-11 15:40:01 +03:00
|
|
|
use Plausible.DataCase
|
|
|
|
import Phoenix.LiveViewTest
|
2023-12-15 19:59:16 +03:00
|
|
|
alias PlausibleWeb.Components.Billing.Notice
|
2023-10-11 15:40:01 +03:00
|
|
|
|
2023-12-15 19:59:16 +03:00
|
|
|
test "premium_feature/1 does not render a notice when user is on trial" do
|
2023-10-11 15:40:01 +03:00
|
|
|
me = insert(:user)
|
|
|
|
|
2023-12-15 19:59:16 +03:00
|
|
|
assert render_component(&Notice.premium_feature/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-14 15:40:04 +03:00
|
|
|
) == ""
|
2023-10-11 15:40:01 +03:00
|
|
|
end
|
|
|
|
|
2023-12-15 19:59:16 +03:00
|
|
|
test "premium_feature/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-12-15 19:59:16 +03:00
|
|
|
render_component(&Notice.premium_feature/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-10 17:03:02 +03:00
|
|
|
assert rendered =~ "Your 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-12-15 19:59:16 +03:00
|
|
|
test "premium_feature/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-12-15 19:59:16 +03:00
|
|
|
render_component(&Notice.premium_feature/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-10 17:03:02 +03:00
|
|
|
assert rendered =~ "The owner of this site does not have access to Funnels"
|
2023-11-08 17:59:03 +03:00
|
|
|
assert rendered =~ "please reach out to the site owner to upgrade their subscription"
|
2023-10-11 15:40:01 +03:00
|
|
|
end
|
|
|
|
|
2023-12-15 19:59:16 +03:00
|
|
|
test "premium_feature/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-12-15 19:59:16 +03:00
|
|
|
render_component(&Notice.premium_feature/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
|
|
|
|
2023-12-15 19:59:16 +03:00
|
|
|
test "limit_exceeded/1 when billable user is on growth displays upgrade link" do
|
2023-11-08 16:24:30 +03:00
|
|
|
me = insert(:user, subscription: build(:growth_subscription))
|
|
|
|
|
|
|
|
rendered =
|
2023-12-15 19:59:16 +03:00
|
|
|
render_component(&Notice.limit_exceeded/1,
|
2023-11-08 16:24:30 +03:00
|
|
|
billable_user: me,
|
|
|
|
current_user: me,
|
|
|
|
limit: 10,
|
|
|
|
resource: "users"
|
|
|
|
)
|
|
|
|
|
2023-11-10 17:03:02 +03:00
|
|
|
assert rendered =~ "Your 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
|
|
|
|
|
2023-12-15 19:59:16 +03:00
|
|
|
test "limit_exceeded/1 when billable user is on growth but is not current user does not display upgrade link" do
|
2023-11-08 16:24:30 +03:00
|
|
|
me = insert(:user, subscription: build(:growth_subscription))
|
|
|
|
|
|
|
|
rendered =
|
2023-12-15 19:59:16 +03:00
|
|
|
render_component(&Notice.limit_exceeded/1,
|
2023-11-08 16:24:30 +03:00
|
|
|
billable_user: me,
|
|
|
|
current_user: insert(:user),
|
|
|
|
limit: 10,
|
|
|
|
resource: "users"
|
|
|
|
)
|
|
|
|
|
2023-11-10 17:03:02 +03:00
|
|
|
assert rendered =~ "The owner of this site is limited to 10 users"
|
2023-11-08 17:59:03 +03:00
|
|
|
assert rendered =~ "please reach out to the site owner to upgrade their subscription"
|
2023-11-08 16:24:30 +03:00
|
|
|
end
|
|
|
|
|
2024-04-29 09:05:33 +03:00
|
|
|
@tag :ee_only
|
2023-12-15 19:59:16 +03:00
|
|
|
test "limit_exceeded/1 when billable user is on trial displays upgrade link" do
|
2023-11-08 16:24:30 +03:00
|
|
|
me = insert(:user)
|
|
|
|
|
|
|
|
rendered =
|
2023-12-15 19:59:16 +03:00
|
|
|
render_component(&Notice.limit_exceeded/1,
|
2023-11-08 16:24:30 +03:00
|
|
|
billable_user: me,
|
|
|
|
current_user: me,
|
|
|
|
limit: 10,
|
|
|
|
resource: "users"
|
|
|
|
)
|
|
|
|
|
2023-11-10 17:03:02 +03:00
|
|
|
assert rendered =~ "Your 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
|
|
|
|
|
2024-04-29 09:05:33 +03:00
|
|
|
@tag :ee_only
|
2023-12-15 19:59:16 +03:00
|
|
|
test "limit_exceeded/1 when billable user is on an enterprise plan displays support email" do
|
2023-11-08 16:24:30 +03:00
|
|
|
me =
|
|
|
|
insert(:user,
|
|
|
|
enterprise_plan: build(:enterprise_plan, paddle_plan_id: "123321"),
|
|
|
|
subscription: build(:subscription, paddle_plan_id: "123321")
|
|
|
|
)
|
|
|
|
|
|
|
|
rendered =
|
2023-12-15 19:59:16 +03:00
|
|
|
render_component(&Notice.limit_exceeded/1,
|
2023-11-08 16:24:30 +03:00
|
|
|
billable_user: me,
|
|
|
|
current_user: me,
|
|
|
|
limit: 10,
|
|
|
|
resource: "users"
|
|
|
|
)
|
|
|
|
|
2023-11-10 17:03:02 +03:00
|
|
|
assert rendered =~ "Your account is limited to 10 users."
|
2024-02-01 11:43:21 +03:00
|
|
|
|
|
|
|
assert rendered =~ "hello@plausible.io"
|
|
|
|
assert rendered =~ "upgrade your subscription"
|
2023-11-08 16:24:30 +03:00
|
|
|
end
|
|
|
|
|
2024-04-29 09:05:33 +03:00
|
|
|
@tag :ee_only
|
2023-12-15 19:59:16 +03:00
|
|
|
test "limit_exceeded/1 when billable user is on a business plan displays support email" do
|
2023-11-08 16:24:30 +03:00
|
|
|
me = insert(:user, subscription: build(:business_subscription))
|
|
|
|
|
|
|
|
rendered =
|
2023-12-15 19:59:16 +03:00
|
|
|
render_component(&Notice.limit_exceeded/1,
|
2023-11-08 16:24:30 +03:00
|
|
|
billable_user: me,
|
|
|
|
current_user: me,
|
|
|
|
limit: 10,
|
|
|
|
resource: "users"
|
|
|
|
)
|
|
|
|
|
2023-11-10 17:03:02 +03:00
|
|
|
assert rendered =~ "Your account is limited to 10 users."
|
2024-02-01 11:43:21 +03:00
|
|
|
|
|
|
|
assert rendered =~ "hello@plausible.io"
|
|
|
|
assert rendered =~ "upgrade your subscription"
|
2023-11-08 16:24:30 +03:00
|
|
|
end
|
2023-10-11 15:40:01 +03:00
|
|
|
end
|