// ignore_for_file: depend_on_referenced_packages

@TestOn('browser')
library;

import 'package:test/test.dart';

import 'package:alt_client/src/integrations/socket/alt_socket_client.dart';
import 'package:alt_client/src/integrations/socket/socket_endpoint.dart';

void main() {
  test(
    'connects from Chrome runtime to ALT API and completes hello handshake',
    () async {
      const endpoint = AltSocketEndpoint(
        host: String.fromEnvironment(
          'ALT_SOCKET_HOST',
          defaultValue: '127.0.0.1',
        ),
        port: int.fromEnvironment('ALT_SOCKET_PORT', defaultValue: 13000),
        path: String.fromEnvironment(
          'ALT_SOCKET_PATH',
          defaultValue: '/socket',
        ),
      );

      final client = await AltSocketClient.connect(endpoint);
      addTearDown(client.close);

      final response = await client.hello(timeout: const Duration(seconds: 5));

      expect(response.serverName, equals('alt-api'));
      expect(response.serverVersion, equals('dev'));
      expect(response.altProtocolVersion, equals('alt.v1'));
      expect(response.capabilities, contains('hello'));
      expect(response.capabilities, contains('request-response'));
    },
  );
}
