From 8140adf6ba8b22b691f4ca45ec916bec6104d617 Mon Sep 17 00:00:00 2001 From: bigbluejay9 <2730943+bigbluejay9@users.noreply.github.com> Date: Sun, 6 Oct 2024 14:49:35 +0700 Subject: [PATCH 1/4] Seed test db will all possible game types. The spads controller 'ratings existing user' test was failing as it was referring to a game type that is known but not seeded in the test db. --- test/support/teiserver_test_lib.ex | 7 +++---- .../controllers/api/spads_controller_test.exs | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/test/support/teiserver_test_lib.ex b/test/support/teiserver_test_lib.ex index 59d3e99cc..86ef591ae 100644 --- a/test/support/teiserver_test_lib.ex +++ b/test/support/teiserver_test_lib.ex @@ -527,10 +527,9 @@ defmodule Teiserver.TeiserverTestLib do Teiserver.Account.get_or_add_smurf_key_type("hw2") Teiserver.Account.get_or_add_smurf_key_type("hw3") - Teiserver.Game.get_or_add_rating_type("Duel") - Teiserver.Game.get_or_add_rating_type("Small Team") - Teiserver.Game.get_or_add_rating_type("Large Team") - Teiserver.Game.get_or_add_rating_type("FFA") + Enum.each(Teiserver.Game.MatchRatingLib.rating_type_list(), fn rating_type -> + Teiserver.Game.get_or_add_rating_type(rating_type) + end) Teiserver.Telemetry.get_or_add_complex_server_event_type("Server startup") Teiserver.Telemetry.get_or_add_simple_server_event_type("account.user_login") diff --git a/test/teiserver_web/controllers/api/spads_controller_test.exs b/test/teiserver_web/controllers/api/spads_controller_test.exs index 60d400c37..c85420bfd 100644 --- a/test/teiserver_web/controllers/api/spads_controller_test.exs +++ b/test/teiserver_web/controllers/api/spads_controller_test.exs @@ -34,7 +34,6 @@ defmodule TeiserverWeb.API.SpadsControllerTest do assert data == %{"rating_value" => 16.67, "uncertainty" => 8.33} end - @tag :needs_attention test "existing user", %{conn: conn} do user = new_user() rating_type_id = MatchRatingLib.rating_type_name_lookup()["Team"] From 091768b2b1412ef88f48e7cf711423ff265f245c Mon Sep 17 00:00:00 2001 From: bigbluejay9 <2730943+bigbluejay9@users.noreply.github.com> Date: Sun, 6 Oct 2024 16:04:59 +0700 Subject: [PATCH 2/4] Fix default rating value --- test/teiserver_web/controllers/api/spads_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/teiserver_web/controllers/api/spads_controller_test.exs b/test/teiserver_web/controllers/api/spads_controller_test.exs index c85420bfd..2b41f21ee 100644 --- a/test/teiserver_web/controllers/api/spads_controller_test.exs +++ b/test/teiserver_web/controllers/api/spads_controller_test.exs @@ -53,7 +53,7 @@ defmodule TeiserverWeb.API.SpadsControllerTest do response = response(conn, 200) data = Jason.decode!(response) - assert data == %{"rating_value" => 20, "uncertainty" => 5} + assert data == %{"rating_value" => 16.67, "uncertainty" => 8.33} end end From f7814d2d4c333f0755f4ca408eda78e3f7b0d7a0 Mon Sep 17 00:00:00 2001 From: bigbluejay9 <2730943+bigbluejay9@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:29:02 +0700 Subject: [PATCH 3/4] Authorize test user to get rating --- .../controllers/api/spads_controller_test.exs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/teiserver_web/controllers/api/spads_controller_test.exs b/test/teiserver_web/controllers/api/spads_controller_test.exs index 2b41f21ee..5f8d5752c 100644 --- a/test/teiserver_web/controllers/api/spads_controller_test.exs +++ b/test/teiserver_web/controllers/api/spads_controller_test.exs @@ -5,11 +5,13 @@ defmodule TeiserverWeb.API.SpadsControllerTest do alias Teiserver.Game.MatchRatingLib alias Teiserver.Coordinator alias Teiserver.Account.ClientLib + alias Teiserver.Client import Teiserver.TeiserverTestLib, only: [ new_user: 0, - new_user: 1 + new_user: 1, + make_lobby: 1 ] defp make_rating(userid, rating_type_id, rating_value) do @@ -49,11 +51,16 @@ defmodule TeiserverWeb.API.SpadsControllerTest do last_updated: Timex.now() }) + Client.login(user, :spring, "127.0.0.1") + lobby_id = + make_lobby(%{name: "Test", founder_id: user.id, founder_name: user.name}) + Client.join_battle(user.id, lobby_id, true) + conn = get(conn, Routes.ts_spads_path(conn, :get_rating, user.id, "Team")) response = response(conn, 200) data = Jason.decode!(response) - assert data == %{"rating_value" => 16.67, "uncertainty" => 8.33} + assert data == %{"rating_value" => 20, "uncertainty" => 5} end end From 0f221dcd6bd71039d4f574e10bd0d0de3725fc88 Mon Sep 17 00:00:00 2001 From: bigbluejay9 <2730943+bigbluejay9@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:34:49 +0700 Subject: [PATCH 4/4] Mix format --- test/teiserver_web/controllers/api/spads_controller_test.exs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/teiserver_web/controllers/api/spads_controller_test.exs b/test/teiserver_web/controllers/api/spads_controller_test.exs index 5f8d5752c..9e432862d 100644 --- a/test/teiserver_web/controllers/api/spads_controller_test.exs +++ b/test/teiserver_web/controllers/api/spads_controller_test.exs @@ -52,8 +52,10 @@ defmodule TeiserverWeb.API.SpadsControllerTest do }) Client.login(user, :spring, "127.0.0.1") + lobby_id = make_lobby(%{name: "Test", founder_id: user.id, founder_name: user.name}) + Client.join_battle(user.id, lobby_id, true) conn = get(conn, Routes.ts_spads_path(conn, :get_rating, user.id, "Team"))