import 'package:flutter_test/flutter_test.dart'; import 'package:patbond_flutter/analytics/analytics_service.dart'; void main() { group('AnalyticsService', () { test('tracks event with required fields', () async { final service = AnalyticsService( apiBaseUrl: 'http://test', getAccessToken: null, ); // Never throws, never awaits network (fire-and-forget). expect( () => service.trackEvent('auth_login_succeeded', { 'identifierType': 'username', 'durationMs': 123, }), returnsNormally, ); }); test('rejects events with forbidden field patterns', () async { final service = AnalyticsService( apiBaseUrl: 'http://test', getAccessToken: null, ); // Forbidden field triggers local rejection (no throw, silent drop). await service.trackEvent('auth_login_succeeded', { 'userPassword': 'leak', // Forbidden pattern }); // Event should be dropped (no assertion — just verify no crash). }); test('identify sets userId', () { final service = AnalyticsService( apiBaseUrl: 'http://test', getAccessToken: null, ); service.identify('user-123'); // Subsequent events will carry userId (validated in integration tests). }); test('reset clears userId but keeps anonymousId', () { final service = AnalyticsService( apiBaseUrl: 'http://test', getAccessToken: null, anonymousId: 'anon-123', ); service.identify('user-123'); service.reset(); // userId cleared, anonymousId retained (validated in integration tests). }); }); }