import 'package:chat_server/src/handlers/auth_handlers.dart'; import 'package:test/test.dart'; void main() { group('normalizeHomeServer', () { test('normalizes host without scheme', () { expect( normalizeHomeServer('chat.example.com'), 'https://chat.example.com', ); expect( normalizeHomeServer('localhost:9870'), 'http://localhost:9870', ); }); test('strips trailing slash/path/query/fragment', () { expect( normalizeHomeServer('https://example.com/a/b?x=1#y'), 'https://example.com', ); expect( normalizeHomeServer('https://example.com/'), 'https://example.com', ); }); test('returns null for invalid input', () { expect(normalizeHomeServer(''), isNull); expect(normalizeHomeServer('://bad'), isNull); }); }); group('defaultSchemeForHost', () { test('returns http for localhost-style hosts', () { expect(defaultSchemeForHost('localhost:9870'), 'http'); expect(defaultSchemeForHost('127.0.0.1:9870'), 'http'); expect(defaultSchemeForHost('[::1]:9870'), 'http'); }); test('returns https for non-local hosts', () { expect(defaultSchemeForHost('chat.example.com'), 'https'); }); }); group('toUserHandle', () { test('uses URL host and port', () { expect( toUserHandle('alice', 'https://chat.example.com:8443'), '@alice@chat.example.com:8443', ); }); test('falls back to raw home server string', () { expect( toUserHandle('alice', 'chat.example.com'), '@alice@chat.example.com', ); }); }); }