import { describe, expect, it } from 'vitest' import { targetAppFromReturnTo } from '../src/lib/target-app.js' describe('targetAppFromReturnTo', () => { it('maps dns host and /sso/ path', () => { expect(targetAppFromReturnTo('https://dns.shnt.top/sso/callback')).toBe( 'dns', ) }) it('unwraps portal /oauth/authorize return_to via redirect_uri', () => { const returnTo = 'https://auth.shnt.top/oauth/authorize?client_id=abc&redirect_uri=' + encodeURIComponent('https://dns.shnt.top/sso/callback') + '&response_type=code&scope=openid' expect(targetAppFromReturnTo(returnTo)).toBe('dns') }) it('keeps portal for bare issuer authorize without redirect_uri', () => { expect( targetAppFromReturnTo('https://auth.shnt.top/oauth/authorize'), ).toBe('portal') }) it('maps cdn host', () => { expect(targetAppFromReturnTo('https://cdn.shnt.top/auth/callback')).toBe( 'cdn', ) }) it('maps mm host', () => { expect(targetAppFromReturnTo('https://mm.shnt.top/auth/callback')).toBe( 'mm', ) }) })