feat: servicios WhatsApp, Bitácora WebControl, SQLite v4, UI y store listing
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:seguridad_electronica/services/sincronizador.dart';
|
||||
import 'package:seguridad_electronica/services/api_auth_service.dart';
|
||||
import 'package:seguridad_electronica/db/dao/alarmas_dao.dart';
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
sqfliteFfiInit();
|
||||
databaseFactory = databaseFactoryFfi;
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
|
||||
test('Prueba de sincronización real contra API_CENTINEL_SECURITY', () async {
|
||||
// 1. Precargar credenciales de Centinel
|
||||
await ApiAuthService.instance.usarCredencialesPruebaCentinel();
|
||||
final headers = await ApiAuthService.instance.getCentinelHeaders();
|
||||
print('Headers configurados: $headers');
|
||||
expect(headers != null, true);
|
||||
|
||||
// 2. Ejecutar pull de alarmas desde API
|
||||
await Sincronizador.instance.sincronizarAlarmas();
|
||||
|
||||
// 3. Verificar que se persistieron en SQLite
|
||||
final alarmas = await AlarmasDao().getAll();
|
||||
print('Total de alarmas en SQLite tras sincronización: ${alarmas.length}');
|
||||
for (final a in alarmas) {
|
||||
print(' - ID ${a.id}: severidad=${a.severidad}, estado=${a.estado}, notas=${a.notas}');
|
||||
}
|
||||
expect(alarmas.isNotEmpty, true);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:seguridad_electronica/services/whatsapp_alert_service.dart';
|
||||
import 'package:seguridad_electronica/models/usuario.dart';
|
||||
|
||||
void main() {
|
||||
group('Pruebas de Validación de Teléfono WhatsApp (E.164 con código de país)', () {
|
||||
test('Números internacionales válidos con código de país', () {
|
||||
// Ecuador (+593 o 593)
|
||||
expect(WhatsAppAlertService.esNumeroValido('+593991234567'), isTrue);
|
||||
expect(WhatsAppAlertService.esNumeroValido('593991234567'), isTrue);
|
||||
expect(WhatsAppAlertService.esNumeroValido('+593 99 123 4567'), isTrue);
|
||||
expect(WhatsAppAlertService.esNumeroValido('+593-99-123-4567'), isTrue);
|
||||
|
||||
// Estados Unidos / Canadá (+1)
|
||||
expect(WhatsAppAlertService.esNumeroValido('+14155552671'), isTrue);
|
||||
|
||||
// México (+52)
|
||||
expect(WhatsAppAlertService.esNumeroValido('+5215512345678'), isTrue);
|
||||
|
||||
// Argentina (+54)
|
||||
expect(WhatsAppAlertService.esNumeroValido('+5491123456789'), isTrue);
|
||||
});
|
||||
|
||||
test('Números inválidos (sin código de país o con cero inicial)', () {
|
||||
// Número local con 0 inicial (formato nacional inválido para WhatsApp)
|
||||
expect(WhatsAppAlertService.esNumeroValido('0991234567'), isFalse);
|
||||
expect(WhatsAppAlertService.esNumeroValido('+0991234567'), isFalse);
|
||||
|
||||
// Números demasiado cortos o vacíos
|
||||
expect(WhatsAppAlertService.esNumeroValido(''), isFalse);
|
||||
expect(WhatsAppAlertService.esNumeroValido('12345'), isFalse);
|
||||
expect(WhatsAppAlertService.esNumeroValido('+593'), isFalse);
|
||||
|
||||
// Letras o caracteres extraños
|
||||
expect(WhatsAppAlertService.esNumeroValido('abcde'), isFalse);
|
||||
});
|
||||
|
||||
test('Normalización de caracteres y espaciado', () {
|
||||
expect(WhatsAppAlertService.normalizarTelefono(' +593 99-123 4567 '), equals('+593991234567'));
|
||||
expect(WhatsAppAlertService.normalizarTelefono('(593) 991234567'), equals('593991234567'));
|
||||
});
|
||||
|
||||
test('Serialización y deserialización del modelo Usuario con teléfono', () {
|
||||
const u = Usuario(
|
||||
id: 1,
|
||||
nombre: 'Guardia Nocturno',
|
||||
iniciales: 'GN',
|
||||
nivelAcceso: 2,
|
||||
pinHash: 'hash123',
|
||||
telefono: '+593987654321',
|
||||
);
|
||||
|
||||
final map = u.toMap();
|
||||
expect(map['telefono'], equals('+593987654321'));
|
||||
|
||||
final u2 = Usuario.fromMap(map);
|
||||
expect(u2.telefono, equals('+593987654321'));
|
||||
|
||||
final u3 = u.copyWith(telefono: '+593999999999');
|
||||
expect(u3.telefono, equals('+593999999999'));
|
||||
expect(u3.nombre, equals('Guardia Nocturno'));
|
||||
});
|
||||
});
|
||||
}
|
||||
+10
-20
@@ -1,30 +1,20 @@
|
||||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility that Flutter provides. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:seguridad_electronica/main.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
sqfliteFfiInit();
|
||||
databaseFactory = databaseFactoryFfi;
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
|
||||
testWidgets('SENTINEL ONE smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const MyApp());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('1'), findsNothing);
|
||||
|
||||
// Tap the '+' icon and trigger a frame.
|
||||
await tester.tap(find.byIcon(Icons.add));
|
||||
await tester.pump();
|
||||
|
||||
// Verify that our counter has incremented.
|
||||
expect(find.text('0'), findsNothing);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
// Verify that the title or brand is rendered
|
||||
expect(find.text('SENTINEL ONE'), findsAtLeastNWidgets(1));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user