feat(paises): add country browser and extract shared radio transport

Extracts ServicioRadio's transport loop (server discovery, host rotation,
bounded retries, User-Agent, timeout, status check, json.decode, sticky-host
bookkeeping) out of `_get` into a new `_getJson(path, params) ->
Future<List<dynamic>>` helper, moved as one block with no logic edits. `_get`
is reimplemented on top, still owning every station-specific concern:
`lastcheckok: '1'`, `Emisora.fromApi` + the empty-uuid/url filter, and the
`_compararCalidad` quality sort. `_getJson` is deliberately sort-agnostic and
filter-agnostic so a non-station endpoint can reuse the resilience behaviour
without inheriting station-only semantics.

Non-negotiable ordering followed per design ADR-4: new
test/servicios/servicio_radio_transporte_test.dart characterises all 8
existing station calls (7 via `_get` plus `registrarClick`, which builds its
own URI) against the UNMODIFIED `_get` first - green by construction -
pinning path, lastcheckok=1, hidebroken=true, a non-empty User-Agent, exact
order/reverse/limit/offset, and the exact returned UUID sequence from a
fixture with deliberately shuffled bitrate/clickcount/votes. That last
assertion is what makes the extraction safe: a sort that silently sank into
transport would pass every other check. Re-running the same file after the
extraction is byte-identical green. test/servicios/servicio_radio_test.dart
is untouched by this work unit - its passing unmodified is itself a signal
that transport wasn't disturbed.

The 6 pre-existing `order: bitrate` occurrences (obtenerPopulares,
buscarPorNombre, buscarPorPais, buscarPorIdioma, buscarPorTag, buscar) are
untouched - a deliberate server-side quality bias deciding which stations
return within `limit`, unrelated to and never to be confused with the
user-facing "Ordenar" control, which stays entirely client-side via the
existing OrdenEmisoras (Engram reference/radio-browser-sort-order).

Behaviour delta, accepted per ADR-4, not a regression: moving
`_servidorActual` bookkeeping into `_getJson` means a successful
`/json/countries` call now warms the sticky host for subsequent station
calls too - one shared warm mirror per instance, desirable, not per-call-type
state.

Adds the Paises browser over the verified `/json/countries` contract (Engram
reference/radio-browser-countries-endpoint): new lib/modelos/pais_radio.dart
(`PaisRadio.fromApi` parses `stationcount` via `int.tryParse` since the API
returns it as a JSON string, not an int - an `as int` cast would throw),
`obtenerPaises()` sends neither `lastcheckok` nor `order` (the screen sorts
client-side by name; the API's raw byte order isn't proper collation for any
locale this app ships), and inherits `hidebroken=true` from the unchanged
`_uri` (desirable here too, since the endpoint's own default is false).
`EstadoBusqueda` gains `paises`/`cargandoPaises`/`cargarPaises()` with an
in-memory cache guard so re-entering the screen never refetches.

New PantallaPaises (lib/pantallas/pantalla_paises.dart): a "Tus idiomas"
shortlist (one representative country per the app's 13 supported locales,
matched against the fetched list - the proposal/spec name this section but
don't specify its derivation) above the full alphabetical list, each entry
showing its parsed station count. Reachable from Buscar's discovery landing
state via a new entry row, added now rather than left dangling per this
file's own forward-reference comment (and the WU15/WU15b lesson: a
fully-tested but unreachable screen is a real defect, not a follow-up).

New ARB keys (en/es only, matching this change's established precedent):
countriesScreenTitle, countriesYourLanguagesTitle, countriesAllTitle,
radioCountriesError.

Tests: 631 -> 649 (2 skipped, unchanged). flutter analyze unchanged at 1
pre-existing info. grep confirms `countrycodes` appears nowhere in lib/.
This commit is contained in:
2026-07-29 09:36:31 +02:00
parent 9bd828139f
commit c6f16c81b5
27 changed files with 1087 additions and 46 deletions
+58
View File
@@ -1,5 +1,6 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_busqueda.dart';
import 'package:pluriwave/modelos/pais_radio.dart';
import '../helpers/fakes.dart';
@@ -64,4 +65,61 @@ void main() {
expect(identical(busqueda.resultados, busqueda.resultados), isTrue);
},
);
// ---------------------------------------------------------------------
// WU7, `station-discovery-browse` spec — Países browser over
// `ServicioRadio.obtenerPaises()`. In-memory cache guard: re-entering the
// Países screen must NOT re-fetch (design ADR-4).
// ---------------------------------------------------------------------
group('EstadoBusqueda — cargarPaises', () {
test(
'carga la lista de países y no vuelve a pedir en un 2º llamado',
() async {
final radio = FakeServicioRadio(
paises: const [
PaisRadio(nombre: 'Spain', codigoIso: 'ES', numeroEmisoras: 482),
PaisRadio(
nombre: 'Argentina',
codigoIso: 'AR',
numeroEmisoras: 120,
),
],
);
final busqueda = EstadoBusqueda(radio: radio);
addTearDown(busqueda.dispose);
expect(busqueda.paises, isEmpty);
expect(busqueda.cargandoPaises, isFalse);
await busqueda.cargarPaises();
expect(
busqueda.paises.map((p) => p.codigoIso),
containsAll(['ES', 'AR']),
);
expect(busqueda.cargandoPaises, isFalse);
expect(radio.obtenerPaisesCalls, 1);
await busqueda.cargarPaises();
// Cache guard: a 2nd call with data already present must not refetch.
expect(radio.obtenerPaisesCalls, 1);
},
);
test(
'falla con gracia: no deja cargandoPaises en true ni la lista poblada',
() async {
final busqueda = EstadoBusqueda(
radio: FakeServicioRadio(errorPaises: Exception('fallo de red')),
);
addTearDown(busqueda.dispose);
await busqueda.cargarPaises();
expect(busqueda.cargandoPaises, isFalse);
expect(busqueda.paises, isEmpty);
},
);
});
}
+17 -1
View File
@@ -4,6 +4,7 @@ import 'package:pluriwave/l10n/gen/app_localizations.dart';
import 'package:pluriwave/modelos/dispositivo_audio.dart';
import 'package:pluriwave/modelos/emisora.dart';
import 'package:pluriwave/modelos/grupo_favoritos.dart';
import 'package:pluriwave/modelos/pais_radio.dart';
import 'package:pluriwave/modelos/preset_ecualizador.dart';
import 'package:pluriwave/servicios/servicio_audio.dart';
import 'package:pluriwave/servicios/servicio_dispositivo_audio.dart';
@@ -218,13 +219,17 @@ class FakeServicioRadio extends ServicioRadio {
List<List<Emisora>>? tendenciasPorLlamada,
List<Object>? erroresPopularesPorLlamada,
List<Object>? erroresTendenciasPorLlamada,
List<PaisRadio>? paises,
Object? errorPaises,
}) : _populares = populares ?? [],
_tendencias = tendencias ?? [],
_busqueda = busqueda ?? [],
_popularesPorLlamada = popularesPorLlamada ?? const [],
_tendenciasPorLlamada = tendenciasPorLlamada ?? const [],
_erroresPopularesPorLlamada = erroresPopularesPorLlamada ?? const [],
_erroresTendenciasPorLlamada = erroresTendenciasPorLlamada ?? const [];
_erroresTendenciasPorLlamada = erroresTendenciasPorLlamada ?? const [],
_paises = paises ?? [],
_errorPaises = errorPaises;
final List<Emisora> _populares;
final List<Emisora> _tendencias;
@@ -233,11 +238,14 @@ class FakeServicioRadio extends ServicioRadio {
final List<List<Emisora>> _tendenciasPorLlamada;
final List<Object> _erroresPopularesPorLlamada;
final List<Object> _erroresTendenciasPorLlamada;
final List<PaisRadio> _paises;
final Object? _errorPaises;
int obtenerPopularesCalls = 0;
int obtenerTendenciasCalls = 0;
int registrarClickCalls = 0;
int buscarCalls = 0;
int obtenerPaisesCalls = 0;
String? ultimoUuidClick;
Exception _normalizarError(Object error) =>
@@ -293,6 +301,14 @@ class FakeServicioRadio extends ServicioRadio {
registrarClickCalls += 1;
ultimoUuidClick = uuid;
}
@override
Future<List<PaisRadio>> obtenerPaises() async {
obtenerPaisesCalls++;
final error = _errorPaises;
if (error != null) throw _normalizarError(error);
return _paises;
}
}
class FakeServicioEcualizador extends ServicioEcualizador {
+60
View File
@@ -0,0 +1,60 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/modelos/pais_radio.dart';
/// WU7 / `station-discovery-browse` spec, scenario "`stationcount` arrives
/// as a JSON string (edge case, critical)": the Radio Browser `/json/countries`
/// endpoint returns `stationcount` as a STRING, not a number. An `as int`
/// cast throws at runtime — this model MUST go through `int.tryParse`
/// (Engram `reference/radio-browser-countries-endpoint`, id 2500).
void main() {
group('PaisRadio.fromApi', () {
test('parsea stationcount desde un string JSON sin lanzar', () {
final pais = PaisRadio.fromApi(const {
'name': 'Spain',
'iso_3166_1': 'es',
'stationcount': '482',
});
expect(pais.nombre, 'Spain');
expect(pais.codigoIso, 'ES');
expect(pais.numeroEmisoras, 482);
});
test('normaliza iso_3166_1 a mayúsculas', () {
final pais = PaisRadio.fromApi(const {
'name': 'France',
'iso_3166_1': 'fr',
'stationcount': '10',
});
expect(pais.codigoIso, 'FR');
});
test('stationcount ausente cae a 0 sin lanzar', () {
final pais = PaisRadio.fromApi(const {
'name': 'Nowhere',
'iso_3166_1': 'xx',
});
expect(pais.numeroEmisoras, 0);
});
test('stationcount no numérico cae a 0 sin lanzar', () {
final pais = PaisRadio.fromApi(const {
'name': 'Nowhere',
'iso_3166_1': 'xx',
'stationcount': 'not-a-number',
});
expect(pais.numeroEmisoras, 0);
});
test('name/iso_3166_1 ausentes caen a string vacío sin lanzar', () {
final pais = PaisRadio.fromApi(const {'stationcount': '5'});
expect(pais.nombre, '');
expect(pais.codigoIso, '');
expect(pais.numeroEmisoras, 5);
});
});
}
+110
View File
@@ -0,0 +1,110 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_busqueda.dart';
import 'package:pluriwave/l10n/gen/app_localizations.dart';
import 'package:pluriwave/modelos/pais_radio.dart';
import 'package:pluriwave/pantallas/pantalla_paises.dart';
import 'package:pluriwave/widgets/pluri_push_scaffold.dart';
import 'package:provider/provider.dart';
import '../helpers/fakes.dart';
/// WU7, `station-discovery-browse` spec — "Países Browser Over the Verified
/// Countries Contract": "Tus idiomas" shortlist + the full alphabetical
/// list, each entry showing its station count. `stationcount`'s "arrives as
/// a JSON string" edge case is covered at its own layer boundary in
/// `test/modelos/pais_radio_test.dart` — `FakeServicioRadio.obtenerPaises()`
/// returns already-parsed `PaisRadio` instances here, so this file tests
/// rendering only, not JSON parsing.
void main() {
Widget buildScreen(EstadoBusqueda estado) {
return ChangeNotifierProvider<EstadoBusqueda>.value(
value: estado,
child: MaterialApp(
locale: const Locale('es'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const PantallaPaises(),
),
);
}
Future<void> pumpEstable(WidgetTester tester) async {
await tester.pump();
await tester.pumpAndSettle();
}
testWidgets(
'renders inside a PluriPushScaffold; muestra "Tus idiomas" y la lista '
'alfabética completa con el conteo de cada país',
(tester) async {
final estado = EstadoBusqueda(
radio: FakeServicioRadio(
paises: const [
PaisRadio(nombre: 'Spain', codigoIso: 'ES', numeroEmisoras: 482),
PaisRadio(
nombre: 'Argentina',
codigoIso: 'AR',
numeroEmisoras: 120,
),
PaisRadio(nombre: 'France', codigoIso: 'FR', numeroEmisoras: 75),
],
),
);
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await pumpEstable(tester);
expect(find.byType(PluriPushScaffold), findsOneWidget);
final l10n = AppLocalizations.of(
tester.element(find.byType(PantallaPaises)),
);
expect(find.text(l10n.countriesYourLanguagesTitle), findsOneWidget);
expect(find.text(l10n.countriesAllTitle), findsOneWidget);
// Full alphabetical list: all 3 fetched countries render.
expect(find.text('Argentina'), findsOneWidget);
expect(find.text('France'), findsOneWidget);
// 'Spain' renders twice: "Tus idiomas" (locale es -> representative
// country ES) AND the full list below.
expect(find.text('Spain'), findsWidgets);
// Each entry's parsed `stationcount` renders via the existing
// `stationsCount` string — 482 came from the API as a STRING
// (`PaisRadio.fromApi`'s job, verified separately) and must display
// as a plain number here, never throwing a cast error.
expect(find.text(l10n.stationsCount(482)), findsWidgets);
expect(find.text(l10n.stationsCount(120)), findsOneWidget);
expect(find.text(l10n.stationsCount(75)), findsOneWidget);
},
);
testWidgets(
'cargarPaises no se re-dispara si ya hay datos en caché al reconstruir',
(tester) async {
final radio = FakeServicioRadio(
paises: const [
PaisRadio(nombre: 'Italy', codigoIso: 'IT', numeroEmisoras: 30),
],
);
final estado = EstadoBusqueda(radio: radio);
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await pumpEstable(tester);
expect(radio.obtenerPaisesCalls, 1);
// Re-entering the screen (a fresh State, same EstadoBusqueda instance)
// must not refetch — the in-memory cache guard lives on EstadoBusqueda,
// not on the widget.
await tester.pumpWidget(const SizedBox.shrink());
await pumpEstable(tester);
await tester.pumpWidget(buildScreen(estado));
await pumpEstable(tester);
expect(radio.obtenerPaisesCalls, 1);
},
);
}
@@ -0,0 +1,293 @@
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
import 'package:pluriwave/modelos/emisora.dart';
import 'package:pluriwave/servicios/servicio_radio.dart';
/// Characterisation tests for all 8 existing `ServicioRadio` station calls,
/// written against the CURRENT (unmodified) `_get`/`registrarClick` — green
/// by construction, per design ADR-4's strict-TDD sequence: "naive 'the test
/// must fail first' does not apply to characterisation."
///
/// Design's non-negotiable ordering rule: this file MUST be green BEFORE the
/// `_getJson` transport extraction begins, and re-run byte-identical green
/// AFTER it (task 7.6) — that re-run is the extraction's actual proof.
///
/// `test/servicios/servicio_radio_test.dart` is intentionally NOT modified
/// by this work unit; its passing untouched is itself a signal that
/// transport was not disturbed.
void main() {
// Deliberately shuffled bitrate/clickcount/votes: by bitrate desc, `s_b`,
// `s_c` and `s_d` tie at 300; `s_d` wins the tie on clickcount; `s_c` beats
// `s_b` on votes. This exercises every level of `_compararCalidad` and is
// what makes the extraction safe — a sort that silently sinks into
// transport would pass every other assertion below but fail this one.
List<Map<String, dynamic>> fixtureDesordenada() => [
{
'stationuuid': 's_a',
'name': 'A',
'url_resolved': 'https://a.example/audio',
'bitrate': 100,
'clickcount': 10,
'votes': 1,
},
{
'stationuuid': 's_b',
'name': 'B',
'url_resolved': 'https://b.example/audio',
'bitrate': 300,
'clickcount': 5,
'votes': 50,
},
{
'stationuuid': 's_c',
'name': 'C',
'url_resolved': 'https://c.example/audio',
'bitrate': 300,
'clickcount': 5,
'votes': 999,
},
{
'stationuuid': 's_d',
'name': 'D',
'url_resolved': 'https://d.example/audio',
'bitrate': 300,
'clickcount': 80,
'votes': 1,
},
{
'stationuuid': 's_e',
'name': 'E',
'url_resolved': 'https://e.example/audio',
'bitrate': 50,
'clickcount': 999,
'votes': 999,
},
];
const ordenEsperado = ['s_d', 's_c', 's_b', 's_a', 's_e'];
/// Runs [accion] against a `ServicioRadio` whose single mock host always
/// answers with [fixtureDesordenada], and returns both the captured
/// request and the method's return value so callers can assert transport
/// concerns (path/params/headers) and result ordering together.
Future<(http.Request, List<Emisora>)> ejecutar(
Future<List<Emisora>> Function(ServicioRadio) accion,
) async {
late http.Request solicitud;
final servicio = ServicioRadio(
cliente: MockClient((request) async {
solicitud = request;
return http.Response(
jsonEncode(fixtureDesordenada()),
200,
headers: {'content-type': 'application/json'},
);
}),
servidores: const ['host.api.radio-browser.info'],
retryDelay: Duration.zero,
);
final resultado = await accion(servicio);
return (solicitud, resultado);
}
group('ServicioRadio — 7 métodos basados en _get', () {
test('obtenerPopulares: path, filtros de transporte y orden', () async {
final (solicitud, emisoras) = await ejecutar(
(s) => s.obtenerPopulares(limit: 7, offset: 3),
);
expect(solicitud.url.path, '/json/stations/search');
expect(solicitud.url.queryParameters['lastcheckok'], '1');
expect(solicitud.url.queryParameters['hidebroken'], 'true');
expect(solicitud.url.queryParameters['order'], 'bitrate');
expect(solicitud.url.queryParameters['reverse'], 'true');
expect(solicitud.url.queryParameters['limit'], '7');
expect(solicitud.url.queryParameters['offset'], '3');
expect(solicitud.headers['User-Agent'], isNotEmpty);
expect(emisoras.map((e) => e.uuid), equals(ordenEsperado));
});
test('obtenerTendencias: path con limit embebido, sin order/reverse, '
'filtros de transporte y orden', () async {
final (solicitud, emisoras) = await ejecutar(
(s) => s.obtenerTendencias(limit: 12),
);
expect(solicitud.url.path, '/json/stations/topclick/12');
expect(solicitud.url.queryParameters['lastcheckok'], '1');
expect(solicitud.url.queryParameters['hidebroken'], 'true');
// topclick is pre-sorted by the endpoint itself — no order/reverse
// is ever sent for this method.
expect(solicitud.url.queryParameters.containsKey('order'), isFalse);
expect(solicitud.url.queryParameters.containsKey('reverse'), isFalse);
expect(solicitud.headers['User-Agent'], isNotEmpty);
expect(emisoras.map((e) => e.uuid), equals(ordenEsperado));
});
test('buscarPorNombre: path, filtros de transporte y orden', () async {
final (solicitud, emisoras) = await ejecutar(
(s) => s.buscarPorNombre('radio horizonte', limit: 9, offset: 2),
);
expect(solicitud.url.path, '/json/stations/search');
expect(solicitud.url.queryParameters['name'], 'radio horizonte');
expect(solicitud.url.queryParameters['lastcheckok'], '1');
expect(solicitud.url.queryParameters['hidebroken'], 'true');
expect(solicitud.url.queryParameters['order'], 'bitrate');
expect(solicitud.url.queryParameters['reverse'], 'true');
expect(solicitud.url.queryParameters['limit'], '9');
expect(solicitud.url.queryParameters['offset'], '2');
expect(solicitud.headers['User-Agent'], isNotEmpty);
expect(emisoras.map((e) => e.uuid), equals(ordenEsperado));
});
test('buscarPorPais: path, filtros de transporte y orden', () async {
final (solicitud, emisoras) = await ejecutar(
(s) => s.buscarPorPais('ES', limit: 11, offset: 4),
);
expect(solicitud.url.path, '/json/stations/bycountrycodeexact/ES');
expect(solicitud.url.queryParameters['lastcheckok'], '1');
expect(solicitud.url.queryParameters['hidebroken'], 'true');
expect(solicitud.url.queryParameters['order'], 'bitrate');
expect(solicitud.url.queryParameters['reverse'], 'true');
expect(solicitud.url.queryParameters['limit'], '11');
expect(solicitud.url.queryParameters['offset'], '4');
expect(solicitud.headers['User-Agent'], isNotEmpty);
expect(emisoras.map((e) => e.uuid), equals(ordenEsperado));
});
test('buscarPorIdioma: path, filtros de transporte y orden', () async {
final (solicitud, emisoras) = await ejecutar(
(s) => s.buscarPorIdioma('spanish', limit: 6, offset: 1),
);
expect(solicitud.url.path, '/json/stations/bylanguageexact/spanish');
expect(solicitud.url.queryParameters['lastcheckok'], '1');
expect(solicitud.url.queryParameters['hidebroken'], 'true');
expect(solicitud.url.queryParameters['order'], 'bitrate');
expect(solicitud.url.queryParameters['reverse'], 'true');
expect(solicitud.url.queryParameters['limit'], '6');
expect(solicitud.url.queryParameters['offset'], '1');
expect(solicitud.headers['User-Agent'], isNotEmpty);
expect(emisoras.map((e) => e.uuid), equals(ordenEsperado));
});
test('buscarPorTag: path, filtros de transporte y orden', () async {
final (solicitud, emisoras) = await ejecutar(
(s) => s.buscarPorTag('jazz', limit: 8, offset: 0),
);
expect(solicitud.url.path, '/json/stations/bytagexact/jazz');
expect(solicitud.url.queryParameters['lastcheckok'], '1');
expect(solicitud.url.queryParameters['hidebroken'], 'true');
expect(solicitud.url.queryParameters['order'], 'bitrate');
expect(solicitud.url.queryParameters['reverse'], 'true');
expect(solicitud.url.queryParameters['limit'], '8');
expect(solicitud.url.queryParameters['offset'], '0');
expect(solicitud.headers['User-Agent'], isNotEmpty);
expect(emisoras.map((e) => e.uuid), equals(ordenEsperado));
});
test('buscar: combina name/countrycode/language/tag, filtros de transporte '
'y orden', () async {
final (solicitud, emisoras) = await ejecutar(
(s) => s.buscar(
nombre: 'rock',
pais: 'ES',
idioma: 'spanish',
tag: 'indie',
limit: 15,
offset: 5,
),
);
expect(solicitud.url.path, '/json/stations/search');
expect(solicitud.url.queryParameters['name'], 'rock');
expect(solicitud.url.queryParameters['countrycode'], 'ES');
expect(solicitud.url.queryParameters['language'], 'spanish');
expect(solicitud.url.queryParameters['tag'], 'indie');
expect(solicitud.url.queryParameters['lastcheckok'], '1');
expect(solicitud.url.queryParameters['hidebroken'], 'true');
expect(solicitud.url.queryParameters['order'], 'bitrate');
expect(solicitud.url.queryParameters['reverse'], 'true');
expect(solicitud.url.queryParameters['limit'], '15');
expect(solicitud.url.queryParameters['offset'], '5');
expect(solicitud.headers['User-Agent'], isNotEmpty);
expect(emisoras.map((e) => e.uuid), equals(ordenEsperado));
});
});
group('ServicioRadio — obtenerPaises (usa _getJson, no _get)', () {
test('consulta /json/countries sin lastcheckok ni order; conserva '
'hidebroken; parsea stationcount desde un string JSON', () async {
late http.Request solicitud;
final servicio = ServicioRadio(
cliente: MockClient((request) async {
solicitud = request;
return http.Response(
jsonEncode([
{'name': 'Spain', 'iso_3166_1': 'es', 'stationcount': '482'},
{'name': 'Argentina', 'iso_3166_1': 'ar', 'stationcount': '120'},
]),
200,
headers: {'content-type': 'application/json'},
);
}),
servidores: const ['host.api.radio-browser.info'],
retryDelay: Duration.zero,
);
final paises = await servicio.obtenerPaises();
expect(solicitud.url.path, '/json/countries');
// The station-only filter and the station-only sort must NOT reach
// this endpoint — that is the entire point of the `_getJson`
// extraction (spec scenario "Countries request omits the
// station-only filter").
expect(solicitud.url.queryParameters.containsKey('lastcheckok'), isFalse);
expect(solicitud.url.queryParameters.containsKey('order'), isFalse);
expect(solicitud.url.queryParameters.containsKey('reverse'), isFalse);
// Inherited from `_uri`, unchanged — desirable here too (Engram id
// 2500): the endpoint's own default is `false`.
expect(solicitud.url.queryParameters['hidebroken'], 'true');
expect(solicitud.headers['User-Agent'], isNotEmpty);
expect(paises.map((p) => p.codigoIso), ['ES', 'AR']);
// `stationcount` arrived as a JSON STRING ("482") — this proves the
// whole pipeline (not just `PaisRadio.fromApi` in isolation) parses
// it without a cast error.
expect(paises.map((p) => p.numeroEmisoras), [482, 120]);
});
});
group('ServicioRadio — registrarClick (8º, no usa _get)', () {
test(
'pega al path correcto con un User-Agent no vacío '
'(literal desactualizado, fuera de alcance: no se fija su valor)',
() async {
late http.Request solicitud;
final servicio = ServicioRadio(
cliente: MockClient((request) async {
solicitud = request;
return http.Response('', 200);
}),
servidores: const ['host.api.radio-browser.info'],
retryDelay: Duration.zero,
);
await servicio.registrarClick('uuid-click');
expect(solicitud.url.path, '/json/url/uuid-click');
expect(solicitud.headers['User-Agent'], isNotEmpty);
// Deliberately NOT asserting the exact User-Agent value: it hardcodes
// a stale 'PluriWave/0.1.0 (...)' literal (known, out-of-scope
// defect — see `_resolverUserAgent()`'s own doc comment). Pinning a
// known-wrong value would convert a bug into a contract.
},
);
});
}