|
|
|
|
@ -25,7 +25,7 @@ defmodule Plausible.GoalsTest do
|
|
|
|
|
|
|
|
|
|
goals = Goals.for_site(site)
|
|
|
|
|
|
|
|
|
|
assert [%{event_name: "Signup"}, %{page_path: "/Signup"}] = goals
|
|
|
|
|
assert [%{page_path: "/Signup"}, %{event_name: "Signup"}] = goals
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "goals are present after domain change" do
|
|
|
|
|
@ -47,4 +47,86 @@ defmodule Plausible.GoalsTest do
|
|
|
|
|
|
|
|
|
|
assert [] = Goals.for_site(site)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "goals can be deleted" do
|
|
|
|
|
site = insert(:site)
|
|
|
|
|
goal = insert(:goal, %{site: site, event_name: " Signup "})
|
|
|
|
|
:ok = Goals.delete(goal.id, site)
|
|
|
|
|
assert [] = Goals.for_site(site)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "goals can be fetched with funnel count preloaded" do
|
|
|
|
|
site = insert(:site)
|
|
|
|
|
|
|
|
|
|
goals =
|
|
|
|
|
Enum.map(1..4, fn i ->
|
|
|
|
|
{:ok, g} = Goals.create(site, %{"page_path" => "/#{i}"})
|
|
|
|
|
g
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
{:ok, %{id: funnel_id1}} =
|
|
|
|
|
Plausible.Funnels.create(
|
|
|
|
|
site,
|
|
|
|
|
"Funnel1",
|
|
|
|
|
[
|
|
|
|
|
%{"goal_id" => Enum.at(goals, 1).id},
|
|
|
|
|
%{"goal_id" => Enum.at(goals, 2).id},
|
|
|
|
|
%{"goal_id" => Enum.at(goals, 3).id}
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
{:ok, %{id: funnel_id2}} =
|
|
|
|
|
Plausible.Funnels.create(
|
|
|
|
|
site,
|
|
|
|
|
"Funnel2",
|
|
|
|
|
[
|
|
|
|
|
%{"goal_id" => Enum.at(goals, 1).id},
|
|
|
|
|
%{"goal_id" => Enum.at(goals, 3).id}
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert [goal, _, _, _] = Goals.for_site(site, preload_funnels?: false)
|
|
|
|
|
assert %Ecto.Association.NotLoaded{} = goal.funnels
|
|
|
|
|
|
|
|
|
|
assert [goal, _, _, _] = Goals.for_site(site, preload_funnels?: true)
|
|
|
|
|
assert [%{id: ^funnel_id1}, %{id: ^funnel_id2}] = goal.funnels
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "deleting goals with funnels triggers funnel reduction" do
|
|
|
|
|
site = insert(:site)
|
|
|
|
|
{:ok, g1} = Goals.create(site, %{"page_path" => "/1"})
|
|
|
|
|
{:ok, g2} = Goals.create(site, %{"page_path" => "/2"})
|
|
|
|
|
{:ok, g3} = Goals.create(site, %{"page_path" => "/3"})
|
|
|
|
|
|
|
|
|
|
{:ok, f1} =
|
|
|
|
|
Plausible.Funnels.create(
|
|
|
|
|
site,
|
|
|
|
|
"Funnel 3 steps",
|
|
|
|
|
[
|
|
|
|
|
%{"goal_id" => g1.id},
|
|
|
|
|
%{"goal_id" => g2.id},
|
|
|
|
|
%{"goal_id" => g3.id}
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
{:ok, f2} =
|
|
|
|
|
Plausible.Funnels.create(
|
|
|
|
|
site,
|
|
|
|
|
"Funnel 2 steps",
|
|
|
|
|
[
|
|
|
|
|
%{"goal_id" => g1.id},
|
|
|
|
|
%{"goal_id" => g2.id}
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
:ok = Goals.delete(g1.id, site)
|
|
|
|
|
|
|
|
|
|
assert {:ok, f1} = Plausible.Funnels.get(site.id, f1.id)
|
|
|
|
|
assert Enum.count(f1.steps) == 2
|
|
|
|
|
|
|
|
|
|
assert {:error, "Funnel not found"} = Plausible.Funnels.get(site.id, f2.id)
|
|
|
|
|
assert Repo.all(from fs in Plausible.Funnel.Step, where: fs.funnel_id == ^f2.id) == []
|
|
|
|
|
|
|
|
|
|
assert [^g3, ^g2] = Goals.for_site(site)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|