import 'package:flutter_test/flutter_test.dart';
import 'package:rasadyar_core/core.dart';

void main() {
  group('DioResponse', () {
    test('data should return response data', () {
      final response = Response(
        requestOptions: RequestOptions(path: "/"),
        data: 'hello',
      );

      final dioResponse = DioResponse<String>(response);

      expect(dioResponse.data, 'hello');
    });

    test('status Code should return 0 if null', () {
      final response = Response(requestOptions: RequestOptions(path: "/"), statusCode: null);
      final dioResponse = DioResponse(response);

      expect(dioResponse.statusCode, 0);
    });

    test('headers should return response headers map', () {
      final headers = Headers.fromMap({
        'content-type': ['application/json'],
      });
      final response = Response(
        requestOptions: RequestOptions(path: "/"),
        headers: headers,
      );
      final dioResponse = DioResponse(response);

      expect(dioResponse.headers, isA<Map>());
      expect(dioResponse.headers, {
        'content-type': ['application/json'],
      });
    });

    test('isSuccessful should return true for 2xx codes', () {
      final response = Response(requestOptions: RequestOptions(path: "/"), statusCode: 200);
      final dioResponse = DioResponse(response);

      expect(dioResponse.statusCode, 200);

      expect(dioResponse.isSuccessful, true);
    });

    test('isSuccessful should return false for non-2xx codes', () {
      final response = Response(requestOptions: RequestOptions(path: "/"),statusCode: 404);
      final dioResponse = DioResponse(response);

      expect(dioResponse.statusCode, 404);

      expect(dioResponse.isSuccessful, false);

    });
  
  });
}
