import { test } from 'node:test'; import assert from 'node:assert/strict'; import { loadConfig } from '../src/config.js'; import { applyTestConfig } from './helpers/testConfig.js'; test('loadConfig rejects an incomplete environment', () => { assert.throws(() => loadConfig({ NODE_ENV: 'test' }), /Invalid environment configuration/); }); test('loadConfig never echoes a value in its error message', () => { try { loadConfig({ CHATWOOT_BASE_URL: 'not-a-url', CHATWOOT_API_TOKEN: 'super-secret-value' }); assert.fail('expected a throw'); } catch (err) { assert.ok(err instanceof Error); assert.ok(!err.message.includes('super-secret-value')); } }); test('boolean and csv env values are coerced', () => { const cfg = applyTestConfig({ WORKER_ENABLED: 'yes', STORE_CURRENCIES: 'pln, eur ,czk' }); assert.equal(cfg.WORKER_ENABLED, true); assert.deepEqual(cfg.STORE_CURRENCIES, ['PLN', 'EUR', 'CZK']); }); test('defaults fill in the optional settings', () => { const cfg = applyTestConfig(); assert.equal(cfg.CHATWOOT_TICKET_LABEL, 'ticket'); assert.equal(cfg.TICKET_NUMBER_PREFIX, 'EKS'); assert.equal(cfg.SPAM_GATE_ENABLED, true); });