Files
pluriwave/test/servicios/servicio_audio_gating_test.dart
T
FreeTLab aa0b242374 feat(iap): add freemium unlock via one-time in-app purchase
Adds a permanent, non-consumable premium unlock (EstadoEntitlement +
PuertoCompras/ServicioComprasPlayBilling) that removes ads and unlocks
alarm vacations, alarms past a 5-alarm free cap, recording start, and
full Android Auto browsing. The phone equalizer stays free for everyone.

- Entitlement is prefs-backed (compra_premium_v1), fail-open, and
  resolvable headlessly via esPremiumPersistido() for the Android Auto
  audio handler, which registers before runApp.
- Android Auto reduced mode keeps the real root folder labels for free
  users; browsing into any of them (and playFromMediaId/playFromSearch/
  skipToNext/skipToPrevious) is blocked at the getChildren/servicio_audio
  choke points, with a locked "Función Premium" item as the backstop.
  Current-station play/pause/stop stays untouched. A free -> premium
  transition actively invalidates the head unit's cached browse tree.
- Ads (top banner + capped interstitial before adding a station or an
  alarm) are gated behind entitlement via ServicioAnuncios, using
  official Google test ad unit IDs pending AdMob provisioning.
- Alarm cap UX shows an explanatory message with a secondary unlock
  action rather than a bare paywall jump; existing data is grandfathered.
- 4 new localization keys translated across all 13 supported locales.

Co-located tests use strict TDD (RED test before implementation) for
every new pure-logic unit; full existing suite passes unchanged.
2026-08-10 20:37:07 +02:00

39 lines
1.6 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/servicios/servicio_audio.dart';
/// Android Auto play-path backstop (design.md ADR-4, android-auto-media
/// spec "Free-Tier Browse Never Leaks Real Content" + "Current-Station
/// Playback Unaffected By Free Tier"): `playFromMediaId`, `playFromSearch`,
/// `skipToNext`, `skipToPrevious` must ALL no-op for a free-tier user,
/// regardless of the target id — gating `getChildren` alone is
/// insufficient because a head unit caches browse trees, so a stale
/// `emisora:<uuid>` tap could otherwise bypass browsing entirely. Pure —
/// `PluriWaveAudioHandler` cannot be instantiated in a unit test (needs a
/// real platform `AudioPlayer`), so this is the extracted decision the
/// handler's dispatch methods delegate to (mirrors `mapearEstadoProceso`
/// and every other pure helper in this file).
void main() {
test('free tier: bloquea cualquier cambio de emisora/salto', () {
expect(debeBloquearCambioDeEmisora(premium: false), isTrue);
});
test('premium: nunca bloquea', () {
expect(debeBloquearCambioDeEmisora(premium: true), isFalse);
});
group('notificarDesbloqueoAuto / registrarNotificacionDesbloqueoAuto', () {
test('sin hook registrado, es un no-op seguro', () {
expect(() => notificarDesbloqueoAuto(), returnsNormally);
});
test('invoca el hook registrado exactamente una vez por llamada', () {
var llamadas = 0;
registrarNotificacionDesbloqueoAuto(() => llamadas++);
notificarDesbloqueoAuto();
expect(llamadas, 1);
});
});
}