import 'package:dio/dio.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:minstrel/api/client.dart'; void main() { test('client attaches Bearer token from token resolver', () async { final d = ApiClient.buildDio( baseUrl: 'http://example/', tokenResolver: () async => 'tok-123', ); Map? captured; d.interceptors.add( InterceptorsWrapper(onRequest: (opts, h) { captured = Map.from(opts.headers); h.reject(DioException(requestOptions: opts, type: DioExceptionType.cancel)); }), ); try { await d.get('/whatever'); } catch (_) {} expect(captured?['Authorization'], 'Bearer tok-123'); }); test('client omits Authorization when resolver returns null', () async { final d = ApiClient.buildDio( baseUrl: 'http://example/', tokenResolver: () async => null, ); Map? captured; d.interceptors.add( InterceptorsWrapper(onRequest: (opts, h) { captured = Map.from(opts.headers); h.reject(DioException(requestOptions: opts, type: DioExceptionType.cancel)); }), ); try { await d.get('/whatever'); } catch (_) {} expect(captured?.containsKey('Authorization'), isFalse); }); }