|
|
|
|
@ -621,131 +621,6 @@ defmodule PlausibleWeb.SiteControllerTest do
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "GET /:website/goals/new" do
|
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
|
|
test "shows form to create a new goal", %{conn: conn, site: site} do
|
|
|
|
|
conn = get(conn, "/#{site.domain}/goals/new")
|
|
|
|
|
|
|
|
|
|
assert html_response(conn, 200) =~ "Add goal"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "POST /:website/goals" do
|
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
|
|
test "creates a pageview goal for the website", %{conn: conn, site: site} do
|
|
|
|
|
conn =
|
|
|
|
|
post(conn, "/#{site.domain}/goals", %{
|
|
|
|
|
goal: %{
|
|
|
|
|
page_path: "/success",
|
|
|
|
|
event_name: ""
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
goal = Repo.one(Plausible.Goal)
|
|
|
|
|
|
|
|
|
|
assert goal.page_path == "/success"
|
|
|
|
|
assert goal.event_name == nil
|
|
|
|
|
assert redirected_to(conn, 302) == "/#{site.domain}/settings/goals"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "creates a custom event goal for the website", %{conn: conn, site: site} do
|
|
|
|
|
conn =
|
|
|
|
|
post(conn, "/#{site.domain}/goals", %{
|
|
|
|
|
goal: %{
|
|
|
|
|
page_path: "",
|
|
|
|
|
event_name: "Signup"
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
goal = Repo.one(Plausible.Goal)
|
|
|
|
|
|
|
|
|
|
assert goal.event_name == "Signup"
|
|
|
|
|
assert goal.page_path == nil
|
|
|
|
|
assert redirected_to(conn, 302) == "/#{site.domain}/settings/goals"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "creates a custom event goal with a revenue value", %{conn: conn, site: site} do
|
|
|
|
|
conn =
|
|
|
|
|
post(conn, "/#{site.domain}/goals", %{
|
|
|
|
|
goal: %{
|
|
|
|
|
page_path: "",
|
|
|
|
|
event_name: "Purchase",
|
|
|
|
|
currency: "EUR"
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
goal = Repo.get_by(Plausible.Goal, site_id: site.id)
|
|
|
|
|
|
|
|
|
|
assert goal.event_name == "Purchase"
|
|
|
|
|
assert goal.page_path == nil
|
|
|
|
|
assert goal.currency == :EUR
|
|
|
|
|
|
|
|
|
|
assert redirected_to(conn, 302) == "/#{site.domain}/settings/goals"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "fails to create a custom event goal with a non-existant currency", %{
|
|
|
|
|
conn: conn,
|
|
|
|
|
site: site
|
|
|
|
|
} do
|
|
|
|
|
conn =
|
|
|
|
|
post(conn, "/#{site.domain}/goals", %{
|
|
|
|
|
goal: %{
|
|
|
|
|
page_path: "",
|
|
|
|
|
event_name: "Purchase",
|
|
|
|
|
currency: "EEEE"
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
refute Repo.get_by(Plausible.Goal, site_id: site.id)
|
|
|
|
|
|
|
|
|
|
assert html_response(conn, 200) =~ "is invalid"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "Cleans currency for pageview goal creation", %{conn: conn, site: site} do
|
|
|
|
|
conn =
|
|
|
|
|
post(conn, "/#{site.domain}/goals", %{
|
|
|
|
|
goal: %{
|
|
|
|
|
page_path: "/purchase",
|
|
|
|
|
event_name: "",
|
|
|
|
|
currency: "EUR"
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
goal = Repo.get_by(Plausible.Goal, site_id: site.id)
|
|
|
|
|
|
|
|
|
|
assert goal.event_name == nil
|
|
|
|
|
assert goal.page_path == "/purchase"
|
|
|
|
|
assert goal.currency == nil
|
|
|
|
|
|
|
|
|
|
assert redirected_to(conn, 302) == "/#{site.domain}/settings/goals"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "DELETE /:website/goals/:id" do
|
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
|
|
test "deletes goal", %{conn: conn, site: site} do
|
|
|
|
|
goal = insert(:goal, site: site, event_name: "Custom event")
|
|
|
|
|
|
|
|
|
|
conn = delete(conn, "/#{site.domain}/goals/#{goal.id}")
|
|
|
|
|
|
|
|
|
|
assert Repo.aggregate(Plausible.Goal, :count, :id) == 0
|
|
|
|
|
assert redirected_to(conn, 302) == "/#{site.domain}/settings/goals"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "fails to delete goal for a foreign site", %{conn: conn, site: site} do
|
|
|
|
|
another_site = insert(:site)
|
|
|
|
|
goal = insert(:goal, site: another_site, event_name: "Custom event")
|
|
|
|
|
|
|
|
|
|
conn = delete(conn, "/#{site.domain}/goals/#{goal.id}")
|
|
|
|
|
|
|
|
|
|
assert Repo.aggregate(Plausible.Goal, :count, :id) == 1
|
|
|
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) == "Could not find goal"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "PUT /:website/settings/features/visibility/:setting" do
|
|
|
|
|
def build_conn_with_some_url(context) do
|
|
|
|
|
{:ok, Map.put(context, :conn, build_conn(:get, "/some_parent_path"))}
|
|
|
|
|
|