Files
carmanagement/carplace/src/lib/appUrls.test.ts
T
root c77d0a8e89
Build & Push / Build & Push Docker Image (push) Failing after 10m39s
Rename legacy storefront app and references to carplace
Replace storefront naming across source, tests, docs, config, and production scripts. Rename the legacy top-level app directory and Carplace component files, remove duplicate storefront startup scripts, and refresh the lockfile.
2026-07-04 18:10:08 -04:00

41 lines
1.7 KiB
TypeScript

import { afterEach, describe, expect, it } from 'vitest'
import { resolveBrowserAppUrl, resolveServerAppUrl } from './appUrls'
function installWindow(hostname: string, protocol = 'https:') {
Object.defineProperty(globalThis, 'window', {
configurable: true,
value: { location: { hostname, protocol } },
})
}
afterEach(() => {
Reflect.deleteProperty(globalThis, 'window')
})
describe('carplace app URL resolution', () => {
it('leaves server-side browser fallback unchanged when window is unavailable', () => {
expect(resolveBrowserAppUrl('http://localhost:3000')).toBe('http://localhost:3000')
})
it('preserves localhost fallbacks but removes trailing slash', () => {
installWindow('localhost')
expect(resolveBrowserAppUrl('http://localhost:3000/')).toBe('http://localhost:3000')
})
it('rewrites production browser fallbacks to the active host and protocol', () => {
installWindow('www.rentaldrivego.ma', 'https:')
expect(resolveBrowserAppUrl('http://localhost:3000')).toBe('https://www.rentaldrivego.ma')
})
it('keeps path prefixes while rewriting the browser origin', () => {
installWindow('rental.example.com', 'https:')
expect(resolveBrowserAppUrl('http://localhost:3000/carplace')).toBe('https://rental.example.com/carplace')
})
it('resolves server URLs from forwarded host/proto and handles invalid fallbacks safely', () => {
expect(resolveServerAppUrl('http://localhost:3000', 'market.example.com', 'https')).toBe('https://market.example.com:3000')
expect(resolveServerAppUrl('http://localhost:3000', null)).toBe('http://localhost:3000')
expect(resolveServerAppUrl('/relative', 'market.example.com')).toBe('/relative')
})
})