fix(iap): address code review defects in freemium/IAP change
Fixes 9 of 10 review findings (10th requires a manual Play Console step, no code change): 1. app.dart/banner_anuncio_superior.dart: move the top SafeArea inside BannerAnuncioSuperior so it only reserves status-bar height when an ad actually renders, restoring edge-to-edge layout for premium and free-unloaded users. 2. servicio_anuncios.dart: bound every interstitial await (load, presentation, and the injected implementation itself) with injectable timeouts so a callback that never fires can no longer hang a caller. 3. estado_entitlement.dart/hoja_premium.dart: expose a typed resultadoUsuario signal for purchase/restore failures and restore-found-nothing, with dedicated localized messages (compraError, restauracionSinCompras) across all 13 locales -- never the raw developer/exception string. 4. main.dart/servicio_consentimiento.dart: add a GDPR/UMP consent flow (ConsentInformation/ConsentForm) that gates Mobile Ads SDK init on canRequestAds(); premium users never see a consent form; failures degrade to no ads instead of crashing or blocking startup. 6. servicio_anuncios.dart: track real ad presentation (onAdShowedFullScreenContent) so a failed-to-show interstitial no longer consumes a session cap slot. 7. banner_anuncio_superior.dart: add an explicit load-attempted guard so repeated didChangeDependencies (e.g. entitlement notifyListeners during a purchase) can only ever trigger one banner load attempt. 8. servicio_anuncios.dart: make esPremium a required constructor parameter, matching the hardened contract already applied to EstadoAlarmas/EstadoGrabacion/EstadoRadio. 9. hoja_premium.dart: add a dedicated premiumActivo localized string instead of reusing the equalizer's equalizerActive translation, across all 13 locales. All fixes implemented RED-first (failing test before production code). Full suite: 1261 passed, 2 pre-existing skips, 0 failures. flutter analyze: 5 pre-existing issues only, 0 new. [version set]
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/servicios/servicio_consentimiento.dart';
|
||||
|
||||
/// Fake [PuertoConsentimiento]: never touches the UMP plugin, lets each
|
||||
/// test drive the outcome of the consent flow directly.
|
||||
class _PuertoConsentimientoFalso implements PuertoConsentimiento {
|
||||
_PuertoConsentimientoFalso({this.resultado = true, this.lanzarError = false});
|
||||
|
||||
final bool resultado;
|
||||
final bool lanzarError;
|
||||
int llamadas = 0;
|
||||
|
||||
@override
|
||||
Future<bool> resolver() async {
|
||||
llamadas++;
|
||||
if (lanzarError) throw Exception('fallo simulado de UMP');
|
||||
return resultado;
|
||||
}
|
||||
}
|
||||
|
||||
/// FIX 4 (code review): no GDPR/UMP consent flow existed at all before
|
||||
/// this. [resolverConsentimientoAnuncios] is the pure/injectable
|
||||
/// orchestration seam -- testable with zero AdMob/UMP platform channels,
|
||||
/// mirroring `ServicioAnuncios`'s own testing strategy.
|
||||
void main() {
|
||||
group('resolverConsentimientoAnuncios', () {
|
||||
test('usuario premium: nunca toca el puerto de consentimiento (cero '
|
||||
'formularios para premium) y resuelve false', () async {
|
||||
final puerto = _PuertoConsentimientoFalso(resultado: true);
|
||||
|
||||
final permiso = await resolverConsentimientoAnuncios(
|
||||
esPremium: true,
|
||||
consentimiento: puerto,
|
||||
);
|
||||
|
||||
expect(permiso, isFalse);
|
||||
expect(puerto.llamadas, 0);
|
||||
});
|
||||
|
||||
test('usuario free: delega al puerto de consentimiento y devuelve su '
|
||||
'resultado (canRequestAds)', () async {
|
||||
final puerto = _PuertoConsentimientoFalso(resultado: true);
|
||||
|
||||
final permiso = await resolverConsentimientoAnuncios(
|
||||
esPremium: false,
|
||||
consentimiento: puerto,
|
||||
);
|
||||
|
||||
expect(permiso, isTrue);
|
||||
expect(puerto.llamadas, 1);
|
||||
});
|
||||
|
||||
test('usuario free, consentimiento no otorgado: nunca se piden anuncios '
|
||||
'(false)', () async {
|
||||
final puerto = _PuertoConsentimientoFalso(resultado: false);
|
||||
|
||||
final permiso = await resolverConsentimientoAnuncios(
|
||||
esPremium: false,
|
||||
consentimiento: puerto,
|
||||
);
|
||||
|
||||
expect(permiso, isFalse);
|
||||
});
|
||||
|
||||
test('un fallo del puerto de consentimiento degrada silenciosamente a '
|
||||
'false -- nunca se propaga ni bloquea al llamador', () async {
|
||||
final puerto = _PuertoConsentimientoFalso(lanzarError: true);
|
||||
|
||||
final permiso = await resolverConsentimientoAnuncios(
|
||||
esPremium: false,
|
||||
consentimiento: puerto,
|
||||
);
|
||||
|
||||
expect(permiso, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user