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

Add test coverage for grief reports #266

Merged
merged 4 commits into from
Nov 12, 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
7 changes: 6 additions & 1 deletion Refresh.GameServer/Database/GameDatabaseContext.Reports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ public partial class GameDatabaseContext
public void AddGriefReport(GameReport report)
{
this.AddSequentialObject(report, () => {});
}
}

public DatabaseList<GameReport> GetGriefReports(int count, int skip)
{
return new DatabaseList<GameReport>(this._realm.All<GameReport>(), skip, count);
}
}
8 changes: 8 additions & 0 deletions Refresh.GameServer/Database/GameDatabaseContext.Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ public void ResetUserPlanets(GameUser user)
user.VitaPlanetsHash = "0";
});
}

public void SetUserGriefReportRedirection(GameUser user, bool value)
{
this._realm.Write(() =>
{
user.RedirectGriefReportsToPhotos = value;
});
}

#if DEBUG
public void ForceUserTokenGame(Token token, TokenGame game)
Expand Down
3 changes: 2 additions & 1 deletion Refresh.GameServer/Endpoints/Game/ModerationEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public string Filter(RequestContext context, CommandService commandService, stri
commandService.HandleCommand(command, database, user, token);
return "(Command)";
}
catch
catch(Exception ex)
{
context.Logger.LogWarning(BunkumCategory.Commands, $"Error running command {body}. ex {ex}");
//do nothing
}
}
Expand Down
29 changes: 20 additions & 9 deletions Refresh.GameServer/Endpoints/Game/ReportingEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,26 @@ public Response UploadReport(RequestContext context, GameDatabaseContext databas
{
GameLevel? level = database.GetLevelById(body.LevelId);

Size imageSize = token.TokenGame switch {
TokenGame.LittleBigPlanet1 => new Size(640, 360),
TokenGame.LittleBigPlanet2 => new Size(640, 360),
TokenGame.LittleBigPlanet3 => new Size(640, 360),
TokenGame.LittleBigPlanetVita => new Size(512, 290),
TokenGame.LittleBigPlanetPSP => new Size(480, 272),
_ => throw new ArgumentOutOfRangeException(nameof(token), $"Token game {token.TokenGame} is not allowed for grief upload!"),
};

Size imageSize;
switch (token.TokenGame)
{
case TokenGame.LittleBigPlanet1:
case TokenGame.LittleBigPlanet2:
case TokenGame.LittleBigPlanet3:
imageSize = new Size(640, 360);
break;
case TokenGame.LittleBigPlanetVita:
imageSize = new Size(512, 290);
break;
case TokenGame.LittleBigPlanetPSP:
imageSize = new Size(480, 272);
break;
case TokenGame.Website:
default:
context.Logger.LogWarning(BunkumCategory.Game, $"User {user} tried to upload grief report with token type {token.TokenGame}!");
return BadRequest;
}

//If the level is specified but its invalid, return BadRequest
if (body.LevelId != 0 && level == null)
return BadRequest;
Expand Down
4 changes: 2 additions & 2 deletions Refresh.GameServer/Services/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ public void HandleCommand(CommandInvocation command, GameDatabaseContext databas
}
case "griefphotoson":
{
user.RedirectGriefReportsToPhotos = true;
database.SetUserGriefReportRedirection(user, true);
break;
}
case "griefphotosoff":
{
user.RedirectGriefReportsToPhotos = false;
database.SetUserGriefReportRedirection(user, false);
break;
}
case "play":
Expand Down
16 changes: 16 additions & 0 deletions RefreshTests.GameServer/TestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public HttpClient GetAuthenticatedClient(TokenType type,
{
return this.GetAuthenticatedClient(type, out _, user, tokenExpirySeconds);
}

public HttpClient GetAuthenticatedClient(TokenType type, TokenGame game, TokenPlatform platform,
GameUser? user = null,
int tokenExpirySeconds = GameDatabaseContext.DefaultTokenExpirySeconds)
{
return this.GetAuthenticatedClient(type, game, platform, out _, user, tokenExpirySeconds);
}

public HttpClient GetAuthenticatedClient(TokenType type, out string tokenData,
GameUser? user = null,
Expand All @@ -56,6 +63,15 @@ public HttpClient GetAuthenticatedClient(TokenType type, out string tokenData,
_ => TokenPlatform.Website,
};

return this.GetAuthenticatedClient(type, game, platform, out tokenData, user, tokenExpirySeconds);
}

public HttpClient GetAuthenticatedClient(TokenType type, TokenGame game, TokenPlatform platform, out string tokenData,
GameUser? user = null,
int tokenExpirySeconds = GameDatabaseContext.DefaultTokenExpirySeconds)
{
user ??= this.CreateUser();

Token token = this.Database.GenerateTokenForUser(user, type, game, platform, tokenExpirySeconds);
tokenData = token.TokenData;

Expand Down
Loading