|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { loadConfig } from '../../src/config' |
| 3 | + |
| 4 | +describe('Config', () => { |
| 5 | + it('should load default configuration', () => { |
| 6 | + const config = loadConfig() |
| 7 | + |
| 8 | + expect(config).toBeDefined() |
| 9 | + expect(config.server.name).toBe('sufetch-mcp') |
| 10 | + expect(config.server.version).toBe('0.3.0') |
| 11 | + }) |
| 12 | + |
| 13 | + it('should have default cache settings', () => { |
| 14 | + const config = loadConfig() |
| 15 | + |
| 16 | + expect(config.cache.exampleSize).toBe(100) |
| 17 | + expect(config.cache.exampleTTL).toBe(5 * 60 * 1000) // 5 minutes |
| 18 | + }) |
| 19 | + |
| 20 | + it('should have default HTTP settings', () => { |
| 21 | + const config = loadConfig() |
| 22 | + |
| 23 | + expect(config.http.methods).toContain('get') |
| 24 | + expect(config.http.methods).toContain('post') |
| 25 | + expect(config.http.successCodes).toContain(200) |
| 26 | + expect(config.http.successCodes).toContain(201) |
| 27 | + }) |
| 28 | + |
| 29 | + it('should respect SUFETCH_DEBUG environment variable', () => { |
| 30 | + const originalValue = process.env.SUFETCH_DEBUG |
| 31 | + |
| 32 | + process.env.SUFETCH_DEBUG = 'true' |
| 33 | + const configWithDebug = loadConfig() |
| 34 | + expect(configWithDebug.debug).toBe(true) |
| 35 | + |
| 36 | + process.env.SUFETCH_DEBUG = 'false' |
| 37 | + const configWithoutDebug = loadConfig() |
| 38 | + expect(configWithoutDebug.debug).toBe(false) |
| 39 | + |
| 40 | + // Restore original value |
| 41 | + if (originalValue === undefined) { |
| 42 | + delete process.env.SUFETCH_DEBUG |
| 43 | + } |
| 44 | + else { |
| 45 | + process.env.SUFETCH_DEBUG = originalValue |
| 46 | + } |
| 47 | + }) |
| 48 | + |
| 49 | + it('should have schema configuration', () => { |
| 50 | + const config = loadConfig() |
| 51 | + |
| 52 | + expect(config.schemas.identifierFields).toContain('id') |
| 53 | + expect(config.schemas.identifierFields).toContain('uuid') |
| 54 | + expect(config.schemas.importantFieldPatterns).toContain('name') |
| 55 | + expect(config.schemas.importantFieldPatterns).toContain('title') |
| 56 | + }) |
| 57 | + |
| 58 | + it('should have example value defaults', () => { |
| 59 | + const config = loadConfig() |
| 60 | + |
| 61 | + expect(config.exampleValues.defaultEmail).toBe('user@example.com') |
| 62 | + expect(config.exampleValues.defaultUrl).toBe('https://example.com') |
| 63 | + expect(config.exampleValues.defaultNumber).toBe(10) |
| 64 | + expect(config.exampleValues.defaultInteger).toBe(1) |
| 65 | + expect(config.exampleValues.defaultBoolean).toBe(true) |
| 66 | + expect(config.exampleValues.getCurrentTimestamp).toBeDefined() |
| 67 | + expect(typeof config.exampleValues.getCurrentTimestamp()).toBe('string') |
| 68 | + }) |
| 69 | +}) |
0 commit comments