JobTests.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Shared.Roles;
  2. using Content.Shared.Roles.Jobs;
  3. using Robust.Shared.Prototypes;
  4. using System.Linq;
  5. namespace Content.IntegrationTests.Tests.Station;
  6. [TestFixture]
  7. [TestOf(typeof(SharedJobSystem))]
  8. public sealed class JobTest
  9. {
  10. /// <summary>
  11. /// Ensures that every job belongs to at most 1 primary department.
  12. /// Having no primary department is ok.
  13. /// </summary>
  14. [Test]
  15. public async Task PrimaryDepartmentsTest()
  16. {
  17. await using var pair = await PoolManager.GetServerClient();
  18. var server = pair.Server;
  19. var prototypeManager = server.ResolveDependency<IPrototypeManager>();
  20. await server.WaitAssertion(() =>
  21. {
  22. // only checking primary departments so don't bother with others
  23. var departments = prototypeManager.EnumeratePrototypes<DepartmentPrototype>()
  24. .Where(department => department.Primary)
  25. .ToList();
  26. var jobs = prototypeManager.EnumeratePrototypes<JobPrototype>();
  27. foreach (var job in jobs)
  28. {
  29. // not actually using the jobs system since that will return the first department
  30. // and we need to test that there is never more than 1, so it not sorting them is correct
  31. var primaries = 0;
  32. foreach (var department in departments)
  33. {
  34. if (!department.Roles.Contains(job.ID))
  35. continue;
  36. primaries++;
  37. Assert.That(primaries, Is.EqualTo(1), $"The job {job.ID} has more than 1 primary department!");
  38. }
  39. }
  40. });
  41. await pair.CleanReturnAsync();
  42. }
  43. }