From 0281968867517705425ff75a211bcaa60e593b5a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 8 Feb 2026 03:34:20 +0000 Subject: [PATCH] test: add comprehensive tests for config validation Adds missing test cases to `tests/validate-config.test.mjs` to cover edge cases for: - `ADMIN_SUPER_NPUB` (empty, invalid format) - `PLATFORM_FEE_PERCENT` (negative, >100, infinite) - `THEME_ACCENT_OVERRIDES` (invalid hex, invalid structure) - Optional URLs (invalid URL, invalid protocol) This ensures `validateInstanceConfig` correctly enforces configuration constraints. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- tests/validate-config.test.mjs | 120 ++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 3 deletions(-) diff --git a/tests/validate-config.test.mjs b/tests/validate-config.test.mjs index 630bb580..a974578b 100644 --- a/tests/validate-config.test.mjs +++ b/tests/validate-config.test.mjs @@ -3,13 +3,22 @@ import { test } from "node:test"; import { validateInstanceConfig } from "../config/validate-config.js"; +// Common valid overrides to use as a base +const VALID_OVERRIDES = { + ADMIN_SUPER_NPUB: "npub1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", + PLATFORM_FEE_PERCENT: 5, + PLATFORM_LUD16_OVERRIDE: "test@example.com", +}; + +test("validateInstanceConfig succeeds with valid configuration", () => { + assert.doesNotThrow(() => validateInstanceConfig(VALID_OVERRIDES)); +}); + test( "validateInstanceConfig throws when platform fee is positive without a platform override", () => { const overrides = { - ADMIN_SUPER_NPUB: - "npub1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", - PLATFORM_FEE_PERCENT: 5, + ...VALID_OVERRIDES, PLATFORM_LUD16_OVERRIDE: " ", }; @@ -19,3 +28,108 @@ test( }); } ); + +test("validateInstanceConfig throws when ADMIN_SUPER_NPUB is empty", () => { + const overrides = { + ...VALID_OVERRIDES, + ADMIN_SUPER_NPUB: " ", + }; + + assert.throws(() => validateInstanceConfig(overrides), { + message: /ADMIN_SUPER_NPUB is required/, + }); +}); + +test("validateInstanceConfig throws when ADMIN_SUPER_NPUB does not start with npub", () => { + const overrides = { + ...VALID_OVERRIDES, + ADMIN_SUPER_NPUB: "invalid_npub", + }; + + assert.throws(() => validateInstanceConfig(overrides), { + message: /ADMIN_SUPER_NPUB should be a bech32 npub/, + }); +}); + +test("validateInstanceConfig throws when PLATFORM_FEE_PERCENT is negative", () => { + const overrides = { + ...VALID_OVERRIDES, + PLATFORM_FEE_PERCENT: -1, + }; + + assert.throws(() => validateInstanceConfig(overrides), { + message: /PLATFORM_FEE_PERCENT must be between 0 and 100 inclusive/, + }); +}); + +test("validateInstanceConfig throws when PLATFORM_FEE_PERCENT is greater than 100", () => { + const overrides = { + ...VALID_OVERRIDES, + PLATFORM_FEE_PERCENT: 101, + }; + + assert.throws(() => validateInstanceConfig(overrides), { + message: /PLATFORM_FEE_PERCENT must be between 0 and 100 inclusive/, + }); +}); + +test("validateInstanceConfig throws when PLATFORM_FEE_PERCENT is not finite", () => { + const overrides = { + ...VALID_OVERRIDES, + PLATFORM_FEE_PERCENT: Infinity, + }; + + assert.throws(() => validateInstanceConfig(overrides), { + message: /PLATFORM_FEE_PERCENT must be a finite number/, + }); +}); + +test("validateInstanceConfig throws when THEME_ACCENT_OVERRIDES has invalid hex color", () => { + const overrides = { + ...VALID_OVERRIDES, + THEME_ACCENT_OVERRIDES: { + light: { + accent: "invalid-hex", + }, + }, + }; + + assert.throws(() => validateInstanceConfig(overrides), { + message: /must be a #RRGGBB hex color/, + }); +}); + +test("validateInstanceConfig throws when THEME_ACCENT_OVERRIDES structure is invalid", () => { + const overrides = { + ...VALID_OVERRIDES, + THEME_ACCENT_OVERRIDES: { + light: "not-an-object", + }, + }; + + assert.throws(() => validateInstanceConfig(overrides), { + message: /must be an object with accent overrides/, + }); +}); + +test("validateInstanceConfig throws when optional URL is invalid", () => { + const overrides = { + ...VALID_OVERRIDES, + BLOG_URL: "not-a-valid-url", + }; + + assert.throws(() => validateInstanceConfig(overrides), { + message: /BLOG_URL must be a valid http\(s\) URL/, + }); +}); + +test("validateInstanceConfig throws when optional URL has invalid protocol", () => { + const overrides = { + ...VALID_OVERRIDES, + BLOG_URL: "ftp://example.com", + }; + + assert.throws(() => validateInstanceConfig(overrides), { + message: /BLOG_URL must be a valid http\(s\) URL/, + }); +});