From f52eceacaf4ed0128a333d8e3551e877558d29e2 Mon Sep 17 00:00:00 2001 From: DevContributor Date: Tue, 28 Jul 2026 00:07:46 +0900 Subject: [PATCH] test: add unit tests for mcpPath utility --- test/utils/mcpPath.test.ts | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/utils/mcpPath.test.ts diff --git a/test/utils/mcpPath.test.ts b/test/utils/mcpPath.test.ts new file mode 100644 index 0000000..31a5b85 --- /dev/null +++ b/test/utils/mcpPath.test.ts @@ -0,0 +1,48 @@ +import { normalizeMcpPath, getCompatibleMcpPaths } from '../../src/utils/mcpPath' + +describe('normalizeMcpPath', () => { + it('returns default "/" when value is undefined', () => { + expect(normalizeMcpPath(undefined)).toBe('/') + }) + + it('returns default "/" when value is empty string', () => { + expect(normalizeMcpPath('')).toBe('/') + }) + + it('returns default "/" when value is whitespace', () => { + expect(normalizeMcpPath(' ')).toBe('/') + }) + + it('preserves value that starts with /', () => { + expect(normalizeMcpPath('/custom')).toBe('/custom') + }) + + it('prepends / when value does not start with /', () => { + expect(normalizeMcpPath('custom')).toBe('/custom') + }) + + it('trims whitespace from value', () => { + expect(normalizeMcpPath(' /path ')).toBe('/path') + }) + + it('uses custom default when value is empty', () => { + expect(normalizeMcpPath(undefined, '/alt')).toBe('/alt') + }) +}) + +describe('getCompatibleMcpPaths', () => { + it('returns both "/" and "/mcp" for root path', () => { + const paths = getCompatibleMcpPaths('/') + expect(paths).toEqual(new Set(['/', '/mcp'])) + }) + + it('returns both "/" and "/mcp" for /mcp path', () => { + const paths = getCompatibleMcpPaths('/mcp') + expect(paths).toEqual(new Set(['/', '/mcp'])) + }) + + it('returns only the configured path for custom paths', () => { + const paths = getCompatibleMcpPaths('/custom') + expect(paths).toEqual(new Set(['/custom'])) + }) +})