refactor(iap): make esPremium a required constructor parameter

EstadoAlarmas, EstadoGrabacion and EstadoRadio defaulted `esPremium` to
`() => true`, so any construction site that forgot to wire entitlement
compiled fine and silently ran ungated — failing OPEN to premium and
disabling the paywall with no test able to catch it.

The parameter is now required with no default. Production wiring in
app.dart was already correct and is unchanged; the 184 pre-existing test
call sites now pass `() => true` explicitly, which is exactly the old
implicit default, so every assertion is untouched.

EstadoRadio has no gate of its own but constructs EstadoGrabacion, so it
inherits the same contract.

The one test that existed to pin the old default is renamed to describe
what it still covers (the premium path through iniciar() with no
duracion); its assertions are unchanged.
This commit is contained in:
2026-08-10 22:06:36 +02:00
parent aa0b242374
commit d81fabbe27
59 changed files with 215 additions and 23 deletions
+6 -5
View File
@@ -47,14 +47,15 @@ class EstadoGrabacion extends ChangeNotifier {
Emisora? Function()? emisoraActual,
void Function(String mensaje)? alError,
// iap-freemium-unlock (Design ADR-3): entitlement query, mirroring
// [_emisoraActual]'s callback-injection shape. Defaults to "premium"
// (ungated) so every pre-existing test/call site keeps its exact
// previous behavior — `app.dart` always wires the real callback.
bool Function()? esPremium,
// [_emisoraActual]'s callback-injection shape. REQUIRED on purpose: an
// optional parameter with any default lets a forgotten wiring compile
// and silently pick a tier, and no test can catch that. Callers must
// state the entitlement source explicitly.
required bool Function() esPremium,
}) : servicio = servicio ?? ServicioGrabacionRadio(),
_emisoraActual = emisoraActual ?? (() => null),
_alError = alError,
_esPremium = esPremium ?? (() => true) {
_esPremium = esPremium {
_suscripcion = this.servicio.estadoStream.listen((estado) {
if (estado.tipo == EstadoGrabacionRadioTipo.error &&
estado.error != null) {