mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-27 07:59:03 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RadicadeServer.DB;
|
||||
using RadicadeServer.RecNet.Auth;
|
||||
using RadicadeServer.RecNet.Enums.Moderation;
|
||||
using RadicadeServer.Utils;
|
||||
using Xunit;
|
||||
|
||||
namespace RadicadeServer.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// A ban that lands because the account is related to a banned one - a shared device or address -
|
||||
/// prints the account it is related to on its own line under the reason. The moderationBlockDetails
|
||||
/// screen has always done this; these lock in that the pushed ban body carries the same line, and
|
||||
/// that a ban about the player themselves never names anybody.
|
||||
/// </summary>
|
||||
[Collection(DbFactoryCollection.Name)]
|
||||
public class BanRelatedAccountTests
|
||||
{
|
||||
private static RecDBContext NewDb() => new(
|
||||
TestDbOptions.Create()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options);
|
||||
|
||||
private static async Task AddProfileAsync(RecDBContext db, long accountId, string username)
|
||||
{
|
||||
db.Profiles.Add(new Profile
|
||||
{
|
||||
accountId = accountId,
|
||||
username = username,
|
||||
displayName = username,
|
||||
profileImage = DBConfig.DefaultProfileImage
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildBlockDetailsAppendsTheRelatedAccountWhenOneIsGiven()
|
||||
{
|
||||
var details = PlayerUtils.BuildBlockDetails(true, ReportCategory.Misc, "Sharing a banned device.",
|
||||
DateTime.UtcNow.AddDays(1), relatedUsername: "HealthyMoose640");
|
||||
|
||||
Assert.Equal("Sharing a banned device.\nRelated account: @HealthyMoose640", details.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildBlockDetailsWithoutARelatedAccountIsJustTheReason()
|
||||
{
|
||||
var details = PlayerUtils.BuildBlockDetails(true, ReportCategory.Misc, "Harassment.",
|
||||
DateTime.UtcNow.AddDays(1));
|
||||
|
||||
Assert.Equal("Harassment.", details.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ARelationBanNamesTheAccountItIsRelatedTo()
|
||||
{
|
||||
using var db = NewDb();
|
||||
await AddProfileAsync(db, 12, "HealthyMoose640");
|
||||
|
||||
var ban = new PlayerUtils.PlayerBanInfo("Hardware", "Sharing a banned device.",
|
||||
DateTime.UtcNow.AddDays(1), "hw:1", ReportCategory.Misc, BannedAccountId: 12);
|
||||
|
||||
var details = await PlayerUtils.BuildBanBlockDetailsAsync(db, ban, accountId: 42);
|
||||
|
||||
Assert.True(details.IsBan);
|
||||
Assert.Equal("Sharing a banned device.\nRelated account: @HealthyMoose640", details.Message);
|
||||
Assert.Equal(details.Message, details.DisplayReason);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ABanAboutThePlayerThemselvesNamesNobody()
|
||||
{
|
||||
using var db = NewDb();
|
||||
await AddProfileAsync(db, 42, "SoleBearer");
|
||||
|
||||
var ban = new PlayerUtils.PlayerBanInfo("Moderation", "Harassment.",
|
||||
DateTime.UtcNow.AddDays(1), "mod:1", ReportCategory.Misc, BannedAccountId: 42);
|
||||
|
||||
var details = await PlayerUtils.BuildBanBlockDetailsAsync(db, ban, accountId: 42);
|
||||
|
||||
Assert.Equal("Harassment.", details.Message);
|
||||
Assert.DoesNotContain("Related account", details.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ABanWithNoRelatedAccountIsJustTheReason()
|
||||
{
|
||||
using var db = NewDb();
|
||||
|
||||
var ban = new PlayerUtils.PlayerBanInfo("Moderation", "Cheating.",
|
||||
DateTime.UtcNow.AddDays(1), "mod:2", ReportCategory.Cheating);
|
||||
|
||||
var details = await PlayerUtils.BuildBanBlockDetailsAsync(db, ban, accountId: 7);
|
||||
|
||||
Assert.Equal("Cheating.", details.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RelatedAccountUsernameIgnoresAMissingOrSelfReference()
|
||||
{
|
||||
using var db = NewDb();
|
||||
await AddProfileAsync(db, 12, "HealthyMoose640");
|
||||
|
||||
Assert.Null(await PlayerUtils.RelatedAccountUsernameAsync(db, null, 42));
|
||||
Assert.Null(await PlayerUtils.RelatedAccountUsernameAsync(db, 42, 42));
|
||||
Assert.Null(await PlayerUtils.RelatedAccountUsernameAsync(db, 999, 42));
|
||||
Assert.Equal("HealthyMoose640", await PlayerUtils.RelatedAccountUsernameAsync(db, 12, 42));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user