mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 23:27:31 +00:00
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.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user