Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lotuuu committed May 14, 2024
1 parent aa338d7 commit 51a2990
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
7 changes: 7 additions & 0 deletions apps/game_backend/lib/game_backend/campaigns.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 29 additions & 8 deletions apps/gateway/test/champions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 51a2990

Please sign in to comment.