1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:13:21 +08:00

Handle score submission request in submission test scene

Was previously not handled at all, therefore displaying request failures
in the test log output. While that was mostly a red herring and
shouldn't have caused any actual *test* failures, it is still better to
handle this explicitly in a realistic manner.
This commit is contained in:
Bartłomiej Dach 2022-01-06 12:57:26 +01:00
parent a9e4a0fd61
commit 84765b99b3
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 42 additions and 17 deletions

View File

@ -57,7 +57,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestNoSubmissionOnResultsWithNoToken()
{
prepareTokenResponse(false);
prepareTestAPI(false);
createPlayerTest();
@ -77,7 +77,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestSubmissionOnResults()
{
prepareTokenResponse(true);
prepareTestAPI(true);
createPlayerTest();
@ -96,7 +96,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestSubmissionForDifferentRuleset()
{
prepareTokenResponse(true);
prepareTestAPI(true);
createPlayerTest(createRuleset: () => new TaikoRuleset());
@ -116,7 +116,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestSubmissionForConvertedBeatmap()
{
prepareTokenResponse(true);
prepareTestAPI(true);
createPlayerTest(createRuleset: () => new ManiaRuleset(), createBeatmap: _ => createTestBeatmap(new OsuRuleset().RulesetInfo));
@ -136,7 +136,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestNoSubmissionOnExitWithNoToken()
{
prepareTokenResponse(false);
prepareTestAPI(false);
createPlayerTest();
@ -153,7 +153,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestNoSubmissionOnEmptyFail()
{
prepareTokenResponse(true);
prepareTestAPI(true);
createPlayerTest(true);
@ -168,7 +168,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestSubmissionOnFail()
{
prepareTokenResponse(true);
prepareTestAPI(true);
createPlayerTest(true);
@ -185,7 +185,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestNoSubmissionOnEmptyExit()
{
prepareTokenResponse(true);
prepareTestAPI(true);
createPlayerTest();
@ -198,7 +198,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestSubmissionOnExit()
{
prepareTokenResponse(true);
prepareTestAPI(true);
createPlayerTest();
@ -213,7 +213,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestSubmissionOnExitDuringImport()
{
prepareTokenResponse(true);
prepareTestAPI(true);
createPlayerTest();
AddStep("block imports", () => Player.AllowImportCompletion.Wait());
@ -232,7 +232,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestNoSubmissionOnLocalBeatmap()
{
prepareTokenResponse(true);
prepareTestAPI(true);
createPlayerTest(false, r =>
{
@ -253,7 +253,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[TestCase(10)]
public void TestNoSubmissionOnCustomRuleset(int? rulesetId)
{
prepareTokenResponse(true);
prepareTestAPI(true);
createPlayerTest(false, createRuleset: () => new OsuRuleset { RulesetInfo = { OnlineID = rulesetId ?? -1 } });
@ -275,7 +275,7 @@ namespace osu.Game.Tests.Visual.Gameplay
}));
}
private void prepareTokenResponse(bool validToken)
private void prepareTestAPI(bool validToken)
{
AddStep("Prepare test API", () =>
{
@ -289,6 +289,31 @@ namespace osu.Game.Tests.Visual.Gameplay
else
tokenRequest.TriggerFailure(new APIException("something went wrong!", null));
return true;
case SubmitSoloScoreRequest submissionRequest:
if (validToken)
{
var requestScore = submissionRequest.Score;
submissionRequest.TriggerSuccess(new MultiplayerScore
{
ID = 1234,
User = dummyAPI.LocalUser.Value,
Rank = requestScore.Rank,
TotalScore = requestScore.TotalScore,
Accuracy = requestScore.Accuracy,
MaxCombo = requestScore.MaxCombo,
Mods = requestScore.Mods,
Statistics = requestScore.Statistics,
Passed = requestScore.Passed,
EndedAt = DateTimeOffset.Now,
Position = 1
});
return true;
}
break;
}
return false;

View File

@ -12,17 +12,17 @@ namespace osu.Game.Online.Solo
{
public class SubmitSoloScoreRequest : APIRequest<MultiplayerScore>
{
public readonly SubmittableScore Score;
private readonly long scoreId;
private readonly int beatmapId;
private readonly SubmittableScore score;
public SubmitSoloScoreRequest(int beatmapId, long scoreId, ScoreInfo scoreInfo)
{
this.beatmapId = beatmapId;
this.scoreId = scoreId;
score = new SubmittableScore(scoreInfo);
Score = new SubmittableScore(scoreInfo);
}
protected override WebRequest CreateWebRequest()
@ -33,7 +33,7 @@ namespace osu.Game.Online.Solo
req.Method = HttpMethod.Put;
req.Timeout = 30000;
req.AddRaw(JsonConvert.SerializeObject(score, new JsonSerializerSettings
req.AddRaw(JsonConvert.SerializeObject(Score, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}));