mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-27 07:51:52 +00:00
Verify hardcoded relays are moved and add regression tests
- Verified that `src/lib.mjs` no longer contains hardcoded relay URLs. - Confirmed `DEFAULT_RELAYS` are defined in `src/constants.mjs` and used in `src/torch-config.mjs`. - Added regression tests in `test/torch-config.test.mjs` to ensure `getRelays()` correctly falls back to `DEFAULT_RELAYS` and prioritizes environment variables. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
695adb6dc9
commit
56694d14d2
1 file changed
+31
-1
@@ -2,7 +2,8 @@ import { test, describe, it, after, beforeEach } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { getTorchConfigPath, parseTorchConfig, loadTorchConfig, _resetTorchConfigCache } from '../src/torch-config.mjs';
|
||||
import { getTorchConfigPath, parseTorchConfig, loadTorchConfig, _resetTorchConfigCache, getRelays } from '../src/torch-config.mjs';
|
||||
import { DEFAULT_RELAYS } from '../src/constants.mjs';
|
||||
|
||||
describe('torch-config', () => {
|
||||
describe('getTorchConfigPath', () => {
|
||||
@@ -181,4 +182,33 @@ describe('torch-config', () => {
|
||||
assert.strictEqual(config1, config2, 'Should be the same object');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRelays', () => {
|
||||
const originalEnv = process.env.NOSTR_LOCK_RELAYS;
|
||||
|
||||
beforeEach(() => {
|
||||
_resetTorchConfigCache();
|
||||
delete process.env.NOSTR_LOCK_RELAYS;
|
||||
});
|
||||
|
||||
after(() => {
|
||||
if (originalEnv === undefined) {
|
||||
delete process.env.NOSTR_LOCK_RELAYS;
|
||||
} else {
|
||||
process.env.NOSTR_LOCK_RELAYS = originalEnv;
|
||||
}
|
||||
_resetTorchConfigCache();
|
||||
});
|
||||
|
||||
it('returns default relays when no config or env var is set', () => {
|
||||
const relays = getRelays();
|
||||
assert.deepStrictEqual(relays, DEFAULT_RELAYS);
|
||||
});
|
||||
|
||||
it('returns relays from env var if set', () => {
|
||||
process.env.NOSTR_LOCK_RELAYS = 'wss://env.relay,wss://env.relay2';
|
||||
const relays = getRelays();
|
||||
assert.deepStrictEqual(relays, ['wss://env.relay', 'wss://env.relay2']);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user