Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1756,4 +1756,58 @@ public async Task TestUserRankingWhenBothUsersHaveSamePpAndUserBSubmitsHigherPpM
Assert.Equal(1, userStatsAFinal!.BestGlobalRank);
Assert.Equal(1, userStatsBFinal!.BestGlobalRank);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task TestMedalNotAwardedWithDifficultyReducingMods(bool hasNonEligibleMod)
{
// Arrange
var scoreService = Scope.ServiceProvider.GetRequiredService<Server.Services.ScoreService>();

var (session, user) = await CreateTestSession();

var (replay, beatmapId) = GetValidTestReplay();

var score = replay.GetScore();
score.BeatmapId = beatmapId;
score.GameMode = GameMode.Standard;
score.Mods = hasNonEligibleMod ? Mods.HalfTime : Mods.None;

score.EnrichWithSessionData(session);

var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet();
var beatmap = beatmapSet.Beatmaps.First() ?? throw new Exception("Beatmap is null");
beatmap.EnrichWithScoreData(score);
beatmap.DifficultyRating = 1.5;

await _mocker.Beatmap.MockBeatmapSet(beatmapSet);

// Act
var resultString = await scoreService.SubmitScore(
session,
score.ToScoreString(user.Username),
score.BeatmapHash,
_mocker.GetRandomInteger(),
_mocker.GetRandomInteger(),
_mocker.GetRandomString(),
session.Attributes.UserHash,
_replayService.GenerateReplayFormFile(),
null
);

// Assert
Assert.DoesNotContain("error", resultString);

var userUnlockedMedals = await Database.Users.Medals.GetUserMedals(session.UserId);

if (hasNonEligibleMod)
{
Assert.DoesNotContain(userUnlockedMedals, m => m.MedalId == 1);
}
else
{
Assert.Contains(userUnlockedMedals, m => m.MedalId == 1);
}
}
}
5 changes: 3 additions & 2 deletions Sunrise.Shared/Database/Seeders/MedalSeeder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using osu.Shared;
using Sunrise.Shared.Database.Models;
using Sunrise.Shared.Database.Models.Users;
Expand All @@ -10,9 +10,9 @@

public class MedalConditionContext
{
public UserStats user { get; set; }

Check warning on line 13 in Sunrise.Shared/Database/Seeders/MedalSeeder.cs

View workflow job for this annotation

GitHub Actions / Test Group 10

Non-nullable property 'user' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public Score score { get; set; }

Check warning on line 14 in Sunrise.Shared/Database/Seeders/MedalSeeder.cs

View workflow job for this annotation

GitHub Actions / Test Group 10

Non-nullable property 'score' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public Beatmap beatmap { get; set; }

Check warning on line 15 in Sunrise.Shared/Database/Seeders/MedalSeeder.cs

View workflow job for this annotation

GitHub Actions / Test Group 10

Non-nullable property 'beatmap' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

public static class MedalSeeder
Expand Down Expand Up @@ -98,7 +98,8 @@

private static string FormatDifficultyRatingPassCondition(int difficultyRating)
{
return $"{nameof(MedalConditionContext.beatmap)}.{nameof(Beatmap.DifficultyRating)} >= {difficultyRating} && {nameof(MedalConditionContext.beatmap)}.{nameof(Beatmap.DifficultyRating)} < {difficultyRating + 1}";
var noReducingMods = (int)(Mods.Easy | Mods.NoFail | Mods.HalfTime);
return $"{nameof(MedalConditionContext.beatmap)}.{nameof(Beatmap.DifficultyRating)} >= {difficultyRating} && {nameof(MedalConditionContext.beatmap)}.{nameof(Beatmap.DifficultyRating)} < {difficultyRating + 1} && ({nameof(MedalConditionContext.score)}.{nameof(Score.Mods)} & {noReducingMods}) == 0";
}

private static string FormatDifficultyRatingFullComboCondition(int difficultyRating)
Expand Down
Loading