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
)
assert rendered =~ " Custom Properties is part of the Plausible Business plan. "
assert rendered =~ " upgrade your subscription "
assert rendered =~ " /billing/upgrade "
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
)
assert rendered =~
" Funnels is part of the Plausible Business plan. To get access to it, please reach out to the site owner to upgrade your subscription to the Business plan. "
refute rendered =~ " /billing/upgrade "
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
end