|
|
|
|
@ -7,14 +7,22 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
test "returns suggestions for pages without a query", %{conn: conn, site: site} do
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/suggestions/page?period=month&date=2019-01-01")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == ["/", "/register", "/contact", "/irrelevant"]
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
|
%{"label" => "/", "value" => "/"},
|
|
|
|
|
%{"label" => "/register", "value" => "/register"},
|
|
|
|
|
%{"label" => "/contact", "value" => "/contact"},
|
|
|
|
|
%{"label" => "/irrelevant", "value" => "/irrelevant"}
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for pages with a query", %{conn: conn, site: site} do
|
|
|
|
|
conn =
|
|
|
|
|
get(conn, "/api/stats/#{site.domain}/suggestions/page?period=month&date=2019-01-01&q=re")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == ["/register", "/irrelevant"]
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
|
%{"label" => "/register", "value" => "/register"},
|
|
|
|
|
%{"label" => "/irrelevant", "value" => "/irrelevant"}
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for pages without any suggestions", %{conn: conn, site: site} do
|
|
|
|
|
@ -37,7 +45,10 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
conn =
|
|
|
|
|
get(conn, "/api/stats/#{site.domain}/suggestions/source?period=month&date=2019-01-01")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == ["10words", "Bing"]
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
|
%{"label" => "10words", "value" => "10words"},
|
|
|
|
|
%{"label" => "Bing", "value" => "Bing"}
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for countries", %{conn: conn, site: site} do
|
|
|
|
|
@ -47,7 +58,7 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
"/api/stats/#{site.domain}/suggestions/country?period=month&date=2019-01-01&q=Unit"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [%{"code" => "US", "name" => "United States"}]
|
|
|
|
|
assert json_response(conn, 200) == [%{"value" => "US", "label" => "United States"}]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for regions", %{conn: conn, user: user} do
|
|
|
|
|
@ -64,7 +75,7 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
"/api/stats/#{site.domain}/suggestions/region?q=Har"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [%{"code" => "EE-37", "name" => "Harjumaa"}]
|
|
|
|
|
assert json_response(conn, 200) == [%{"value" => "EE-37", "label" => "Harjumaa"}]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for cities", %{conn: conn, user: user} do
|
|
|
|
|
@ -81,7 +92,7 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
"/api/stats/#{site.domain}/suggestions/city?q=Kär"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [%{"code" => "591632", "name" => "Kärdla"}]
|
|
|
|
|
assert json_response(conn, 200) == [%{"value" => "591632", "label" => "Kärdla"}]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for countries without country in search", %{conn: conn, site: site} do
|
|
|
|
|
@ -98,14 +109,14 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
conn =
|
|
|
|
|
get(conn, "/api/stats/#{site.domain}/suggestions/screen?period=month&date=2019-01-01")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == ["Desktop"]
|
|
|
|
|
assert json_response(conn, 200) == [%{"value" => "Desktop", "label" => "Desktop"}]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for browsers", %{conn: conn, site: site} do
|
|
|
|
|
conn =
|
|
|
|
|
get(conn, "/api/stats/#{site.domain}/suggestions/browser?period=month&date=2019-01-01")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == ["Chrome"]
|
|
|
|
|
assert json_response(conn, 200) == [%{"label" => "Chrome", "value" => "Chrome"}]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for browser versions", %{conn: conn, site: site} do
|
|
|
|
|
@ -117,13 +128,13 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
"/api/stats/#{site.domain}/suggestions/browser_version?period=month&date=2019-01-01&filters=#{filters}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == ["78.0"]
|
|
|
|
|
assert json_response(conn, 200) == [%{"value" => "78.0", "label" => "78.0"}]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for OS", %{conn: conn, site: site} do
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/suggestions/os?period=month&date=2019-01-01")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == ["Mac"]
|
|
|
|
|
assert json_response(conn, 200) == [%{"value" => "Mac", "label" => "Mac"}]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for OS versions", %{conn: conn, site: site} do
|
|
|
|
|
@ -135,7 +146,7 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
"/api/stats/#{site.domain}/suggestions/os_version?period=month&date=2019-01-01&filters=#{filters}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == ["10.15"]
|
|
|
|
|
assert json_response(conn, 200) == [%{"label" => "10.15", "value" => "10.15"}]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for OS versions with search", %{conn: conn, site: site} do
|
|
|
|
|
@ -154,7 +165,9 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
conn =
|
|
|
|
|
get(conn, "/api/stats/#{site.domain}/suggestions/referrer?period=month&date=2019-01-01")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == ["10words.com/page1"]
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
|
%{"value" => "10words.com/page1", "label" => "10words.com/page1"}
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ -183,7 +196,11 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
conn =
|
|
|
|
|
get(conn, "/api/stats/#{site.domain}/suggestions/prop_key?period=day&date=2022-01-01")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) |> Enum.sort() == ["author", "dark_mode", "logged_in"]
|
|
|
|
|
assert json_response(conn, 200) |> Enum.map(& &1["value"]) |> Enum.sort() == [
|
|
|
|
|
"author",
|
|
|
|
|
"dark_mode",
|
|
|
|
|
"logged_in"
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for prop key with value filter", %{conn: conn, site: site} do
|
|
|
|
|
@ -213,7 +230,10 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
"/api/stats/#{site.domain}/suggestions/prop_key?period=day&date=2022-01-01&filters=#{filters}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) |> Enum.sort() == ["dark_mode", "logged_in"]
|
|
|
|
|
assert json_response(conn, 200) |> Enum.map(& &1["value"]) |> Enum.sort() == [
|
|
|
|
|
"dark_mode",
|
|
|
|
|
"logged_in"
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for prop value with no filter", %{conn: conn, site: site} do
|
|
|
|
|
@ -238,7 +258,11 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
conn =
|
|
|
|
|
get(conn, "/api/stats/#{site.domain}/suggestions/prop_value?period=day&date=2022-01-01")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) |> Enum.sort() == ["Uku Taht", "false", "true"]
|
|
|
|
|
assert json_response(conn, 200) |> Enum.map(& &1["value"]) |> Enum.sort() == [
|
|
|
|
|
"Uku Taht",
|
|
|
|
|
"false",
|
|
|
|
|
"true"
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns suggestions for prop value with filter on prop key", %{conn: conn, site: site} do
|
|
|
|
|
@ -268,7 +292,7 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
|
|
|
|
"/api/stats/#{site.domain}/suggestions/prop_value?period=day&date=2022-01-01&filters=#{filters}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) |> Enum.sort() == ["Uku Taht"]
|
|
|
|
|
assert json_response(conn, 200) |> Enum.map(& &1["value"]) |> Enum.sort() == ["Uku Taht"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "when date is borked, bad request is returned", %{
|
|
|
|
|
|