diff --git a/apps/game_backend/lib/game_backend/campaigns.ex b/apps/game_backend/lib/game_backend/campaigns.ex index 190722ebb..ce42a3eeb 100644 --- a/apps/game_backend/lib/game_backend/campaigns.ex +++ b/apps/game_backend/lib/game_backend/campaigns.ex @@ -108,6 +108,13 @@ defmodule GameBackend.Campaigns do Repo.get(SuperCampaign, super_campaign_id) end + @doc """ + Get a super campaign by name and game_id. + """ + def get_super_campaign_by_name_and_game(name, game_id) do + Repo.get_by(SuperCampaign, name: name, game_id: game_id) + end + @doc """ Get a campaign progress by user id and campaign id. Returns `{:error, :not_found}` if no progress is found. diff --git a/apps/gateway/test/champions_test.exs b/apps/gateway/test/champions_test.exs index 5883765ad..7e73662e8 100644 --- a/apps/gateway/test/champions_test.exs +++ b/apps/gateway/test/champions_test.exs @@ -328,8 +328,15 @@ defmodule Gateway.Test.Champions do # Register user {:ok, user} = Users.register("battle_user") - # Get user's first SuperCampaignProgress - [super_campaign_progress | _] = user.super_campaign_progresses + # Get user's Main Campaign progress + main_super_campaign = + GameBackend.Campaigns.get_super_campaign_by_name_and_game( + "Main Campaign", + Utils.get_game_id(:champions_of_mirra) + ) + + {:ok, super_campaign_progress} = + GameBackend.Campaigns.get_super_campaign_progress(user.id, main_super_campaign.id) # Get the SuperCampaignProgress' Level level_id = super_campaign_progress.level_id @@ -357,8 +364,15 @@ defmodule Gateway.Test.Champions do GameBackend.Units.update_unit(unit, %{level: 9999}) end) - # Get user's first SuperCampaignProgress - [super_campaign_progress | _] = user.super_campaign_progresses + # Get user's progress in the main SuperCampaign + main_super_campaign = + GameBackend.Campaigns.get_super_campaign_by_name_and_game( + "Main Campaign", + Utils.get_game_id(:champions_of_mirra) + ) + + {:ok, super_campaign_progress} = + GameBackend.Campaigns.get_super_campaign_progress(user.id, main_super_campaign.id) # Get the SuperCampaignProgress' Level level_id = super_campaign_progress.level_id @@ -376,7 +390,8 @@ defmodule Gateway.Test.Champions do {:ok, advanced_user} = Users.get_user(user.id) - [advanced_super_campaign_progress | _] = advanced_user.super_campaign_progresses + {:ok, advanced_super_campaign_progress} = + GameBackend.Campaigns.get_super_campaign_progress(user.id, main_super_campaign.id) assert user.id == advanced_user.id assert advanced_super_campaign_progress.level_id != level_id @@ -389,10 +404,16 @@ defmodule Gateway.Test.Champions do # Register user {:ok, user} = Users.register("invalid_battle_user") - # Get user's first SuperCampaignProgress - [super_campaign_progress | _] = user.super_campaign_progresses + # Get user's Main Campaign progress + main_super_campaign = + GameBackend.Campaigns.get_super_campaign_by_name_and_game( + "Main Campaign", + Utils.get_game_id(:champions_of_mirra) + ) + + {:ok, super_campaign_progress} = + GameBackend.Campaigns.get_super_campaign_progress(user.id, main_super_campaign.id) - # Get the level of the SuperCampaignProgress next_level_id = super_campaign_progress.level_id # Get a Level that is not the next one in the SuperCampaignProgress