2024-02-21 14:41:56 +03:00
|
|
|
defmodule PlausibleWeb.Plugins.API.Controllers.CapabilitiesTest do
|
|
|
|
use PlausibleWeb.PluginsAPICase, async: true
|
|
|
|
alias PlausibleWeb.Plugins.API.Schemas
|
|
|
|
|
|
|
|
describe "examples" do
|
|
|
|
test "Capabilities" do
|
|
|
|
assert_schema(
|
|
|
|
Schemas.Capabilities.schema().example,
|
|
|
|
"Capabilities",
|
|
|
|
spec()
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "unauthorized" do
|
|
|
|
test "no token", %{conn: conn} do
|
2024-02-28 12:26:01 +03:00
|
|
|
resp =
|
|
|
|
conn
|
|
|
|
|> get(Routes.plugins_api_capabilities_url(PlausibleWeb.Endpoint, :index))
|
|
|
|
|> json_response(200)
|
2024-02-21 14:41:56 +03:00
|
|
|
|
2024-02-28 12:26:01 +03:00
|
|
|
assert resp ==
|
2024-02-21 14:41:56 +03:00
|
|
|
%{
|
|
|
|
"authorized" => false,
|
|
|
|
"data_domain" => nil,
|
|
|
|
"features" => %{
|
|
|
|
"Funnels" => false,
|
|
|
|
"Goals" => false,
|
|
|
|
"Props" => false,
|
|
|
|
"RevenueGoals" => false,
|
|
|
|
"StatsAPI" => false
|
|
|
|
}
|
|
|
|
}
|
2024-02-28 12:26:01 +03:00
|
|
|
|
|
|
|
assert_schema(resp, "Capabilities", spec())
|
2024-02-21 14:41:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "bad token", %{conn: conn} do
|
|
|
|
resp =
|
|
|
|
conn
|
|
|
|
|> put_req_header("content-type", "application/json")
|
|
|
|
|> authenticate("foo", "bad token")
|
|
|
|
|> get(Routes.plugins_api_capabilities_url(PlausibleWeb.Endpoint, :index))
|
2024-02-28 12:26:01 +03:00
|
|
|
|> json_response(200)
|
2024-02-21 14:41:56 +03:00
|
|
|
|
2024-02-28 12:26:01 +03:00
|
|
|
assert resp ==
|
2024-02-21 14:41:56 +03:00
|
|
|
%{
|
|
|
|
"authorized" => false,
|
|
|
|
"data_domain" => nil,
|
|
|
|
"features" => %{
|
|
|
|
"Funnels" => false,
|
|
|
|
"Goals" => false,
|
|
|
|
"Props" => false,
|
|
|
|
"RevenueGoals" => false,
|
|
|
|
"StatsAPI" => false
|
|
|
|
}
|
|
|
|
}
|
2024-02-28 12:26:01 +03:00
|
|
|
|
|
|
|
assert_schema(resp, "Capabilities", spec())
|
2024-02-21 14:41:56 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "authorized" do
|
|
|
|
test "trial", %{conn: conn, site: site, token: token} do
|
|
|
|
resp =
|
|
|
|
conn
|
|
|
|
|> put_req_header("content-type", "application/json")
|
|
|
|
|> authenticate(site.domain, token)
|
|
|
|
|> get(Routes.plugins_api_capabilities_url(PlausibleWeb.Endpoint, :index))
|
2024-02-28 12:26:01 +03:00
|
|
|
|> json_response(200)
|
2024-02-21 14:41:56 +03:00
|
|
|
|
2024-02-28 12:26:01 +03:00
|
|
|
assert resp ==
|
2024-02-21 14:41:56 +03:00
|
|
|
%{
|
|
|
|
"authorized" => true,
|
|
|
|
"data_domain" => site.domain,
|
|
|
|
"features" => %{
|
|
|
|
"Funnels" => true,
|
|
|
|
"Goals" => true,
|
|
|
|
"Props" => true,
|
|
|
|
"RevenueGoals" => true,
|
|
|
|
"StatsAPI" => true
|
|
|
|
}
|
|
|
|
}
|
2024-02-28 12:26:01 +03:00
|
|
|
|
|
|
|
assert_schema(resp, "Capabilities", spec())
|
2024-02-21 14:41:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "growth", %{conn: conn, site: site, token: token} do
|
|
|
|
site = Plausible.Repo.preload(site, :owner)
|
|
|
|
insert(:growth_subscription, user: site.owner)
|
|
|
|
|
|
|
|
resp =
|
|
|
|
conn
|
|
|
|
|> put_req_header("content-type", "application/json")
|
|
|
|
|> authenticate(site.domain, token)
|
|
|
|
|> get(Routes.plugins_api_capabilities_url(PlausibleWeb.Endpoint, :index))
|
2024-02-28 12:26:01 +03:00
|
|
|
|> json_response(200)
|
2024-02-21 14:41:56 +03:00
|
|
|
|
2024-02-28 12:26:01 +03:00
|
|
|
assert resp ==
|
2024-02-21 14:41:56 +03:00
|
|
|
%{
|
|
|
|
"authorized" => true,
|
|
|
|
"data_domain" => site.domain,
|
|
|
|
"features" => %{
|
|
|
|
"Funnels" => false,
|
|
|
|
"Goals" => true,
|
|
|
|
"Props" => false,
|
|
|
|
"RevenueGoals" => false,
|
|
|
|
"StatsAPI" => false
|
|
|
|
}
|
|
|
|
}
|
2024-02-28 12:26:01 +03:00
|
|
|
|
|
|
|
assert_schema(resp, "Capabilities", spec())
|
2024-02-21 14:41:56 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|