From d5591f1993b1c2cca612f761ca27784afb0f7e49 Mon Sep 17 00:00:00 2001 From: bigbluejay9 <2730943+bigbluejay9@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:09:11 +0800 Subject: [PATCH] Seed test db will all possible game types. (#501) * 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. * Fix default rating value * Authorize test user to get rating * Mix format --- test/support/teiserver_test_lib.ex | 7 +++---- .../controllers/api/spads_controller_test.exs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 6 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..9e432862d 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 @@ -34,7 +36,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"] @@ -50,6 +51,13 @@ 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)