Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more tests #522

Merged
merged 5 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/teiserver/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/support/server_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions test/support/teiserver_test_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 7 additions & 12 deletions test/teiserver/data/user_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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, %{
Expand All @@ -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, %{
Expand All @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, _} =
Expand Down
Loading