0576820059
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
25 lines
1.2 KiB
TypeScript
25 lines
1.2 KiB
TypeScript
// server/services/refresh.test.ts
|
|
import { describe, it, expect, vi } from "vitest";
|
|
|
|
// Mock all modules with side-effects at import time (DB, SSH, templates)
|
|
vi.mock("../db/client.js", () => ({ db: {}, schema: { machines: {}, snapshots: {} } }));
|
|
vi.mock("../env.js", () => ({ env: { requireMasterKey: vi.fn(), reportsDir: "/tmp" } }));
|
|
vi.mock("../ssh/client.js", () => ({ runScriptSudo: vi.fn() }));
|
|
vi.mock("../templates/render.js", () => ({ renderTemplate: vi.fn() }));
|
|
vi.mock("../templates/aptReduce.js", () => ({ reduceAptLines: vi.fn(() => []) }));
|
|
vi.mock("./machines.js", () => ({ getMachineRow: vi.fn(), getCreds: vi.fn() }));
|
|
vi.mock("../ws/outputHub.js", () => ({ outputHub: { clear: vi.fn(), publish: vi.fn() } }));
|
|
|
|
import { extractSection } from "./refresh.js";
|
|
|
|
const raw = "===SU:UPDATE===\nok\n===SU:SIMULATE===\nInst a [1] (2 X [amd64])\n===SU:REBOOT===\nREBOOT_REQUIRED=0\n===SU:END===";
|
|
|
|
describe("extractSection", () => {
|
|
it("extrait le contenu entre deux marqueurs", () => {
|
|
expect(extractSection(raw, "===SU:SIMULATE===", "===SU:REBOOT===")).toBe("Inst a [1] (2 X [amd64])");
|
|
});
|
|
it("retourne vide si marqueur absent", () => {
|
|
expect(extractSection(raw, "===SU:NOPE===", "===SU:END===")).toBe("");
|
|
});
|
|
});
|