Skip to content

Commit

Permalink
Seed test db will all possible game types. (#501)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bigbluejay9 authored Oct 18, 2024
1 parent 295a5be commit d5591f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 3 additions & 4 deletions test/support/teiserver_test_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 10 additions & 2 deletions test/teiserver_web/controllers/api/spads_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand All @@ -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)
Expand Down

0 comments on commit d5591f1

Please sign in to comment.