diff --git a/Content.IntegrationTests/Tests/Commands/ObjectiveCommandsTest.cs b/Content.IntegrationTests/Tests/Commands/ObjectiveCommandsTest.cs new file mode 100644 index 0000000000..a77761a7d1 --- /dev/null +++ b/Content.IntegrationTests/Tests/Commands/ObjectiveCommandsTest.cs @@ -0,0 +1,72 @@ +#nullable enable +using System.Linq; +using Content.Server.Objectives; +using Content.Shared.Mind; +using Robust.Shared.GameObjects; +using Robust.Shared.Player; + +namespace Content.IntegrationTests.Tests.Commands; + +public sealed class ObjectiveCommandsTest +{ + + private const string ObjectiveProtoId = "MindCommandsTestObjective"; + private const string DummyUsername = "MindCommandsTestUser"; + + [TestPrototypes] + private const string Prototypes = $""" +- type: entity + id: {ObjectiveProtoId} + components: + - type: Objective + difficulty: 1 + issuer: objective-issuer-syndicate + icon: + sprite: error.rsi + state: error + - type: DieCondition +"""; + + /// + /// Creates a dummy session, and assigns it a mind, then + /// tests using addobjective, lsobjectives, + /// and rmobjective on it. + /// + [Test] + public async Task AddListRemoveObjectiveTest() + { + await using var pair = await PoolManager.GetServerClient(); + var server = pair.Server; + var entMan = server.EntMan; + var playerMan = server.ResolveDependency(); + var mindSys = server.System(); + var objectivesSystem = server.System(); + + await server.AddDummySession(DummyUsername); + await server.WaitRunTicks(5); + + var playerSession = playerMan.Sessions.Single(); + + Entity? mindEnt = null; + await server.WaitPost(() => + { + mindEnt = mindSys.CreateMind(playerSession.UserId); + }); + + Assert.That(mindEnt, Is.Not.Null); + var mindComp = mindEnt.Value.Comp; + Assert.That(mindComp.Objectives, Is.Empty, "Dummy player started with objectives."); + + await pair.WaitCommand($"addobjective {playerSession.Name} {ObjectiveProtoId}"); + + Assert.That(mindComp.Objectives, Has.Count.EqualTo(1), "addobjective failed to increase Objectives count."); + + await pair.WaitCommand($"lsobjectives {playerSession.Name}"); + + await pair.WaitCommand($"rmobjective {playerSession.Name} 0"); + + Assert.That(mindComp.Objectives, Is.Empty, "rmobjective failed to remove objective"); + + await pair.CleanReturnAsync(); + } +}