import { describe, expect, it } from 'vitest'; import { getServiceUrlWithRoute, joinPath } from '../../utils/url'; describe('url utils', () => { describe('getServiceUrlWithRoute', () => { it('should return url', () => { expect(getServiceUrlWithRoute('https://example.com', '/route')).toEqual('https://example.com/route'); expect(getServiceUrlWithRoute('https://example.com/', '/route')).toEqual('https://example.com/route'); expect(getServiceUrlWithRoute('https://example.com/', 'route')).toEqual('https://example.com/route'); expect(getServiceUrlWithRoute('https://example.com', 'route')).toEqual('https://example.com/route'); expect(getServiceUrlWithRoute('https://example.com/', '/route/')).toEqual('https://example.com/route/'); expect(getServiceUrlWithRoute('https://example.com', 'route/')).toEqual('https://example.com/route/'); }); it('should handle complex service URL', () => { expect(getServiceUrlWithRoute('https://example.com:555', '/route')).toEqual('https://example.com:555/route'); expect(getServiceUrlWithRoute('https://user:pass@example.com:555/base/path', '/route')) .toEqual('https://user:pass@example.com:555/base/path/route'); expect(getServiceUrlWithRoute('https://example.com:555/base/path?a=1&b=2#search', '/route')) .toEqual('https://example.com:555/base/path/route?a=1&b=2#search'); }); it('should handle routes with spaces', () => { expect(getServiceUrlWithRoute('https://example.com', '/route/ key')).toEqual('https://example.com/route/%20key'); expect(getServiceUrlWithRoute('https://example.com/ base', '/route')) .toEqual('https://example.com/%20base/route'); }); }); describe('joinPath', () => { it('should handle edge-cases', () => { expect(joinPath()).toEqual('/'); expect(joinPath('', '')).toEqual('/'); expect(joinPath('/a/b/c')).toEqual('/a/b/c'); }); it('should join two paths', () => { expect(joinPath('/', '/')).toEqual('/'); expect(joinPath('/', ' /')).toEqual('/ /'); expect(joinPath('/', ' / ')).toEqual('/ / '); expect(joinPath('/', '/a/b/c')).toEqual('/a/b/c'); expect(joinPath('/', 'a/b/c')).toEqual('/a/b/c'); expect(joinPath('/a', '/b/c')).toEqual('/a/b/c'); expect(joinPath('/a', 'b/c')).toEqual('/a/b/c'); expect(joinPath('/a/', 'b/c')).toEqual('/a/b/c'); expect(joinPath('/a/', 'b/c/')).toEqual('/a/b/c/'); expect(joinPath('a', 'b/c/')).toEqual('/a/b/c/'); expect(joinPath('a', '/b/c/')).toEqual('/a/b/c/'); }); it('should 3+ paths', () => { expect(joinPath('', '', '')).toEqual('/'); expect(joinPath(' ', ' ', ' ')).toEqual('/ / / '); expect(joinPath('/', '/', '/')).toEqual('/'); expect(joinPath('/', '/a/b', '/c')).toEqual('/a/b/c'); expect(joinPath('/', '/a/b', 'c')).toEqual('/a/b/c'); expect(joinPath('/a', '/b', 'c/')).toEqual('/a/b/c/'); expect(joinPath('/a/', '/b', '/c/')).toEqual('/a/b/c/'); expect(joinPath('a', 'b', 'c')).toEqual('/a/b/c'); }); }); });