import 'package:flutter_test/flutter_test.dart';
import 'package:showen_v2_flutter/services/http_api_service.dart';

void main() {
  group('HttpApiService.normalizeBaseUrl', () {
    test('trims whitespace, adds scheme, and removes trailing slash', () {
      expect(
        HttpApiService.normalizeBaseUrl('  192.168.1.8:5000/  '),
        'http://192.168.1.8:5000',
      );
    });

    test('preserves explicit https scheme', () {
      expect(
        HttpApiService.normalizeBaseUrl('https://showen.local/'),
        'https://showen.local',
      );
    });

    test('throws for empty baseUrl', () {
      expect(
        () => HttpApiService.normalizeBaseUrl('   '),
        throwsA(
          isA<ApiException>().having(
            (error) => error.message,
            'message',
            'baseUrl 不能为空',
          ),
        ),
      );
    });
  });

  group('ApiException', () {
    test('stores message and optional status code', () {
      const exception = ApiException('upload failed', statusCode: 413);

      expect(exception.message, 'upload failed');
      expect(exception.statusCode, 413);
      expect(exception.toString(), 'upload failed');
    });
  });
}
