Files

18 lines
882 B
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { parseApiUrl } from '../src/config.ts';
test('normalizes the API base without losing the reverse proxy path', () => {
assert.equal(parseApiUrl(' https://delivery.example.test/api/ '), 'https://delivery.example.test/api');
assert.equal(parseApiUrl(''), null);
});
test('rejects insecure production URLs and embedded credentials', () => {
for (const value of ['http://localhost:3001', 'https://user:secret@example.test/api', 'https://example.test/api?token=secret', 'https://example.test/api#token', 'file:///tmp/api']) {
assert.throws(() => parseApiUrl(value));
}
});
test('permits only emulator/loopback HTTP in development', () => {
assert.equal(parseApiUrl('http://10.0.2.2:3001', true), 'http://10.0.2.2:3001');
assert.throws(() => parseApiUrl('http://example.test', true));
});