Skip to content

Commit

Permalink
LevelListOverrideTests: Basic CanGetOverriddenLevels test (#263)
Browse files Browse the repository at this point in the history
This restores 100% tost coverage for LevelEndpoints
  • Loading branch information
jvyden authored Nov 10, 2023
2 parents f48fd58 + 477f704 commit 57754e5
Showing 1 changed file with 28 additions and 2 deletions.
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);
}
}

0 comments on commit 57754e5

Please sign in to comment.