Files
dbmole-mcp/packages/esmole-mcp/test/unit/schema.test.ts
T
2026-06-16 20:44:11 +05:00

68 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { connectionConfigSchema, defaultPort } from '../../src/schema.js'
describe('esmole connectionConfigSchema', () => {
it('accepts a basic-auth connection with scheme/verifyTls/readonly defaults', () => {
const c = connectionConfigSchema.parse({
name: 'es1',
host: 'es.local',
type: 'elasticsearch',
user: 'elastic',
password: 'p'
})
expect(c.scheme).toBe('https')
expect(c.verifyTls).toBe(true)
expect(c.readonly).toBe(false)
})
it('accepts an apiKey connection without user/password', () => {
const c = connectionConfigSchema.parse({
name: 'es2',
host: 'es.local',
type: 'elasticsearch',
apiKey: 'abc=='
})
expect(c.apiKey).toBe('abc==')
})
it('rejects a connection with neither user/password nor apiKey', () => {
expect(() =>
connectionConfigSchema.parse({ name: 'es3', host: 'es.local', type: 'elasticsearch' })
).toThrow()
})
it('rejects a connection with user but no password and no apiKey', () => {
expect(() =>
connectionConfigSchema.parse({
name: 'es3b',
host: 'es.local',
type: 'elasticsearch',
user: 'elastic'
})
).toThrow()
})
it('rejects unknown keys (strict)', () => {
expect(() =>
connectionConfigSchema.parse({
name: 'es4',
host: 'h',
type: 'elasticsearch',
apiKey: 'x',
bogus: 1
})
).toThrow()
})
it('allows http scheme + verifyTls false for 7.x dev', () => {
const c = connectionConfigSchema.parse({
name: 'es5',
host: 'h',
type: 'elasticsearch',
apiKey: 'x',
scheme: 'http',
verifyTls: false
})
expect(c.scheme).toBe('http')
expect(c.verifyTls).toBe(false)
})
it('defaultPort is 9200', () => {
expect(defaultPort()).toBe(9200)
})
})