import test from "node:test";
import assert from "node:assert/strict";
import { fetchPcStatus } from "./pc-status.js";

test("PC status returns the safe display name and check time", async () => {
  const checkedAt = new Date("2026-07-13T10:00:00.000Z");
  const status = await fetchPcStatus("https://pc.example.ts.net", async () => ({
    ok: true,
    json: async () => ({ ok: true, pc: { name: "DESKTOP-CODEX" } })
  }), () => checkedAt);

  assert.deepEqual(status, { state: "online", name: "DESKTOP-CODEX", checkedAt });
});

test("PC status reports offline without leaking fetch errors", async () => {
  const status = await fetchPcStatus("https://pc.example.ts.net", async () => {
    throw new Error("secret network detail");
  }, () => new Date("2026-07-13T10:00:00.000Z"));

  assert.deepEqual(status, { state: "offline", name: "", checkedAt: null });
});
