feat(M4): Reusable code abstractions and dead-code removal
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { dryRunResponse, resolveFormat } from "../src/command-helpers.js";
|
||||
|
||||
// ── dryRunResponse ────────────────────────────────────────────────────────
|
||||
|
||||
test("dryRunResponse wraps data with ok:true and dryRun:true", () => {
|
||||
const data = { method: "POST", url: "https://example.com/api/v2/pages" };
|
||||
const result = dryRunResponse(data);
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.dryRun, true);
|
||||
assert.deepEqual(result.data, data);
|
||||
});
|
||||
|
||||
test("dryRunResponse preserves the exact data reference", () => {
|
||||
const data = { nested: { key: "value" } };
|
||||
const result = dryRunResponse(data);
|
||||
assert.strictEqual(result.data, data);
|
||||
});
|
||||
|
||||
test("dryRunResponse works with primitive data", () => {
|
||||
const result = dryRunResponse("dry-run-string");
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.dryRun, true);
|
||||
assert.equal(result.data, "dry-run-string");
|
||||
});
|
||||
|
||||
// ── resolveFormat ─────────────────────────────────────────────────────────
|
||||
|
||||
test("resolveFormat returns json by default for undefined", () => {
|
||||
assert.equal(resolveFormat(undefined), "json");
|
||||
});
|
||||
|
||||
test("resolveFormat returns json for unrecognised values", () => {
|
||||
assert.equal(resolveFormat("xml"), "json");
|
||||
assert.equal(resolveFormat(""), "json");
|
||||
assert.equal(resolveFormat("TEXT"), "json");
|
||||
});
|
||||
|
||||
test("resolveFormat returns text only for the exact string 'text'", () => {
|
||||
assert.equal(resolveFormat("text"), "text");
|
||||
});
|
||||
Reference in New Issue
Block a user