From 1ef83fa9370c859e4859d8937856380b7a770e65 Mon Sep 17 00:00:00 2001 From: richardscull <106016833+richardscull@users.noreply.github.com> Date: Sun, 1 Feb 2026 18:07:55 +0200 Subject: [PATCH 1/2] feat: Add ability to setup eligible beatmap statuses for hype --- Sunrise.API/Controllers/BeatmapController.cs | 2 +- Sunrise.Server/appsettings.Development.json | 10 ++++++++-- Sunrise.Shared/Application/Configuration.cs | 11 +++++++++++ .../Database/Services/Beatmaps/BeatmapHypeService.cs | 10 +++++++--- .../Extensions/Beatmaps/BeatmapStatusExtensions.cs | 6 ++++++ Sunrise.Shared/Objects/Serializable/BeatmapSet.cs | 2 +- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Sunrise.API/Controllers/BeatmapController.cs b/Sunrise.API/Controllers/BeatmapController.cs index a8dffdfa..05cb862f 100644 --- a/Sunrise.API/Controllers/BeatmapController.cs +++ b/Sunrise.API/Controllers/BeatmapController.cs @@ -182,7 +182,7 @@ public async Task HypeBeatmapSet([Range(1, int.MaxValue)] int id, var user = HttpContext.GetCurrentUserOrThrow(); - var hypeBeatmapSetResult = await database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSet.Id); + var hypeBeatmapSetResult = await database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSet.Id, beatmapSet.StatusGeneric); if (hypeBeatmapSetResult.IsFailure) return Problem(hypeBeatmapSetResult.Error, statusCode: StatusCodes.Status400BadRequest); diff --git a/Sunrise.Server/appsettings.Development.json b/Sunrise.Server/appsettings.Development.json index 565f661a..32bf519f 100644 --- a/Sunrise.Server/appsettings.Development.json +++ b/Sunrise.Server/appsettings.Development.json @@ -17,8 +17,14 @@ }, "BeatmapHype": { "UserHypesWeekly": 10, - "HypesToStartHypeTrain": 2, - "AllowMultipleHypeFromSameUser": false + "HypesToStartHypeTrain": 1, + "AllowMultipleHypeFromSameUser": false, + "ExcludedHypeStatuses": [ + "Ranked", + "Approved", + "Qualified", + "Loved" + ] }, "Moderation": { "BannablePPThreshold": 2500, diff --git a/Sunrise.Shared/Application/Configuration.cs b/Sunrise.Shared/Application/Configuration.cs index 829937be..e272e01e 100644 --- a/Sunrise.Shared/Application/Configuration.cs +++ b/Sunrise.Shared/Application/Configuration.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.IdentityModel.Tokens; using Sunrise.Shared.Enums; +using Sunrise.Shared.Enums.Beatmaps; using Sunrise.Shared.Extensions; using Sunrise.Shared.Objects; @@ -146,6 +147,16 @@ public static string WebTokenSecret public static bool AllowMultipleHypeFromSameUser => Config.GetSection("BeatmapHype").GetValue("AllowMultipleHypeFromSameUser") ?? true; + public static BeatmapStatusWeb[] ExcludedHypeStatuses => + Config.GetSection("BeatmapHype").GetSection("ExcludedHypeStatuses").Get()?.Select(x => + { + var isValid = Enum.TryParse(x, out BeatmapStatusWeb status); + if (!isValid) + throw new Exception($"Invalid beatmap status in ExcludedHypeStatuses: {x}. Should be one of the following: {string.Join(", ", Enum.GetNames(typeof(BeatmapStatusWeb)))}"); + + return status; + }).ToArray() ?? + [BeatmapStatusWeb.Qualified, BeatmapStatusWeb.Approved, BeatmapStatusWeb.Ranked, BeatmapStatusWeb.Loved]; // Telemetry section public static bool UseMetrics => Config.GetSection("Telemetry").GetValue("UseMetrics") ?? true; diff --git a/Sunrise.Shared/Database/Services/Beatmaps/BeatmapHypeService.cs b/Sunrise.Shared/Database/Services/Beatmaps/BeatmapHypeService.cs index cd59ec0f..9f1cd234 100644 --- a/Sunrise.Shared/Database/Services/Beatmaps/BeatmapHypeService.cs +++ b/Sunrise.Shared/Database/Services/Beatmaps/BeatmapHypeService.cs @@ -1,4 +1,4 @@ -using CSharpFunctionalExtensions; +using CSharpFunctionalExtensions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Sunrise.Shared.Application; @@ -11,6 +11,7 @@ using Sunrise.Shared.Database.Services.Users; using Sunrise.Shared.Enums; using Sunrise.Shared.Enums.Beatmaps; +using Sunrise.Shared.Extensions.Beatmaps; using Sunrise.Shared.Utils; namespace Sunrise.Shared.Database.Services.Beatmaps; @@ -23,10 +24,13 @@ public class BeatmapHypeService( BeatmapEventService beatmapEventService ) { - public async Task AddBeatmapHypeFromUserInventory(User user, int beatmapSetId) + public async Task AddBeatmapHypeFromUserInventory(User user, int beatmapSetId, BeatmapStatusWeb beatmapStatus) { return await databaseService.Value.CommitAsTransactionAsync(async () => { + if (!beatmapStatus.IsEligibleForHype()) + throw new ApplicationException($"You can't hype beatmapset with status '{beatmapStatus}'"); + var beatmapsetCustomStatuses = await databaseService.Value.Beatmaps.CustomStatuses.GetCustomBeatmapSetStatuses(beatmapSetId); if (beatmapsetCustomStatuses.Any()) throw new ApplicationException("You can't hype beatmapset with custom beatmap status"); @@ -49,7 +53,7 @@ public async Task AddBeatmapHypeFromUserInventory(User user, int beatmap { throw new ApplicationException("You already hyped this beatmap set"); } - + userBeatmapHype.Hypes += 1; } diff --git a/Sunrise.Shared/Extensions/Beatmaps/BeatmapStatusExtensions.cs b/Sunrise.Shared/Extensions/Beatmaps/BeatmapStatusExtensions.cs index 719808ea..88fe6aa0 100644 --- a/Sunrise.Shared/Extensions/Beatmaps/BeatmapStatusExtensions.cs +++ b/Sunrise.Shared/Extensions/Beatmaps/BeatmapStatusExtensions.cs @@ -1,3 +1,4 @@ +using Sunrise.Shared.Application; using Sunrise.Shared.Enums.Beatmaps; namespace Sunrise.Shared.Extensions.Beatmaps; @@ -81,4 +82,9 @@ public static bool IsScoreable(this BeatmapStatusWeb status) { return status is BeatmapStatusWeb.Ranked or BeatmapStatusWeb.Approved or BeatmapStatusWeb.Loved or BeatmapStatusWeb.Qualified; } + + public static bool IsEligibleForHype(this BeatmapStatusWeb status) + { + return Configuration.ExcludedHypeStatuses.All(s => s != status); + } } \ No newline at end of file diff --git a/Sunrise.Shared/Objects/Serializable/BeatmapSet.cs b/Sunrise.Shared/Objects/Serializable/BeatmapSet.cs index e2ccb368..0d9cd5bf 100644 --- a/Sunrise.Shared/Objects/Serializable/BeatmapSet.cs +++ b/Sunrise.Shared/Objects/Serializable/BeatmapSet.cs @@ -125,7 +125,7 @@ public class BeatmapSet public CompactUser? User { get; set; } public User? BeatmapNominatorUser { get; set; } - public bool CanBeHyped => BeatmapNominatorUser == null && !IsScoreable; + public bool CanBeHyped => BeatmapNominatorUser == null && StatusGeneric.IsEligibleForHype(); } public class Covers From af869860680042c5d437982afbfadc7caf25e3ac Mon Sep 17 00:00:00 2001 From: richardscull <106016833+richardscull@users.noreply.github.com> Date: Sun, 1 Feb 2026 18:08:02 +0200 Subject: [PATCH 2/2] feat: add tests --- .../ApiAddBeatmapSetHypeTests.cs | 141 +++++++++++++++++- .../BeatmapController/ApiBeatmapSetTests.cs | 31 +++- .../ApiGetBeatmapSetHypeTests.cs | 7 +- .../ApiGetHypedBeatmapSetsTests.cs | 15 +- .../ApiUpdateBeatmapCustomStatusTests.cs | 21 ++- .../Manager/EnvironmentVariableManager.cs | 26 ++++ 6 files changed, 224 insertions(+), 17 deletions(-) diff --git a/Sunrise.Server.Tests/API/BeatmapController/ApiAddBeatmapSetHypeTests.cs b/Sunrise.Server.Tests/API/BeatmapController/ApiAddBeatmapSetHypeTests.cs index 4ab51da4..848fa405 100644 --- a/Sunrise.Server.Tests/API/BeatmapController/ApiAddBeatmapSetHypeTests.cs +++ b/Sunrise.Server.Tests/API/BeatmapController/ApiAddBeatmapSetHypeTests.cs @@ -5,11 +5,11 @@ using Sunrise.Shared.Enums; using Sunrise.Shared.Enums.Beatmaps; using Sunrise.Shared.Enums.Users; +using Sunrise.Shared.Extensions.Beatmaps; using Sunrise.Tests.Abstracts; using Sunrise.Tests.Extensions; using Sunrise.Tests.Services.Mock; using Sunrise.Tests.Utils; -using Sunrise.Tests; namespace Sunrise.Server.Tests.API.BeatmapController; @@ -17,7 +17,7 @@ namespace Sunrise.Server.Tests.API.BeatmapController; public class ApiAddBeatmapSetHypeTests(IntegrationDatabaseFixture fixture) : ApiTest(fixture) { private readonly MockService _mocker = new(); - + [Theory] [InlineData(true)] [InlineData(false)] @@ -32,6 +32,12 @@ public async Task TestAddBeatmapSetHype(bool shouldFillHypeTrain) var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet(); beatmapSet.Id = 1; + beatmapSet.StatusString = BeatmapStatusWeb.Graveyard.BeatmapStatusWebToString(); + + foreach (var beatmap in beatmapSet.Beatmaps) + { + beatmap.StatusString = beatmapSet.StatusString; + } await _mocker.Beatmap.MockBeatmapSet(beatmapSet); @@ -75,12 +81,18 @@ public async Task TestAddBeatmapSetHypeCantHypeIfNoMultipleHypeIsEnabled(bool is var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet(); beatmapSet.Id = 1; + beatmapSet.StatusString = BeatmapStatusWeb.Graveyard.BeatmapStatusWebToString(); + + foreach (var beatmap in beatmapSet.Beatmaps) + { + beatmap.StatusString = beatmapSet.StatusString; + } await _mocker.Beatmap.MockBeatmapSet(beatmapSet); EnvManager.Set("BeatmapHype:AllowMultipleHypeFromSameUser", isMultipleHypeEnabled ? "true" : "false"); - var addBeatmapHypeBeforeResult = await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSet.Id); + var addBeatmapHypeBeforeResult = await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSet.Id, beatmapSet.StatusGeneric); if (addBeatmapHypeBeforeResult.IsFailure) throw new Exception(addBeatmapHypeBeforeResult.Error); @@ -122,6 +134,12 @@ public async Task TestAddBeatmapSetHypeCantHypeIfUserDoesntHasHypes() var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet(); beatmapSet.Id = 1; + beatmapSet.StatusString = BeatmapStatusWeb.Graveyard.BeatmapStatusWebToString(); + + foreach (var beatmap in beatmapSet.Beatmaps) + { + beatmap.StatusString = beatmapSet.StatusString; + } await _mocker.Beatmap.MockBeatmapSet(beatmapSet); @@ -152,6 +170,12 @@ public async Task TestAddBeatmapSetHypeCantHypeIfBeatmapSetHasCustomStatus() var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet(); beatmapSet.Id = 1; + beatmapSet.StatusString = BeatmapStatusWeb.Graveyard.BeatmapStatusWebToString(); + + foreach (var beatmap in beatmapSet.Beatmaps) + { + beatmap.StatusString = beatmapSet.StatusString; + } await _mocker.Beatmap.MockBeatmapSet(beatmapSet); @@ -179,7 +203,7 @@ await Database.Beatmaps.CustomStatuses.AddCustomBeatmapStatus(new CustomBeatmapS Assert.NotNull(userHypes); Assert.Equal(userHypes.Quantity, Configuration.UserHypesWeekly); } - + [Fact] public async Task TestAddBeatmapSetHypeUnauthorized() { @@ -227,4 +251,113 @@ public async Task TestAddBeatmapSetHypeNotFound() // Assert Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } + + [Fact] + public async Task TestAddBeatmapSetHypeCantHypeExcludedStatuses() + { + // Arrange + var client = App.CreateClient().UseClient("api"); + + var excludedStatus = BeatmapStatusWeb.Pending; + + EnvManager.Set("General:IgnoreBeatmapRanking", "false"); + + EnvManager.Set("BeatmapHype:ExcludedHypeStatuses", + [excludedStatus.ToString()]); + + var user = await CreateTestUser(); + var tokens = await GetUserAuthTokens(user); + client.UseUserAuthToken(tokens); + + var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet(); + beatmapSet.Id = 1; + beatmapSet.StatusString = excludedStatus.BeatmapStatusWebToString(); + + await _mocker.Beatmap.MockBeatmapSet(beatmapSet); + + // Act + var response = await client.PostAsync("beatmapset/1/hype", new StringContent(string.Empty)); + + // Assert + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); + + var responseString = await response.Content.ReadFromJsonAsyncWithAppConfig(); + Assert.Contains("can't hype", responseString?.Detail?.ToLower()); + + var beatmapHypeCount = await Database.Beatmaps.Hypes.GetBeatmapHypeCount(beatmapSet.Id); + Assert.Equal(0, beatmapHypeCount); + + var userHypes = await Database.Users.Inventory.GetInventoryItem(user.Id, ItemType.Hype); + Assert.NotNull(userHypes); + Assert.Equal(userHypes.Quantity, Configuration.UserHypesWeekly); + } + + [Fact] + public async Task TestAddBeatmapSetHypeCanHypeNonExcludedStatuses() + { + // Arrange + var client = App.CreateClient().UseClient("api"); + + EnvManager.Set("General:IgnoreBeatmapRanking", "false"); + + var user = await CreateTestUser(); + var tokens = await GetUserAuthTokens(user); + client.UseUserAuthToken(tokens); + + var allowedStatus = BeatmapStatusWeb.Graveyard; + + var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet(); + beatmapSet.Id = 1; + beatmapSet.StatusString = allowedStatus.BeatmapStatusWebToString(); + + await _mocker.Beatmap.MockBeatmapSet(beatmapSet); + + // Act + var response = await client.PostAsync("beatmapset/1/hype", new StringContent(string.Empty)); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + var beatmapHypeCount = await Database.Beatmaps.Hypes.GetBeatmapHypeCount(beatmapSet.Id); + Assert.Equal(1, beatmapHypeCount); + + var userHypes = await Database.Users.Inventory.GetInventoryItem(user.Id, ItemType.Hype); + Assert.NotNull(userHypes); + Assert.Equal(userHypes.Quantity, Configuration.UserHypesWeekly - 1); + } + + [Fact] + public async Task TestAddBeatmapSetHypeOverridesDefault() + { + // Arrange + var client = App.CreateClient().UseClient("api"); + + EnvManager.Set("General:IgnoreBeatmapRanking", "false"); + EnvManager.Set("BeatmapHype:ExcludedHypeStatuses", [BeatmapStatusWeb.Qualified.ToString()]); + + var user = await CreateTestUser(); + var tokens = await GetUserAuthTokens(user); + client.UseUserAuthToken(tokens); + + var allowedStatus = BeatmapStatusWeb.Ranked; + + var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet(); + beatmapSet.Id = 1; + beatmapSet.StatusString = allowedStatus.BeatmapStatusWebToString(); + + await _mocker.Beatmap.MockBeatmapSet(beatmapSet); + + // Act + var response = await client.PostAsync("beatmapset/1/hype", new StringContent(string.Empty)); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + var beatmapHypeCount = await Database.Beatmaps.Hypes.GetBeatmapHypeCount(beatmapSet.Id); + Assert.Equal(1, beatmapHypeCount); + + var userHypes = await Database.Users.Inventory.GetInventoryItem(user.Id, ItemType.Hype); + Assert.NotNull(userHypes); + Assert.Equal(userHypes.Quantity, Configuration.UserHypesWeekly - 1); + } } \ No newline at end of file diff --git a/Sunrise.Server.Tests/API/BeatmapController/ApiBeatmapSetTests.cs b/Sunrise.Server.Tests/API/BeatmapController/ApiBeatmapSetTests.cs index 1ef341d4..28ad8431 100644 --- a/Sunrise.Server.Tests/API/BeatmapController/ApiBeatmapSetTests.cs +++ b/Sunrise.Server.Tests/API/BeatmapController/ApiBeatmapSetTests.cs @@ -1,9 +1,10 @@ -using System.Net; +using System.Net; using System.Net.Http.Json; using Sunrise.API.Serializable.Request; using Sunrise.API.Serializable.Response; using Sunrise.Shared.Database.Models.Beatmap; using Sunrise.Shared.Enums.Beatmaps; +using Sunrise.Shared.Extensions.Beatmaps; using Sunrise.Tests.Abstracts; using Sunrise.Tests.Extensions; using Sunrise.Tests.Services.Mock; @@ -169,4 +170,32 @@ public async Task TestGetBeatmapSetNotFound() // Assert Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } + + [Theory] + [InlineData(BeatmapStatusWeb.Graveyard, true)] + [InlineData(BeatmapStatusWeb.Ranked, false)] + public async Task TestGetBeatmapSetCanBeHypedBasedOnExcludedStatuses(BeatmapStatusWeb status, bool expectedCanBeHyped) + { + // Arrange + var client = App.CreateClient().UseClient("api"); + + EnvManager.Set("General:IgnoreBeatmapRanking", "false"); + + var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet(); + beatmapSet.Id = 1; + beatmapSet.StatusString = status.BeatmapStatusWebToString(); + + await _mocker.Beatmap.MockBeatmapSet(beatmapSet); + + // Act + var response = await client.GetAsync("beatmapset/1"); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + var beatmapSetResponse = await response.Content.ReadFromJsonAsyncWithAppConfig(); + Assert.NotNull(beatmapSetResponse); + Assert.Equal(status, beatmapSetResponse.Status); + Assert.Equal(expectedCanBeHyped, beatmapSetResponse.CanBeHyped); + } } \ No newline at end of file diff --git a/Sunrise.Server.Tests/API/BeatmapController/ApiGetBeatmapSetHypeTests.cs b/Sunrise.Server.Tests/API/BeatmapController/ApiGetBeatmapSetHypeTests.cs index 20f7c437..043131c7 100644 --- a/Sunrise.Server.Tests/API/BeatmapController/ApiGetBeatmapSetHypeTests.cs +++ b/Sunrise.Server.Tests/API/BeatmapController/ApiGetBeatmapSetHypeTests.cs @@ -1,11 +1,10 @@ -using System.Net; +using System.Net; using Sunrise.API.Serializable.Response; using Sunrise.Shared.Application; using Sunrise.Tests.Abstracts; using Sunrise.Tests.Extensions; using Sunrise.Tests.Services.Mock; using Sunrise.Tests.Utils; -using Sunrise.Tests; namespace Sunrise.Server.Tests.API.BeatmapController; @@ -30,7 +29,7 @@ public async Task TestGetBeatmapSetHype(bool shouldHypeBefore) if (shouldHypeBefore) { var user = await CreateTestUser(); - var addBeatmapHypeResult = await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSet.Id); + var addBeatmapHypeResult = await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSet.Id, beatmapSet.StatusGeneric); if (addBeatmapHypeResult.IsFailure) throw new Exception(addBeatmapHypeResult.Error); } @@ -47,7 +46,7 @@ public async Task TestGetBeatmapSetHype(bool shouldHypeBefore) Assert.Equal(shouldHypeBefore ? 1 : 0, content.CurrentHypes); Assert.Equal(Configuration.HypesToStartHypeTrain, content.RequiredHypes); } - + [Theory] [InlineData("-1")] public async Task TestGetBeatmapSetHypeInvalidBeatmapSetId(string beatmapSetId) diff --git a/Sunrise.Server.Tests/API/BeatmapController/ApiGetHypedBeatmapSetsTests.cs b/Sunrise.Server.Tests/API/BeatmapController/ApiGetHypedBeatmapSetsTests.cs index f06535e7..d7c06d4d 100644 --- a/Sunrise.Server.Tests/API/BeatmapController/ApiGetHypedBeatmapSetsTests.cs +++ b/Sunrise.Server.Tests/API/BeatmapController/ApiGetHypedBeatmapSetsTests.cs @@ -1,11 +1,12 @@ -using System.Net; +using System.Net; using Sunrise.API.Serializable.Response; +using Sunrise.Shared.Enums.Beatmaps; using Sunrise.Shared.Enums.Users; +using Sunrise.Shared.Extensions.Beatmaps; using Sunrise.Tests.Abstracts; using Sunrise.Tests.Extensions; using Sunrise.Tests.Services.Mock; using Sunrise.Tests.Utils; -using Sunrise.Tests; namespace Sunrise.Server.Tests.API.BeatmapController; @@ -62,7 +63,7 @@ public async Task TestGetHypedBeatmapSets(bool shouldAddedHypeStartHypeTrain) EnvManager.Set("BeatmapHype:HypesToStartHypeTrain", shouldAddedHypeStartHypeTrain ? "1" : "100"); - await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSet.Id); + await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSet.Id, beatmapSet.StatusGeneric); // Act var response = await client.GetAsync("beatmapset/get-hyped-sets"); @@ -97,15 +98,17 @@ public async Task TestGetHypedBeatmapSetsTestPageAndLimit() var beatmapSetFirst = _mocker.Beatmap.GetRandomBeatmapSet(); beatmapSetFirst.Id = 1; + beatmapSetFirst.StatusString = BeatmapStatusWeb.Graveyard.BeatmapStatusWebToString(); await _mocker.Beatmap.MockBeatmapSet(beatmapSetFirst); - await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSetFirst.Id); + await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSetFirst.Id, beatmapSetFirst.StatusGeneric); var beatmapSetSecond = _mocker.Beatmap.GetRandomBeatmapSet(); beatmapSetSecond.Id = 2; + beatmapSetSecond.StatusString = BeatmapStatusWeb.Graveyard.BeatmapStatusWebToString(); await _mocker.Beatmap.MockBeatmapSet(beatmapSetSecond); - await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSetSecond.Id); + await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSetSecond.Id, beatmapSetSecond.StatusGeneric); // Act var response = await client.GetAsync("beatmapset/get-hyped-sets?limit=1&page=2"); @@ -120,7 +123,7 @@ public async Task TestGetHypedBeatmapSetsTestPageAndLimit() Assert.Equal(2, content.TotalCount); Assert.Equal(beatmapSetFirst.Id, content.Sets.First().Id); } - + [Fact] public async Task TestGetHypedBeatmapSetsUnauthorized() { diff --git a/Sunrise.Server.Tests/API/BeatmapController/ApiUpdateBeatmapCustomStatusTests.cs b/Sunrise.Server.Tests/API/BeatmapController/ApiUpdateBeatmapCustomStatusTests.cs index e3ae8b6f..f348a34f 100644 --- a/Sunrise.Server.Tests/API/BeatmapController/ApiUpdateBeatmapCustomStatusTests.cs +++ b/Sunrise.Server.Tests/API/BeatmapController/ApiUpdateBeatmapCustomStatusTests.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; using System.Net.Http.Json; using System.Text; using Sunrise.API.Serializable.Request; @@ -8,6 +8,7 @@ using Sunrise.Shared.Enums; using Sunrise.Shared.Enums.Beatmaps; using Sunrise.Shared.Enums.Users; +using Sunrise.Shared.Extensions.Beatmaps; using Sunrise.Tests.Abstracts; using Sunrise.Tests.Extensions; using Sunrise.Tests.Services.Mock; @@ -42,12 +43,17 @@ public async Task TestUpdateBeatmapCustomStatus(bool hadCustomStatusBefore, bool var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet(); var beatmap = beatmapSet.Beatmaps.First(); + beatmapSet.StatusString = BeatmapStatusWeb.Graveyard.BeatmapStatusWebToString(); + foreach (var b in beatmapSet.Beatmaps) + { + b.StatusString = beatmapSet.StatusString; + } await _mocker.Beatmap.MockBeatmapSet(beatmapSet); if (wasHypedBefore) { - var addBeatmapHypeResult = await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSet.Id); + var addBeatmapHypeResult = await Database.Beatmaps.Hypes.AddBeatmapHypeFromUserInventory(user, beatmapSet.Id, beatmapSet.StatusGeneric); if (addBeatmapHypeResult.IsFailure) throw new Exception(addBeatmapHypeResult.Error); } @@ -113,10 +119,20 @@ public async Task TestUpdateBeatmapCustomStatusWithMultipleIds() var beatmapSetFirst = _mocker.Beatmap.GetRandomBeatmapSet(); var beatmapFirst = beatmapSetFirst.Beatmaps.First(); + beatmapSetFirst.StatusString = BeatmapStatusWeb.Graveyard.BeatmapStatusWebToString(); + foreach (var b in beatmapSetFirst.Beatmaps) + { + b.StatusString = beatmapSetFirst.StatusString; + } await _mocker.Beatmap.MockBeatmapSet(beatmapSetFirst); var beatmapSetSecond = _mocker.Beatmap.GetRandomBeatmapSet(); var beatmapSecond = beatmapSetSecond.Beatmaps.First(); + beatmapSetSecond.StatusString = BeatmapStatusWeb.Graveyard.BeatmapStatusWebToString(); + foreach (var b in beatmapSetSecond.Beatmaps) + { + b.StatusString = beatmapSetSecond.StatusString; + } await _mocker.Beatmap.MockBeatmapSet(beatmapSetSecond); // Act @@ -165,6 +181,7 @@ public async Task TestUpdateBeatmapCustomStatusToDefault() var beatmapSet = _mocker.Beatmap.GetRandomBeatmapSet(); var beatmap = beatmapSet.Beatmaps.First(); + beatmapSet.StatusString = BeatmapStatusWeb.Ranked.BeatmapStatusWebToString(); await _mocker.Beatmap.MockBeatmapSet(beatmapSet); var addCustomBeatmapStatusResult = await Database.Beatmaps.CustomStatuses.AddCustomBeatmapStatus(new CustomBeatmapStatus diff --git a/Sunrise.Tests/Manager/EnvironmentVariableManager.cs b/Sunrise.Tests/Manager/EnvironmentVariableManager.cs index d9360546..b305be15 100644 --- a/Sunrise.Tests/Manager/EnvironmentVariableManager.cs +++ b/Sunrise.Tests/Manager/EnvironmentVariableManager.cs @@ -45,4 +45,30 @@ public void Set(string key, string? value) throw new Exception($"Configuration reload failed after setting environment variable '{key}'.", ex); } } + + public void Set(string key, List values) + { + if (!_originalValues.ContainsKey(key)) + { + _originalValues[key] = Environment.GetEnvironmentVariable(key); + } + + Env.TraversePath().Load(".env.tests"); + + Environment.SetEnvironmentVariable(key, null); + + for (var i = 0; i < values.Count; i++) + { + Environment.SetEnvironmentVariable($"{key}:{i}", values[i]); + } + + try + { + Configuration.GetConfig().Reload(); + } + catch (Exception ex) + { + throw new Exception($"Configuration reload failed after setting environment variable '{key}'.", ex); + } + } } \ No newline at end of file