]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add test of objective-related console commands (#36400)
authorTayrtahn <tayrtahn@gmail.com>
Wed, 2 Jul 2025 00:57:57 +0000 (20:57 -0400)
committerGitHub <noreply@github.com>
Wed, 2 Jul 2025 00:57:57 +0000 (02:57 +0200)
* Add test of objective add/list/remove commands

* Not sure why we're validating test prototypes, but sure

* We don't need a map

Content.IntegrationTests/Tests/Commands/ObjectiveCommandsTest.cs [new file with mode: 0644]

diff --git a/Content.IntegrationTests/Tests/Commands/ObjectiveCommandsTest.cs b/Content.IntegrationTests/Tests/Commands/ObjectiveCommandsTest.cs
new file mode 100644 (file)
index 0000000..a77761a
--- /dev/null
@@ -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
+""";
+
+    /// <summary>
+    /// Creates a dummy session, and assigns it a mind, then
+    /// tests using <c>addobjective</c>, <c>lsobjectives</c>,
+    /// and <c>rmobjective</c> on it.
+    /// </summary>
+    [Test]
+    public async Task AddListRemoveObjectiveTest()
+    {
+        await using var pair = await PoolManager.GetServerClient();
+        var server = pair.Server;
+        var entMan = server.EntMan;
+        var playerMan = server.ResolveDependency<ISharedPlayerManager>();
+        var mindSys = server.System<SharedMindSystem>();
+        var objectivesSystem = server.System<ObjectivesSystem>();
+
+        await server.AddDummySession(DummyUsername);
+        await server.WaitRunTicks(5);
+
+        var playerSession = playerMan.Sessions.Single();
+
+        Entity<MindComponent>? 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();
+    }
+}