feature flags

This commit is contained in:
2026-01-06 12:40:58 +01:00
parent 6aad7897db
commit c55ef731a1
11 changed files with 517 additions and 30 deletions

View File

@@ -0,0 +1,43 @@
/**
* Integration test to verify the feature flag system works end-to-end
*/
import { describe, it, expect, beforeAll } from 'vitest';
import { loadFeatureConfig, isFeatureEnabled, getFeatureState } from './feature-loader';
describe('Feature Flag Integration Test', () => {
it('should load config and provide correct feature states', async () => {
// Set test environment
process.env.NODE_ENV = 'test';
const result = await loadFeatureConfig();
// Verify config loaded from file
expect(result.loadedFrom).toBe('config-file');
expect(result.configPath).toBe('apps/api/src/config/features.config.ts');
// Verify specific features from our config
expect(result.features['sponsors.portal']).toBe('enabled');
expect(result.features['sponsors.dashboard']).toBe('enabled');
expect(result.features['admin.dashboard']).toBe('enabled');
expect(result.features['beta.newUI']).toBe('disabled');
// Verify utility functions work
expect(isFeatureEnabled(result.features, 'sponsors.portal')).toBe(true);
expect(isFeatureEnabled(result.features, 'beta.newUI')).toBe(false);
expect(getFeatureState(result.features, 'sponsors.portal')).toBe('enabled');
expect(getFeatureState(result.features, 'nonexistent')).toBe('disabled');
});
it('should work with different environments', async () => {
// Test development environment
process.env.NODE_ENV = 'development';
const devResult = await loadFeatureConfig();
expect(devResult.features['beta.newUI']).toBe('enabled'); // dev has beta enabled
// Test production environment
process.env.NODE_ENV = 'production';
const prodResult = await loadFeatureConfig();
expect(prodResult.features['beta.newUI']).toBe('disabled'); // prod has beta disabled
});
});