Real World Config
Learn about real world config in fp-ts reader
Code Editor
07-real-world-config.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('Real-world configuration', () => {
const config: AppConfig = {
database: {
host: 'db.example.com',
port: 5432,
username: 'admin',
password: 'secret123',
},
api: {
baseUrl: 'https://api.example.com',
apiKey: 'abc123',
timeout: 5000,
},
env: 'production',
}
it('builds database connection URL', () => {
const result = getDatabaseUrl()(config)
expect(result).toBe('postgresql://admin:secret123@db.example.com:5432')
})
it('builds API endpoint with path', () => {
const result = getApiEndpoint('users')(config)
expect(result).toBe('https://api.example.com/users?key=abc123')
})
it('creates config summary', () => {
const result = getConfigSummary()(config)
expect(result).toEqual({
env: 'production',
dbHost: 'db.example.com',
apiUrl: 'https://api.example.com',
})
})
it('checks if production environment', () => {
expect(isProduction()(config)).toBe(true)
const devConfig = { ...config, env: 'development' as const }
expect(isProduction()(devConfig)).toBe(false)
})
it('works with different configurations', () => {
const testConfig: AppConfig = {
...config,
database: { ...config.database, host: 'localhost', port: 5433 },
env: 'test',
}
expect(getDatabaseUrl()(testConfig)).toBe('postgresql://admin:secret123@localhost:5433')
expect(isProduction()(testConfig)).toBe(false)
})
})🧪
Ready to Test?
Click "Run Tests" to see how your code performs
Quick Tips
•Read the TODO comments in the code
•Use Reset to restore original code
•Check Solution if stuck
Pro Tips
💡 Stuck? Here's what to try:
- • Read the comments in the code carefully
- • Run tests frequently to get feedback
- • Check the fp-ts documentation
- • Use the solution if you need help
🚀 Learning Approach:
- • Focus on understanding, not just solving
- • Experiment with different approaches
- • Think about real-world applications
- • Build on previous exercises