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

34 lines
1.0 KiB
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_site]
test "returns top countries by new visitors", %{conn: conn, site: site} do
conn = get(conn, "/api/stats/#{site.domain}/countries?period=day&date=2019-01-01")
assert json_response(conn, 200) == [
%{
"name" => "EST",
"full_country_name" => "Estonia",
"count" => 2,
"percentage" => 50
},
%{
"name" => "GBR",
"full_country_name" => "United Kingdom",
"count" => 1,
"percentage" => 25
},
%{
"name" => "USA",
"full_country_name" => "United States",
"count" => 1,
"percentage" => 25
}
]
end
end
end