Skip to content

Commit

Permalink
Add fake data for geolocation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ukutaht committed Apr 12, 2021
1 parent ce23839 commit bfbadd1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ cron_enabled = String.to_existing_atom(System.get_env("CRON_ENABLED", "false"))
custom_domain_server_ip = System.get_env("CUSTOM_DOMAIN_SERVER_IP")
custom_domain_server_user = System.get_env("CUSTOM_DOMAIN_SERVER_USER")
custom_domain_server_password = System.get_env("CUSTOM_DOMAIN_SERVER_PASSWORD")
geolite2_country_db = System.get_env("GEOLITE2_COUNTRY_DB", "priv/geodb/dbip-country.mmdb")
geolite2_country_db = System.get_env("EOLITE2_COUNTRY_DB", "priv/geodb/dbip-country.mmdb")
disable_auth = String.to_existing_atom(System.get_env("DISABLE_AUTH", "false"))
disable_registration = String.to_existing_atom(System.get_env("DISABLE_REGISTRATION", "false"))
hcaptcha_sitekey = System.get_env("HCAPTCHA_SITEKEY")
Expand Down Expand Up @@ -243,7 +243,7 @@ config :kaffy,
]
]

if geolite2_country_db do
if config_env() != :test && geolite2_country_db do
config :geolix,
databases: [
%{
Expand Down
9 changes: 9 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@ config :plausible,
paddle_api: Plausible.PaddleApi.Mock,
google_api: Plausible.Google.Api.Mock

config :geolix,
databases: [
%{
id: :country,
adapter: Geolix.Adapter.Fake,
data: %{{1, 1, 1, 1} => %{country: %{iso_code: "US"}}}
}
]

config :plausible,
session_timeout: 0
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
assert event.referrer == ""
end

# Fake data is set up in config/test.exs
test "looks up the country from the ip address", %{conn: conn} do
params = %{
name: "pageview",
Expand All @@ -463,12 +464,12 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do

conn
|> put_req_header("content-type", "text/plain")
|> put_req_header("x-forwarded-for", "78.76.58.149")
|> put_req_header("x-forwarded-for", "1.1.1.1")
|> post("/api/event", Jason.encode!(params))

pageview = get_event("external-controller-test-20.com")

assert pageview.country_code == "SE"
assert pageview.country_code == "US"
end

test "URL is decoded", %{conn: conn} do
Expand Down

0 comments on commit bfbadd1

Please sign in to comment.