Implement exporter using nocap from nostr-watch along with tests
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { loadConfig } from "../src/config.js";
|
||||
|
||||
test("loadConfig parses valid relays and ignores invalid entries", () => {
|
||||
const config = loadConfig({
|
||||
RELAYS: "wss://relay.damus.io,not-a-url,wss://nos.lol",
|
||||
WRITE_CHECK_ENABLED: "false",
|
||||
});
|
||||
|
||||
assert.equal(config.relays.length, 2);
|
||||
assert.equal(config.relays[0]?.relay, "wss://relay.damus.io/");
|
||||
assert.equal(config.relays[1]?.relay, "wss://nos.lol/");
|
||||
assert.equal(config.writeCheck.enabled, false);
|
||||
assert.equal(config.probeIntervalMs, 0);
|
||||
assert.ok(config.warnings.some((w) => w.includes("Ignoring invalid relay URL")));
|
||||
});
|
||||
|
||||
test("loadConfig generates write-check private key when missing", () => {
|
||||
const config = loadConfig({
|
||||
RELAYS: "wss://relay.damus.io",
|
||||
WRITE_CHECK_ENABLED: "true",
|
||||
});
|
||||
|
||||
assert.equal(config.writeCheck.enabled, true);
|
||||
assert.match(config.writeCheck.privkey ?? "", /^[0-9a-f]{64}$/i);
|
||||
assert.ok(
|
||||
config.warnings.some((w) => w.includes("generated ephemeral write-check key")),
|
||||
"expected warning about generated write-check key",
|
||||
);
|
||||
});
|
||||
|
||||
test("loadConfig generates write-check private key when configured key is invalid", () => {
|
||||
const config = loadConfig({
|
||||
RELAYS: "wss://relay.damus.io",
|
||||
WRITE_CHECK_ENABLED: "true",
|
||||
WRITE_CHECK_PRIVKEY: "not-a-valid-key",
|
||||
});
|
||||
|
||||
assert.equal(config.writeCheck.enabled, true);
|
||||
assert.match(config.writeCheck.privkey ?? "", /^[0-9a-f]{64}$/i);
|
||||
assert.notEqual(config.writeCheck.privkey, "not-a-valid-key");
|
||||
assert.ok(
|
||||
config.warnings.some((w) => w.includes("WRITE_CHECK_PRIVKEY invalid")),
|
||||
"expected warning about invalid configured key",
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user