Files
julian 1e9219d14a Implement Phase 1 tasks 1.1-1.4 (scaffold + core shell + Teltonika framing)
- Project scaffold (Node 22 + TS 5 + pnpm + vitest + ESLint flat config)
- Core shell: TCP server, session loop, adapter registry, types
- Configuration (zod-validated env) and pino logger
- Teltonika adapter: IMEI handshake, frame envelope, CRC-16/IBM,
  codec dispatch registry, DeviceAuthority seam (AllowAllAuthority default)

Codec data parsers (1.5-1.7), Redis publisher (1.8), and downstream
tasks remain. 36 tests covering CRC, framing, handshake, device
authority, config, and core server. typecheck/lint/test/build all clean.
2026-04-30 15:51:07 +02:00

55 lines
1.8 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { loadConfig } from '../src/config/load.js';
describe('loadConfig', () => {
it('throws when REDIS_URL is unset and names REDIS_URL in the error', () => {
expect(() => loadConfig({})).toThrowError(/REDIS_URL/);
});
it('returns a valid Config with sensible defaults when only REDIS_URL is set in development', () => {
const config = loadConfig({
NODE_ENV: 'development',
REDIS_URL: 'redis://localhost:6379',
});
expect(config.NODE_ENV).toBe('development');
expect(config.REDIS_URL).toBe('redis://localhost:6379');
expect(config.TELTONIKA_PORT).toBe(5027);
expect(config.REDIS_TELEMETRY_STREAM).toBe('telemetry:teltonika');
expect(config.REDIS_STREAM_MAXLEN).toBe(1_000_000);
expect(config.METRICS_PORT).toBe(9090);
expect(config.LOG_LEVEL).toBe('info');
expect(config.STRICT_DEVICE_AUTH).toBe(false);
expect(config.INSTANCE_ID).toMatch(/^local-[0-9a-f]{8}$/);
});
it('parses TELTONIKA_PORT as a number from a string env var', () => {
const config = loadConfig({
REDIS_URL: 'redis://localhost:6379',
TELTONIKA_PORT: '5555',
});
expect(config.TELTONIKA_PORT).toBe(5555);
});
it('enables STRICT_DEVICE_AUTH when set to "true"', () => {
const config = loadConfig({
REDIS_URL: 'redis://localhost:6379',
STRICT_DEVICE_AUTH: 'true',
});
expect(config.STRICT_DEVICE_AUTH).toBe(true);
});
it('rejects an invalid NODE_ENV value', () => {
expect(() =>
loadConfig({
REDIS_URL: 'redis://localhost:6379',
NODE_ENV: 'staging',
}),
).toThrow();
});
it('rejects a non-URL REDIS_URL', () => {
expect(() => loadConfig({ REDIS_URL: 'not-a-url' })).toThrowError(/REDIS_URL/);
});
});