diff --git a/lib/teiserver/config.ex b/lib/teiserver/config.ex index 27c9ee4aa..9748c9af3 100644 --- a/lib/teiserver/config.ex +++ b/lib/teiserver/config.ex @@ -312,7 +312,7 @@ defmodule Teiserver.Config do Repo.one(query) end - @spec update_site_config(String.t(), String.t()) :: :ok + @spec update_site_config(String.t(), term()) :: :ok def update_site_config(key, value) do query = from site_config in SiteConfig, diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 8d0a55f87..bfbdf4612 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -35,6 +35,7 @@ defmodule TeiserverWeb.ConnCase do setup tags do :ok = Ecto.Adapters.SQL.Sandbox.checkout(Teiserver.Repo) Teiserver.TeiserverTestLib.clear_all_con_caches() + Teiserver.Config.update_site_config("system.Use geoip", false) on_exit(&Teiserver.TeiserverTestLib.clear_all_con_caches/0) unless tags[:async] do diff --git a/test/support/server_case.ex b/test/support/server_case.ex index fc55dca68..79b11acec 100644 --- a/test/support/server_case.ex +++ b/test/support/server_case.ex @@ -33,6 +33,7 @@ defmodule Teiserver.ServerCase do # more false failures. Teiserver.TeiserverTestLib.clear_all_con_caches() Teiserver.DataCase.setup_sandbox(tags) + Teiserver.Config.update_site_config("system.Use geoip", false) on_exit(&Teiserver.TeiserverTestLib.clear_all_con_caches/0) :ok end diff --git a/test/support/teiserver_test_lib.ex b/test/support/teiserver_test_lib.ex index 86ef591ae..f1ed67b0c 100644 --- a/test/support/teiserver_test_lib.ex +++ b/test/support/teiserver_test_lib.ex @@ -571,16 +571,18 @@ defmodule Teiserver.TeiserverTestLib do :telemetry_simple_server_event_types_cache ] - Enum.each(cache_list, fn cache -> - cache - |> ConCache.ets() - |> :ets.tab2list() - |> Enum.each(fn {key, _} -> ConCache.delete(cache, key) end) - end) + Enum.each(cache_list, &clear_cache/1) :ok end + def clear_cache(cache) do + cache + |> ConCache.ets() + |> :ets.tab2list() + |> Enum.each(fn {key, _} -> ConCache.delete(cache, key) end) + end + def seed_matchmaking_queues() do alias Teiserver.Game diff --git a/test/teiserver/data/user_test.exs b/test/teiserver/data/user_test.exs index 8353270ba..a3d68e72d 100644 --- a/test/teiserver/data/user_test.exs +++ b/test/teiserver/data/user_test.exs @@ -71,12 +71,13 @@ defmodule Teiserver.Data.UserTest do test "renaming" do user = TeiserverTestLib.new_user() + expected_rename_error = + {:error, "Rename limit reached (2 times in 5 days or 3 times in 30 days)"} + assert CacheUser.rename_user(user.id, "rename1") == :success assert CacheUser.rename_user(user.id, "rename2") == :success - assert CacheUser.rename_user(user.id, "rename3") == - {:error, - "If you keep changing your name people won't know who you are; give it a bit of time (5 days)"} + assert CacheUser.rename_user(user.id, "rename3") == expected_rename_error # Lets make it so they can do it again Account.update_user_stat(user.id, %{ @@ -86,9 +87,7 @@ defmodule Teiserver.Data.UserTest do assert CacheUser.rename_user(user.id, "rename4") == :success assert CacheUser.rename_user(user.id, "rename44") == :success - assert CacheUser.rename_user(user.id, "rename5") == - {:error, - "If you keep changing your name people won't know who you are; give it a bit of time (5 days)"} + assert CacheUser.rename_user(user.id, "rename5") == expected_rename_error # What if they've done it many times before but nothing recent? Account.update_user_stat(user.id, %{ @@ -98,9 +97,7 @@ defmodule Teiserver.Data.UserTest do assert CacheUser.rename_user(user.id, "rename6") == :success assert CacheUser.rename_user(user.id, "rename66") == :success - assert CacheUser.rename_user(user.id, "rename7") == - {:error, - "If you keep changing your name people won't know who you are; give it a bit of time (5 days)"} + assert CacheUser.rename_user(user.id, "rename7") == expected_rename_error # Nothing in the last 15 days but enough in the last 30 now = System.system_time(:second) @@ -114,9 +111,7 @@ defmodule Teiserver.Data.UserTest do ] }) - assert CacheUser.rename_user(user.id, "rename8") == - {:error, - "If you keep changing your name people won't know who you are; give it a bit of time (30 days)"} + assert CacheUser.rename_user(user.id, "rename8") == expected_rename_error end test "valid_email?" do diff --git a/test/teiserver_web/controllers/api/spads_controller_test.exs b/test/teiserver_web/controllers/api/spads_controller_test.exs index 9e432862d..3bf81e04b 100644 --- a/test/teiserver_web/controllers/api/spads_controller_test.exs +++ b/test/teiserver_web/controllers/api/spads_controller_test.exs @@ -38,6 +38,7 @@ defmodule TeiserverWeb.API.SpadsControllerTest do test "existing user", %{conn: conn} do user = new_user() + Teiserver.TeiserverTestLib.clear_cache(:teiserver_game_rating_types) rating_type_id = MatchRatingLib.rating_type_name_lookup()["Team"] {:ok, _} =