You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
analytics/test/plausible_web/controllers/api/stats_controller/countries_test.exs

38 lines
955 B
Elixir

defmodule PlausibleWeb.Api.StatsController.CountriesTest do
use PlausibleWeb.ConnCase
import Plausible.TestUtils
describe "GET /api/stats/:domain/countries" do
setup [:create_user, :log_in, :create_new_site]
test "returns top countries by new visitors", %{conn: conn, site: site} do
populate_stats(site, [
build(:pageview,
country_code: "EE"
),
build(:pageview,
country_code: "EE"
),
build(:pageview,
country_code: "GB"
)
])
conn = get(conn, "/api/stats/#{site.domain}/countries?period=day")
assert json_response(conn, 200) == [
%{
"name" => "EST",
"count" => 2,
"percentage" => 67
},
%{
"name" => "GBR",
"count" => 1,
"percentage" => 33
}
]
end
end
end