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

100% test coverage with ActivityEndpoints #206

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion Refresh.GameServer/Endpoints/Game/ReviewEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,5 @@ public Response RateUserLevel(RequestContext context, GameDatabaseContext databa
}

return database.RateLevel(level, user, rating) ? OK : Unauthorized;

}
}
66 changes: 66 additions & 0 deletions RefreshTests.GameServer/Tests/Users/ActivityEndpointsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Refresh.GameServer.Authentication;
using Refresh.GameServer.Types.Levels;
using Refresh.GameServer.Types.News;
using Refresh.GameServer.Types.UserData;
using RefreshTests.GameServer.Extensions;

namespace RefreshTests.GameServer.Tests.Users;

public class ActivityEndpointsTests : GameServerTest
{
[Test]
public void GetNews()
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();
GameLevel level = context.CreateLevel(user);

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

//Team pick a level, so that it appears in the news list
context.Database.AddTeamPickToLevel(level);

HttpResponseMessage message = client.GetAsync("/lbp/news").Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));

GameNewsResponse response = message.Content.ReadAsXML<GameNewsResponse>();
Assert.That(response.Subcategory.Items, Has.Count.EqualTo(1));
Assert.That(response.Subcategory.Items[0].Subject, Is.EqualTo("Team Pick"));
}

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

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

HttpResponseMessage message = client.GetAsync($"/lbp/stream").Result;
Assert.That(message.StatusCode, Is.EqualTo(OK));

//TODO: once we figure out how to parse ActivityPage here, lets do that instead of this mess
string response = message.Content.ReadAsStringAsync().Result;

//Ensure that the response contains a first login event, and a user
StringAssert.Contains("<event type=\"firstlogin\">", response);
StringAssert.Contains("<user type=\"user\">", response);
}

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

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

HttpResponseMessage message = client.GetAsync($"/lbp/stream?timestamp=HAHA").Result;
Assert.That(message.StatusCode, Is.EqualTo(BadRequest));

message = client.GetAsync($"/lbp/stream?endTimestamp=HAHAHA").Result;
Assert.That(message.StatusCode, Is.EqualTo(BadRequest));
}
}
Loading