import 'dart:convert'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/onboarding/discovery/browser_server_discovery.dart'; void main() { test( 'browser parses names, default ports, auth and deduplicates endpoints', () async { final scan = BrowserServerDiscovery( fetch: () async => jsonEncode({ 'discovered_servers': [ { 'name': 'Linux', 'endpoint': 'ws://192.168.1.5:8083/connect', 'auth': 'password', 'version': 'v1', }, { 'name': 'Linux', 'endpoint': 'ws://192.168.1.5:8083/connect', 'auth': 'password', }, { 'name': 'Mac', 'endpoint': 'wss://mac.local/connect', 'auth': 'none', }, {'name': 'Bad', 'endpoint': 'ws://password@host/connect'}, {'name': '', 'endpoint': 'ws://host/connect'}, {'name': 'Fragment', 'endpoint': 'ws://host/connect#secret'}, ], }), ); final values = await scan.scan().single; expect(values.map((s) => s.name), ['Linux', 'Mac']); expect(values.first.passwordRequired, isTrue); expect(values.last.passwordRequired, isFalse); expect(values.last.port, 443); }, ); test('unknown and malformed discovery responses report failure', () async { for (final body in ['not json', '{}', '{"discovered_servers":null}']) { await expectLater( BrowserServerDiscovery(fetch: () async => body).scan(), emitsError(isA()), ); } }); test( 'network failure is surfaced instead of pretending no machines exist', () async { await expectLater( BrowserServerDiscovery( fetch: () async => throw StateError('offline'), ).scan(), emitsError(isA()), ); }, ); }