feature flags
This commit is contained in:
43
apps/api/src/config/integration.test.ts
Normal file
43
apps/api/src/config/integration.test.ts
Normal 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
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user