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.
84 lines
2.3 KiB
Dart
84 lines
2.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pluriwave/estado/estado_alarmas.dart';
|
|
import 'package:pluriwave/modelos/alarma_musical.dart';
|
|
import 'package:pluriwave/servicios/servicio_alarmas.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../helpers/fakes_alarmas.dart';
|
|
|
|
/// S3-R6: `_ejecucionesEmitidas` must be bounded — stale entries (>24 h)
|
|
/// pruned and total size capped.
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
setUp(() {
|
|
SharedPreferences.setMockInitialValues({});
|
|
});
|
|
|
|
EstadoAlarmas crearEstado(FakePuertoAlarmasAndroid android) {
|
|
final estado = EstadoAlarmas(
|
|
esPremium: () => true,
|
|
servicio: ServicioAlarmas(),
|
|
android: android,
|
|
iniciarAutomaticamente: false,
|
|
);
|
|
addTearDown(estado.dispose);
|
|
addTearDown(android.dispose);
|
|
return estado;
|
|
}
|
|
|
|
const base = AlarmaMusical(
|
|
id: 'a1',
|
|
nombre: 'Diaria',
|
|
hora: 7,
|
|
minuto: 0,
|
|
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
|
diasSemana: [],
|
|
);
|
|
|
|
test('poda las entradas con mas de 24 horas (S3-R6-A)', () {
|
|
final estado = crearEstado(FakePuertoAlarmasAndroid());
|
|
final ahora = DateTime.now();
|
|
|
|
for (var i = 0; i < 100; i++) {
|
|
estado.marcarEjecucionGestionada(
|
|
base.copyWith(
|
|
proximaEjecucion: ahora.subtract(Duration(hours: 25, minutes: i)),
|
|
),
|
|
);
|
|
}
|
|
estado.marcarEjecucionGestionada(
|
|
base.copyWith(
|
|
id: 'fresca',
|
|
proximaEjecucion: ahora.add(const Duration(minutes: 5)),
|
|
),
|
|
);
|
|
|
|
expect(
|
|
estado.ejecucionesEmitidasLength,
|
|
lessThanOrEqualTo(EstadoAlarmas.maxEjecucionesEmitidas),
|
|
);
|
|
expect(
|
|
estado.ejecucionesEmitidasLength,
|
|
1,
|
|
reason: 'solo la entrada fresca sobrevive a la poda por antiguedad',
|
|
);
|
|
});
|
|
|
|
test('limita el total de entradas al tope configurado', () {
|
|
final estado = crearEstado(FakePuertoAlarmasAndroid());
|
|
final ahora = DateTime.now();
|
|
|
|
for (var i = 0; i < EstadoAlarmas.maxEjecucionesEmitidas + 50; i++) {
|
|
estado.marcarEjecucionGestionada(
|
|
base.copyWith(proximaEjecucion: ahora.add(Duration(minutes: i))),
|
|
);
|
|
}
|
|
|
|
expect(
|
|
estado.ejecucionesEmitidasLength,
|
|
lessThanOrEqualTo(EstadoAlarmas.maxEjecucionesEmitidas),
|
|
);
|
|
});
|
|
}
|