import 'dart:convert'; import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:reelbox/data/api_service.dart'; import 'package:reelbox/data/models.dart'; import 'package:shared_preferences/shared_preferences.dart'; class _LiveNetwork extends HttpOverrides {} void main() { TestWidgetsFlutterBinding.ensureInitialized(); test( 'deployed Iran Catalogue works through the real app API client', () async { // Explicit opt-in live test; only local preferences are mocked. // ignore: invalid_use_of_visible_for_testing_member SharedPreferences.setMockInitialValues({}); await HttpOverrides.runWithHttpOverrides(() async { final api = ApiService(); await api.setBaseUrl('https://reelbox.dartty.top/api/'); await api.initialize(); expect(api.baseUrl, 'https://reelbox.dartty.top/api/'); final home = await api.home(); final genres = await api.genres(); final countries = await api.countries(); final movies = await api.catalog(); final series = await api.catalog(kind: 'serie'); expect(home['genres'], isNotEmpty); expect(genres, isNotEmpty); expect(countries, isNotEmpty); expect(movies, isNotEmpty); expect(series, isNotEmpty); TitleRecord? film; for (final candidate in movies.take(5)) { final detail = await api.poster(candidate.id); if (detail.sources.isNotEmpty) { film = detail; break; } } expect(film, isNotNull); final seasons = await api.seasons(series.first.id); expect(seasons, isNotEmpty); final episodeSources = seasons .expand((s) => s.episodes) .expand((e) => e.sources); expect(episodeSources, isNotEmpty); final allSources = [...film!.sources, ...episodeSources]; for (final source in allSources) { final uri = Uri.parse(source.url); expect(uri.scheme, anyOf('http', 'https')); expect(uri.host, isNot('reelbox.dartty.top')); expect(uri.host, isNot('87.107.110.187')); } final search = await api.search('Matrix', english: true); final recommendations = await api.bestRandom(); final curated = await api.curatedLinks(); expect(search, isNotEmpty); expect(recommendations, isNotEmpty); if (curated.isNotEmpty) { expect( await api.curatedContent(curated.first['link'] as String), isNotEmpty, ); } expect(await api.comments(film.id), isEmpty); final restored = ApiService(); await restored.initialize(discover: false); expect(restored.baseUrl, api.baseUrl); stdout.writeln( jsonEncode({ 'api_base': api.baseUrl, 'genre_count': genres.length, 'country_count': countries.length, 'movie_page_count': movies.length, 'series_page_count': series.length, 'movie_id': film.id, 'movie_sources': film.sources.length, 'series_id': series.first.id, 'season_count': seasons.length, 'episode_sources': episodeSources.length, 'search_count': search.length, 'recommendations': recommendations.length, 'curated_groups': curated.length, 'all_media_sources_direct': true, 'api_choice_restored': true, 'media_downloaded': false, }), ); }, _LiveNetwork()); }, timeout: const Timeout(Duration(minutes: 3)), ); }