Keep user filter when listing cities, countries, and regions stats (#2030)
This commit fixes a bug where location filters were filtering stats but
not the locations list. This was caused by a `Map.put/3` call that
overrides the user filter. This commit rollbacks 5b57143273
changes and removes the `Map.put/3` call.
Closes #1982
pull/2056/head
parent
0324d03da9
commit
b5ea6ae3dc
@ -0,0 +1,36 @@
|
||||
defmodule PlausibleWeb.Api.StatsController.CitiesTest do
|
||||
use PlausibleWeb.ConnCase
|
||||
import Plausible.TestUtils
|
||||
|
||||
describe "GET /api/stats/:domain/cities" do
|
||||
defp seed(%{site: site}) do
|
||||
populate_stats(site, [
|
||||
build(:pageview, country_code: "EE", subdivision1_code: "EE-37", city_geoname_id: 588_409),
|
||||
build(:pageview, country_code: "EE", subdivision1_code: "EE-37", city_geoname_id: 588_409),
|
||||
build(:pageview, country_code: "EE", subdivision1_code: "EE-37", city_geoname_id: 588_409),
|
||||
build(:pageview, country_code: "EE", subdivision1_code: "EE-39", city_geoname_id: 591_632),
|
||||
build(:pageview, country_code: "EE", subdivision1_code: "EE-39", city_geoname_id: 591_632)
|
||||
])
|
||||
end
|
||||
|
||||
setup [:create_user, :log_in, :create_new_site, :add_imported_data, :seed]
|
||||
|
||||
test "returns top cities by new visitors", %{conn: conn, site: site} do
|
||||
conn = get(conn, "/api/stats/#{site.domain}/cities?period=day")
|
||||
|
||||
assert json_response(conn, 200) == [
|
||||
%{"code" => 588_409, "country_flag" => "🇪🇪", "name" => "Tallinn", "visitors" => 3},
|
||||
%{"code" => 591_632, "country_flag" => "🇪🇪", "name" => "Kärdla", "visitors" => 2}
|
||||
]
|
||||
end
|
||||
|
||||
test "when list is filtered returns one city only", %{conn: conn, site: site} do
|
||||
filters = Jason.encode!(%{city: "591632"})
|
||||
conn = get(conn, "/api/stats/#{site.domain}/cities?period=day&filters=#{filters}")
|
||||
|
||||
assert json_response(conn, 200) == [
|
||||
%{"code" => 591_632, "country_flag" => "🇪🇪", "name" => "Kärdla", "visitors" => 2}
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,36 @@
|
||||
defmodule PlausibleWeb.Api.StatsController.RegionsTest do
|
||||
use PlausibleWeb.ConnCase
|
||||
import Plausible.TestUtils
|
||||
|
||||
describe "GET /api/stats/:domain/regions" do
|
||||
defp seed(%{site: site}) do
|
||||
populate_stats(site, [
|
||||
build(:pageview, country_code: "EE", subdivision1_code: "EE-37", city_geoname_id: 588_409),
|
||||
build(:pageview, country_code: "EE", subdivision1_code: "EE-37", city_geoname_id: 588_409),
|
||||
build(:pageview, country_code: "EE", subdivision1_code: "EE-37", city_geoname_id: 588_409),
|
||||
build(:pageview, country_code: "EE", subdivision1_code: "EE-39", city_geoname_id: 591_632),
|
||||
build(:pageview, country_code: "EE", subdivision1_code: "EE-39", city_geoname_id: 591_632)
|
||||
])
|
||||
end
|
||||
|
||||
setup [:create_user, :log_in, :create_new_site, :add_imported_data, :seed]
|
||||
|
||||
test "returns top cities by new visitors", %{conn: conn, site: site} do
|
||||
conn = get(conn, "/api/stats/#{site.domain}/regions?period=day")
|
||||
|
||||
assert json_response(conn, 200) == [
|
||||
%{"code" => "EE-37", "country_flag" => "🇪🇪", "name" => "Harjumaa", "visitors" => 3},
|
||||
%{"code" => "EE-39", "country_flag" => "🇪🇪", "name" => "Hiiumaa", "visitors" => 2}
|
||||
]
|
||||
end
|
||||
|
||||
test "when list is filtered returns one city only", %{conn: conn, site: site} do
|
||||
filters = Jason.encode!(%{region: "EE-39"})
|
||||
conn = get(conn, "/api/stats/#{site.domain}/regions?period=day&filters=#{filters}")
|
||||
|
||||
assert json_response(conn, 200) == [
|
||||
%{"code" => "EE-39", "country_flag" => "🇪🇪", "name" => "Hiiumaa", "visitors" => 2}
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue