import test from "node:test";
import assert from "node:assert/strict";
import { sessionContext, sortSessions } from "./session-list.js";

test("sorts sessions newest first", () => {
  const sessions = [
    { id: "old", updatedAt: "2026-06-27T00:00:00.000Z" },
    { id: "new", updatedAt: "2026-06-27T01:00:00.000Z" }
  ];
  assert.deepEqual(sortSessions(sessions).map((item) => item.id), ["new", "old"]);
});

test("resolves account and workspace labels", () => {
  const result = sessionContext(
    { accountId: "account-a", workspaceId: "workspace-a" },
    [{ id: "account-a", label: "Account A" }],
    [{ id: "workspace-a", label: "Workspace A" }]
  );
  assert.deepEqual(result, { accountLabel: "Account A", workspaceLabel: "Workspace A" });
});
