Skip to content

Commit

Permalink
Tests: Refactor all PSP tests + re-add accidentally removed test
Browse files Browse the repository at this point in the history
  • Loading branch information
Beyley committed Nov 8, 2023
1 parent eae6ebd commit 93d7717
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 176 deletions.
13 changes: 13 additions & 0 deletions RefreshTests.GameServer/Tests/Assets/AssetUploadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,17 @@ public void InvalidHashFails()
response = client.GetAsync("/lbp/r/..%2Frpc.json").Result;
Assert.That(response.StatusCode, Is.EqualTo(BadRequest));
}

[Test]
public void CantCheckForInvalidMissingAssets()
{
using TestContext context = this.GetServer();
context.Server.Value.Server.AddService<ImportService>();
GameUser user = context.CreateUser();
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);

//Check the list initially, should have 1 item
HttpResponseMessage response = client.PostAsync("/lbp/filterResources", new StringContent(new SerializedResourceList(new[] { "I_AM_NOT_HASH" }).AsXML())).Result;
Assert.That(response.StatusCode, Is.EqualTo(BadRequest));
}
}
113 changes: 24 additions & 89 deletions RefreshTests.GameServer/Tests/Relations/FavouriteSlotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,20 @@ public void FavouriteAndUnfavouriteLevel()
Assert.That(result.Items, Has.Count.EqualTo(0));
}

[Test]
public void CantFavouriteMissingLevel()
[TestCase(false)]
[TestCase(true)]
public void CantFavouriteMissingLevel(bool psp)
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
if (psp)
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Favourite an invalid level
HttpResponseMessage message = client.PostAsync($"/lbp/favourite/slot/user/{int.MaxValue}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(NotFound));

//Get the favourite slots
message = client.GetAsync($"/lbp/favouriteSlots/{user.Username}").Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
//Make sure its now empty
SerializedMinimalFavouriteLevelList result = message.Content.ReadAsXML<SerializedMinimalFavouriteLevelList>();
Assert.That(result.Items, Has.Count.EqualTo(0));
}

[Test]
public void CantFavouriteMissingLevelPsp()
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Favourite an invalid level
HttpResponseMessage message = client.PostAsync($"/lbp/favourite/slot/user/{int.MaxValue}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
Assert.That(message.StatusCode, Is.EqualTo(psp ? OK : NotFound));

//Get the favourite slots
message = client.GetAsync($"/lbp/favouriteSlots/{user.Username}").Result;
Expand All @@ -82,76 +64,41 @@ public void CantFavouriteMissingLevelPsp()
Assert.That(result.Items, Has.Count.EqualTo(0));
}

[Test]
public void CantUnfavouriteMissingLevel()
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();

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

//Unfavourite an invalid level
HttpResponseMessage message = client.PostAsync($"/lbp/unfavourite/slot/user/{int.MaxValue}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(NotFound));
}

[Test]
public void CantUnfavouriteMissingLevelPsp()
[TestCase(false)]
[TestCase(true)]
public void CantUnfavouriteMissingLevel(bool psp)
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");
if(psp)
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Unfavourite an invalid level
HttpResponseMessage message = client.PostAsync($"/lbp/unfavourite/slot/user/{int.MaxValue}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
Assert.That(message.StatusCode, Is.EqualTo(psp ? OK : NotFound));
}

[Test]
public void CantFavouriteLevelTwice()
[TestCase(false)]
[TestCase(true)]
public void CantFavouriteLevelTwice(bool psp)
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();
GameLevel level = context.CreateLevel(user);

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
if (psp)
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Favourite a level
HttpResponseMessage message = client.PostAsync($"/lbp/favourite/slot/user/{level.LevelId}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));

//Favourite another level
message = client.PostAsync($"/lbp/favourite/slot/user/{level.LevelId}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(Unauthorized));

//Get the favourite slots
message = client.GetAsync($"/lbp/favouriteSlots/{user.Username}").Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
//Make sure it has the level
SerializedMinimalFavouriteLevelList result = message.Content.ReadAsXML<SerializedMinimalFavouriteLevelList>();
Assert.That(result.Items, Has.Count.EqualTo(1));
Assert.That(result.Items.First().LevelId, Is.EqualTo(level.LevelId));
}

[Test]
public void CantFavouriteLevelTwicePsp()
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();
GameLevel level = context.CreateLevel(user);

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Favourite a level
HttpResponseMessage message = client.PostAsync($"/lbp/favourite/slot/user/{level.LevelId}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));

//Favourite the level again
message = client.PostAsync($"/lbp/favourite/slot/user/{level.LevelId}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
Assert.That(message.StatusCode, Is.EqualTo(psp ? OK : Unauthorized));

//Get the favourite slots
message = client.GetAsync($"/lbp/favouriteSlots/{user.Username}").Result;
Expand All @@ -162,32 +109,20 @@ public void CantFavouriteLevelTwicePsp()
Assert.That(result.Items.First().LevelId, Is.EqualTo(level.LevelId));
}

[Test]
public void CantUnfavouriteLevelTwice()
[TestCase(false)]
[TestCase(true)]
public void CantUnfavouriteLevelTwice(bool psp)
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();
GameLevel level = context.CreateLevel(user);

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
if(psp)
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Unfavourite a level, which we haven't favourited
HttpResponseMessage message = client.PostAsync($"/lbp/unfavourite/slot/user/{level.LevelId}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(Unauthorized));
}

[Test]
public void CantUnfavouriteLevelTwicePsp()
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();
GameLevel level = context.CreateLevel(user);

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Unfavourite a level, which we haven't favourited
HttpResponseMessage message = client.PostAsync($"/lbp/unfavourite/slot/user/{level.LevelId}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
Assert.That(message.StatusCode, Is.EqualTo(psp ? OK : Unauthorized));
}
}
111 changes: 24 additions & 87 deletions RefreshTests.GameServer/Tests/Relations/FavouriteUserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ public void FavouriteAndUnfavouriteUser()
Assert.That(result.Items, Has.Count.EqualTo(0));
}

[Test]
public void CantFavouriteMissingUser()
[TestCase(false)]
[TestCase(true)]
public void CantFavouriteMissingUser(bool psp)
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
if(psp)
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Favourite an invalid user
HttpResponseMessage message = client.PostAsync($"/lbp/favourite/user/pain peko", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(NotFound));
Assert.That(message.StatusCode, Is.EqualTo(psp ? OK : NotFound));

//Get the favourite users
message = client.GetAsync($"/lbp/favouriteUsers/{user.Username}").Result;
Expand All @@ -61,97 +64,42 @@ public void CantFavouriteMissingUser()
Assert.That(result.Items, Has.Count.EqualTo(0));
}

[Test]
public void CantFavouriteMissingUserPsp()
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Favourite an invalid user
HttpResponseMessage message = client.PostAsync($"/lbp/favourite/user/painer peko", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));

//Get the favourite users
message = client.GetAsync($"/lbp/favouriteUsers/{user.Username}").Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
//Make sure its still empty
SerializedFavouriteUserList result = message.Content.ReadAsXML<SerializedFavouriteUserList>();
Assert.That(result.Items, Has.Count.EqualTo(0));
}

[Test]
public void CantUnfavouriteMissingUser()
[TestCase(false)]
[TestCase(true)]
public void CantUnfavouriteMissingUser(bool psp)
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
if(psp)
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Unfavourite an invalid user
HttpResponseMessage message = client.PostAsync($"/lbp/unfavourite/user/womp womp", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(NotFound));
Assert.That(message.StatusCode, Is.EqualTo(psp ? OK : NotFound));
}

[Test]
public void CantUnfavouriteMissingUserPsp()
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Unfavourite an invalid user
HttpResponseMessage message = client.PostAsync($"/lbp/unfavourite/user/gymbag", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
}

[Test]
public void CantFavouriteUserTwice()
[TestCase(false)]
[TestCase(true)]
public void CantFavouriteUserTwice(bool psp)
{
using TestContext context = this.GetServer();
GameUser user1 = context.CreateUser();
GameUser user2 = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user1);
if (psp)
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Favourite a user
HttpResponseMessage message = client.PostAsync($"/lbp/favourite/user/{user2.Username}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));

//Favourite the same user again
message = client.PostAsync($"/lbp/favourite/user/{user2.Username}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(Unauthorized));

//Get the favourite users
message = client.GetAsync($"/lbp/favouriteUsers/{user1.Username}").Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
//Make sure it has the user
SerializedFavouriteUserList result = message.Content.ReadAsXML<SerializedFavouriteUserList>();
Assert.That(result.Items, Has.Count.EqualTo(1));
Assert.That(result.Items.First().Handle.Username, Is.EqualTo(user2.Username));
}

[Test]
public void CantFavouriteUserTwicePsp()
{
using TestContext context = this.GetServer();
GameUser user1 = context.CreateUser();
GameUser user2 = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user1);
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Favourite a user
HttpResponseMessage message = client.PostAsync($"/lbp/favourite/user/{user2.Username}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));

//Favourite the same user again
message = client.PostAsync($"/lbp/favourite/user/{user2.Username}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
Assert.That(message.StatusCode, Is.EqualTo(psp ? OK : Unauthorized));

//Get the favourite users
message = client.GetAsync($"/lbp/favouriteUsers/{user1.Username}").Result;
Expand All @@ -162,33 +110,22 @@ public void CantFavouriteUserTwicePsp()
Assert.That(result.Items.First().Handle.Username, Is.EqualTo(user2.Username));
}

[Test]
public void CantUnfavouriteUserTwice()
[TestCase(false)]
[TestCase(true)]
public void CantUnfavouriteUserTwice(bool psp)
{
using TestContext context = this.GetServer();
GameUser user1 = context.CreateUser();
GameUser user2 = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user1);
if(psp)
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Unfavourite a user, which we haven't favourited
HttpResponseMessage message = client.PostAsync($"/lbp/unfavourite/user/{user2.Username}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(Unauthorized));
}

[Test]
public void CantUnfavouriteUserTwicePsp()
{
using TestContext context = this.GetServer();
GameUser user1 = context.CreateUser();
GameUser user2 = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user1);
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

//Unfavourite a user, which we haven't favourited
HttpResponseMessage message = client.PostAsync($"/lbp/unfavourite/user/{user2.Username}", new ReadOnlyMemoryContent(Array.Empty<byte>())).Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));
Assert.That(message.StatusCode, Is.EqualTo(psp ? OK : Unauthorized));
}

[Test]
Expand Down

0 comments on commit 93d7717

Please sign in to comment.