Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LevelListOverrideTests: Basic CanGetOverriddenLevels test #263

Merged
merged 1 commit into from
Nov 10, 2023
Merged
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
30 changes: 28 additions & 2 deletions RefreshTests.GameServer/Tests/Levels/LevelListOverrideTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using Refresh.GameServer.Authentication;
using Refresh.GameServer.Services;
using Refresh.GameServer.Types.Levels;
using Refresh.GameServer.Types.Lists;
using Refresh.GameServer.Types.UserData;
using RefreshTests.GameServer.Extensions;
using RefreshTests.GameServer.Logging;

namespace RefreshTests.GameServer.Tests.Levels;
Expand Down Expand Up @@ -39,15 +41,39 @@ public void CanGetOverriddenLevels()
GameUser user = context.CreateUser();
GameLevel level = context.CreateLevel(user, "dingus 2B47430C-70F1-4A21-A1D0-EC3011A62239");

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game);
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);

// Verify that the endpoint isn't already attempting to return anything
// This can be any endpoint that doesnt return all levels but I chose mmpicks
HttpResponseMessage message = client.GetAsync("/lbp/slots/mmpicks").Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
Assert.That(message.Content.ReadAsStringAsync().Result, Does.Not.Contain(level.Title));
SerializedMinimalLevelList levelList = message.Content.ReadAsXML<SerializedMinimalLevelList>();
Assert.That(levelList.Items, Is.Empty);

//Make sure we dont have an override set
LevelListOverrideService overrideService = context.GetService<LevelListOverrideService>();
Assert.That(overrideService.UserHasOverrides(user), Is.False);

//Set a level as the override
message = client.PostAsync($"/api/v3/levels/id/{level.LevelId}/setAsOverride", new ByteArrayContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));

context.Database.Refresh();

//Assert that the override was set in the database properly
Assert.That(overrideService.UserHasOverrides(user), Is.True);

//Get the slots, and make sure it contains the level we set as the override
message = client.GetAsync("/lbp/slots/mmpicks").Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
levelList = message.Content.ReadAsXML<SerializedMinimalLevelList>();
Assert.That(levelList.Items, Has.Count.EqualTo(1));
Assert.That(levelList.Items[0].LevelId, Is.EqualTo(level.LevelId));

//Verify the team picks slot list has stopped pointing to the user override
message = client.GetAsync("/lbp/slots/mmpicks").Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
levelList = message.Content.ReadAsXML<SerializedMinimalLevelList>();
Assert.That(levelList.Items, Is.Empty);
}
}
Loading