using System.Linq;
using Content.Shared.Roles.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Reflection;
namespace Content.IntegrationTests.Tests.Minds;
[TestFixture]
public sealed class RoleTests
{
///
/// Check that any prototype with a is properly configured
///
[Test]
public async Task ValidateRolePrototypes()
{
await using var pair = await PoolManager.GetServerClient();
var jobComp = pair.Server.ResolveDependency().GetComponentName();
Assert.Multiple(() =>
{
foreach (var (proto, comp) in pair.GetPrototypesWithComponent())
{
Assert.That(comp.AntagPrototype == null || comp.JobPrototype == null, $"Role {proto.ID} has both a job and antag prototype.");
Assert.That(!comp.ExclusiveAntag || comp.Antag, $"Role {proto.ID} is marked as an exclusive antag, despite not being an antag.");
Assert.That(comp.Antag || comp.AntagPrototype == null, $"Role {proto.ID} has an antag prototype, despite not being an antag.");
if (comp.JobPrototype != null)
Assert.That(proto.Components.ContainsKey(jobComp), $"Role {proto.ID} is a job, despite not having a job prototype.");
// It is possible that this is meant to be supported? Though I would assume that it would be for
// admin / prototype uploads, and that pre-defined roles should still check this.
Assert.That(!comp.Antag || comp.AntagPrototype != null , $"Role {proto.ID} is an antag, despite not having a antag prototype.");
}
});
await pair.CleanReturnAsync();
}
///
/// Check that any prototype with a also has a properly configured
///
///
[Test]
public async Task ValidateJobPrototypes()
{
await using var pair = await PoolManager.GetServerClient();
var mindCompId = pair.Server.ResolveDependency().GetComponentName();
Assert.Multiple(() =>
{
foreach (var (proto, comp) in pair.GetPrototypesWithComponent())
{
if (proto.Components.TryGetComponent(mindCompId, out var mindComp))
Assert.That(((MindRoleComponent)mindComp).JobPrototype, Is.Not.Null);
}
});
await pair.CleanReturnAsync();
}
///
/// Check that any prototype with a component that inherits from also has a
///
///
[Test]
public async Task ValidateRolesHaveMindRoleComp()
{
await using var pair = await PoolManager.GetServerClient();
var refMan = pair.Server.ResolveDependency();
var mindCompId = pair.Server.ResolveDependency().GetComponentName();
var compTypes = refMan.GetAllChildren(typeof(BaseMindRoleComponent))
.Append(typeof(RoleBriefingComponent))
.Where(x => !x.IsAbstract);
Assert.Multiple(() =>
{
foreach (var comp in compTypes)
{
foreach (var proto in pair.GetPrototypesWithComponent(comp))
{
Assert.That(proto.Components.ContainsKey(mindCompId), $"Role {proto.ID} does not have a {nameof(MindRoleComponent)} despite having a {comp.Name}");
}
}
});
await pair.CleanReturnAsync();
}
}