baa-conductor


baa-conductor / apps / conductor-daemon / src / renewal
codex@macbookpro  ·  2026-04-01

utils.test.js

 1import assert from "node:assert/strict";
 2import test from "node:test";
 3
 4import {
 5  isPlainRecord,
 6  normalizeOptionalString,
 7  normalizeRequiredString,
 8  parseJsonValue
 9} from "../../dist/renewal/utils.js";
10
11test("renewal utils normalize optional and required strings without changing legacy error styles", () => {
12  assert.equal(normalizeOptionalString("  hello  "), "hello");
13  assert.equal(normalizeOptionalString("   "), null);
14  assert.equal(normalizeOptionalString(null), null);
15  assert.equal(normalizeOptionalString(123), null);
16
17  assert.equal(normalizeRequiredString("  value  ", "name"), "value");
18  assert.throws(
19    () => normalizeRequiredString("   ", "cursorStateKey"),
20    /cursorStateKey must be a non-empty string\./u
21  );
22  assert.throws(
23    () => normalizeRequiredString(null, "platform", {
24      errorStyle: "field"
25    }),
26    /Field "platform" must be a non-empty string\./u
27  );
28});
29
30test("renewal utils parse JSON values and distinguish plain records", () => {
31  const parsedRecord = parseJsonValue("{\"text\":\"hello\"}");
32
33  assert.deepEqual(parsedRecord, {
34    text: "hello"
35  });
36  assert.equal(isPlainRecord(parsedRecord), true);
37  assert.equal(isPlainRecord(parseJsonValue("[1,2,3]")), false);
38  assert.equal(isPlainRecord(parseJsonValue("\"hello\"")), false);
39  assert.equal(isPlainRecord(parseJsonValue(null)), false);
40  assert.equal(parseJsonValue("{"), null);
41});