import { getSafeRedirectUrl } from './safe-redirect';

describe('getSafeRedirectUrl', () => {
	it('returns fallback when raw is empty', () => {
		expect(getSafeRedirectUrl(null)).toBe('/dashboard/rests');
		expect(getSafeRedirectUrl(undefined)).toBe('/dashboard/rests');
		expect(getSafeRedirectUrl('')).toBe('/dashboard/rests');
	});

	it('allows relative in-app paths', () => {
		expect(getSafeRedirectUrl('/accounts')).toBe('/accounts');
		expect(getSafeRedirectUrl('%2Fdashboard%2Frests')).toBe('/dashboard/rests');
	});

	it('blocks open redirects', () => {
		expect(getSafeRedirectUrl('//evil.com')).toBe('/dashboard/rests');
		expect(getSafeRedirectUrl('https://evil.com')).toBe('/dashboard/rests');
		expect(getSafeRedirectUrl('http://evil.com')).toBe('/dashboard/rests');
		expect(getSafeRedirectUrl('/path?next=https://evil.com')).toBe('/dashboard/rests');
	});
});

