sourceServerStatus.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. aggregateSourceStatus,
  4. buildAggregatedSourceStatusMap,
  5. } from "@/lib/remoteConnectionPresentation.js";
  6. describe("aggregateSourceStatus", () => {
  7. it("uses semantic precedence instead of input order", () => {
  8. expect(
  9. aggregateSourceStatus([
  10. { state: "offline" },
  11. { state: "bootstrapping" },
  12. { state: "identity-change-pending" },
  13. ]),
  14. ).toBe("connecting");
  15. expect(aggregateSourceStatus([{ state: "offline" }, { state: "needs-upgrade" }])).toBe(
  16. "pending",
  17. );
  18. expect(aggregateSourceStatus([{ state: "failed" }, { state: "offline" }])).toBe("failed");
  19. expect(aggregateSourceStatus([{ state: "offline" }])).toBe("offline");
  20. });
  21. it("builds one Source status map from active profiles only", () => {
  22. expect(
  23. buildAggregatedSourceStatusMap({
  24. servers: [{ sourceServerId: "source-1" }],
  25. profiles: [
  26. {
  27. profileId: "active",
  28. sourceServerId: "source-1",
  29. lifecycleState: "active",
  30. },
  31. {
  32. profileId: "retired",
  33. sourceServerId: "source-1",
  34. lifecycleState: "retired",
  35. },
  36. ],
  37. states: [
  38. { profileId: "active", state: "offline" },
  39. { profileId: "retired", state: "online" },
  40. ],
  41. } as never),
  42. ).toEqual(new Map([["source-1", "offline"]]));
  43. });
  44. });