|
| 1 | +import { describe, expect, it } from 'bun:test'; |
| 2 | +import { getProxyModeBasePath } from './proxy'; |
| 3 | + |
| 4 | +describe('getProxyModeBasePath', () => { |
| 5 | + it('should return the base path for proxy mode (base = /, path = /)', () => { |
| 6 | + const input = new URL('https://example.com/docs'); |
| 7 | + const resolved = { basePath: '/', pathname: '/' }; |
| 8 | + expect(getProxyModeBasePath(input, resolved)).toEqual('/docs/'); |
| 9 | + }); |
| 10 | + |
| 11 | + it('should return the base path for proxy mode (base = /, path = /hello/world)', () => { |
| 12 | + const input = new URL('https://example.com/docs/hello/world'); |
| 13 | + const resolved = { basePath: '/', pathname: '/hello/world' }; |
| 14 | + expect(getProxyModeBasePath(input, resolved)).toEqual('/docs/'); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should return the base path for proxy mode (base = /v1, path = /)', () => { |
| 18 | + const input = new URL('https://example.com/docs/v1'); |
| 19 | + const resolved = { basePath: '/v1', pathname: '/' }; |
| 20 | + expect(getProxyModeBasePath(input, resolved)).toEqual('/docs/v1/'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should return the base path for proxy mode (base = /v1/, path = /)', () => { |
| 24 | + const input = new URL('https://example.com/docs/v1/'); |
| 25 | + const resolved = { basePath: '/v1/', pathname: '/' }; |
| 26 | + expect(getProxyModeBasePath(input, resolved)).toEqual('/docs/v1/'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should return the base path for proxy mode (base = /v1, path = /hello/world)', () => { |
| 30 | + const input = new URL('https://example.com/docs/v1/hello/world'); |
| 31 | + const resolved = { basePath: '/v1', pathname: '/hello/world' }; |
| 32 | + expect(getProxyModeBasePath(input, resolved)).toEqual('/docs/v1/'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should return the base path for proxy mode (base = /v1/, path = /hello/world)', () => { |
| 36 | + const input = new URL('https://example.com/docs/v1/hello/world'); |
| 37 | + const resolved = { basePath: '/v1/', pathname: '/hello/world' }; |
| 38 | + expect(getProxyModeBasePath(input, resolved)).toEqual('/docs/v1/'); |
| 39 | + }); |
| 40 | +}); |
0 commit comments