Ensure step ordering works

pull/2859/head
Adam Rutkowski 4 years ago
parent 909f0ef40a
commit 0dc30d2680

@ -1,12 +1,24 @@
defmodule Plausible.Funnel do
use Ecto.Schema
defmodule Step do
use Ecto.Schema
@type t() :: %__MODULE__{}
schema "funnel_steps" do
field :step_order, :integer
belongs_to :funnel, Plausible.Funnel
belongs_to :goal, Plausible.Goal
timestamps()
end
end
@type t() :: %__MODULE__{}
schema "funnels" do
field :name, :string
belongs_to :site, Plausible.Site
has_many :steps, Plausible.FunnelStep,
has_many :steps, Step,
preload_order: [
asc: :step_order
]

@ -1,11 +0,0 @@
defmodule Plausible.FunnelStep do
use Ecto.Schema
@type t() :: %__MODULE__{}
schema "funnel_steps" do
field :step_order, :integer
belongs_to :funnel, Plausible.Funnel
belongs_to :goal, Plausible.Goal
timestamps()
end
end

@ -39,6 +39,7 @@ defmodule Plausible.Funnels do
where: f.id == ^funnel_id,
inner_join: steps in assoc(f, :steps),
inner_join: goal in assoc(steps, :goal),
order_by: steps.step_order,
preload: [
steps: {steps, goal: goal}
]

@ -35,12 +35,12 @@ defmodule Plausible.FunnelsTest do
assert fg3.step_order == 3
end
test "retrieve a funnel by id and site", %{site: site, goals: goals} do
test "retrieve a funnel by id and site, get steps in order", %{site: site, goals: [g1, g2, g3]} do
funnel =
Funnels.create(
site,
"Lorem ipsum",
goals,
[g3, g1, g2],
nil
)

Loading…
Cancel
Save