Add tests for utm_term and content in the API

This commit is contained in:
Uku Taht 2021-12-16 16:18:16 +02:00
parent d48eafc436
commit 15931b9346

View File

@ -268,20 +268,17 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do
end
test "breakdown by visit:utm_campaign", %{conn: conn, site: site} do
populate_stats([
populate_stats(site, [
build(:pageview,
utm_campaign: "ads",
domain: site.domain,
timestamp: ~N[2021-01-01 00:00:00]
),
build(:pageview,
utm_campaign: "ads",
domain: site.domain,
timestamp: ~N[2021-01-01 00:25:00]
),
build(:pageview,
utm_campaign: "",
domain: site.domain,
timestamp: ~N[2021-01-01 00:00:00]
)
])
@ -302,6 +299,70 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do
}
end
test "breakdown by visit:utm_content", %{conn: conn, site: site} do
populate_stats(site, [
build(:pageview,
utm_content: "Content1",
timestamp: ~N[2021-01-01 00:00:00]
),
build(:pageview,
utm_content: "Content1",
timestamp: ~N[2021-01-01 00:25:00]
),
build(:pageview,
utm_content: "",
timestamp: ~N[2021-01-01 00:00:00]
)
])
conn =
get(conn, "/api/v1/stats/breakdown", %{
"site_id" => site.domain,
"period" => "day",
"date" => "2021-01-01",
"property" => "visit:utm_content"
})
assert json_response(conn, 200) == %{
"results" => [
%{"utm_content" => "Content1", "visitors" => 2},
%{"utm_content" => "Direct / None", "visitors" => 1}
]
}
end
test "breakdown by visit:utm_term", %{conn: conn, site: site} do
populate_stats(site, [
build(:pageview,
utm_term: "Term1",
timestamp: ~N[2021-01-01 00:00:00]
),
build(:pageview,
utm_term: "Term1",
timestamp: ~N[2021-01-01 00:25:00]
),
build(:pageview,
utm_term: "",
timestamp: ~N[2021-01-01 00:00:00]
)
])
conn =
get(conn, "/api/v1/stats/breakdown", %{
"site_id" => site.domain,
"period" => "day",
"date" => "2021-01-01",
"property" => "visit:utm_term"
})
assert json_response(conn, 200) == %{
"results" => [
%{"utm_term" => "Term1", "visitors" => 2},
%{"utm_term" => "Direct / None", "visitors" => 1}
]
}
end
test "breakdown by visit:device", %{conn: conn, site: site} do
populate_stats([
build(:pageview,