2019-11-19 07:30:42 +03:00
|
|
|
defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
|
|
|
|
use PlausibleWeb.ConnCase
|
|
|
|
import Plausible.TestUtils
|
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/conversions" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
test "returns mixed conversions in ordered by count", %{conn: conn, site: site} do
|
2020-05-18 12:44:52 +03:00
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/register"})
|
2019-11-19 07:30:42 +03:00
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Signup"})
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/conversions?period=day&date=2019-01-01")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-10-28 12:09:04 +03:00
|
|
|
%{"name" => "Signup", "count" => 3, "total_count" => 3, "meta_keys" => ["variant"]},
|
|
|
|
%{"name" => "Visit /register", "count" => 2, "total_count" => 2, "meta_keys" => nil}
|
2020-06-08 10:35:13 +03:00
|
|
|
]
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|
|
|
|
end
|
2019-11-20 11:49:22 +03:00
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/conversions - with goal filter" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
test "returns only the conversion tha is filtered for", %{conn: conn, site: site} do
|
2020-05-18 12:44:52 +03:00
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/register"})
|
2019-11-20 11:49:22 +03:00
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Signup"})
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{goal: "Signup"})
|
2020-06-08 10:35:13 +03:00
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/stats/#{site.domain}/conversions?period=day&date=2019-01-01&filters=#{filters}"
|
|
|
|
)
|
2019-11-20 11:49:22 +03:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-10-28 12:09:04 +03:00
|
|
|
%{"name" => "Signup", "count" => 3, "total_count" => 3, "meta_keys" => ["variant"]}
|
2020-06-08 10:35:13 +03:00
|
|
|
]
|
2019-11-20 11:49:22 +03:00
|
|
|
end
|
|
|
|
end
|
2020-10-28 12:09:04 +03:00
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/meta-breakdown/:key" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
test "returns metadata breakdown for goal", %{conn: conn, site: site} do
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Signup"})
|
|
|
|
filters = Jason.encode!(%{goal: "Signup"})
|
|
|
|
meta_key = "variant"
|
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/stats/#{site.domain}/meta-breakdown/#{meta_key}?period=day&date=2019-01-01&filters=#{filters}"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{"count" => 2, "name" => "B", "total_count" => 2},
|
|
|
|
%{"count" => 1, "name" => "A", "total_count" => 1}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|