Files
TREK/server/tests/unit/helpers/test-config.test.ts
T
Maurice 00cbc5aae3 test(server): src/config takes fixed test values from the setup file, so suites stop mocking it
tests/setup.ts mocks src/config once with tests/helpers/test-config.ts. A suite that needs other values calls overrideTestConfig(), and the setup file restores the defaults after every case. The 191 per-file factories are gone; config.test.ts takes the real module through vi.unmock, and the few suites that signed tokens with their own literal secret read it from TEST_CONFIG.
2026-10-10 20:16:10 +02:00

44 lines
1.8 KiB
TypeScript

import * as config from '../../../src/config';
import { TEST_CONFIG, overrideTestConfig, resetTestConfig } from '../../helpers/test-config';
import { describe, it, expect } from 'vitest';
describe('test config', () => {
it('is what src/config answers in every suite', () => {
expect(config.JWT_SECRET).toBe('test-jwt-secret-for-trek-testing-only');
expect(config.ENCRYPTION_KEY).toBe(TEST_CONFIG.ENCRYPTION_KEY);
expect(config.DEFAULT_LANGUAGE).toBe('en');
expect(config.SESSION_DURATION_SECONDS).toBe(86400);
expect(config.SESSION_DURATION_REMEMBER_MS).toBe(2592000000);
});
it('keeps updateJwtSecret inert, so a rotation in one case does not leak into the next', () => {
config.updateJwtSecret('rotated');
expect(config.JWT_SECRET).toBe('test-jwt-secret-for-trek-testing-only');
});
it('overrideTestConfig changes what src/config answers until the restore runs', () => {
const restore = overrideTestConfig({ JWT_SECRET: 'other-secret', DEFAULT_LANGUAGE: 'de' });
expect(config.JWT_SECRET).toBe('other-secret');
expect(config.DEFAULT_LANGUAGE).toBe('de');
restore();
expect(config.JWT_SECRET).toBe('test-jwt-secret-for-trek-testing-only');
expect(config.DEFAULT_LANGUAGE).toBe('en');
});
it('leaves an override in place for the rest of its own case', () => {
overrideTestConfig({ ENCRYPTION_KEY: 'case-local-key' });
expect(config.ENCRYPTION_KEY).toBe('case-local-key');
});
it('starts the next case from the defaults again', () => {
expect(config.ENCRYPTION_KEY).toBe('a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6a7b8c9d0e1f2a3b4c5d6a7b8c9d0e1f2');
});
it('resetTestConfig puts every value back', () => {
overrideTestConfig({ SESSION_DURATION_SECONDS: 5 });
resetTestConfig();
expect(config.SESSION_DURATION_SECONDS).toBe(86400);
});
});