- Implement EmergencyService for handling emergency contacts per trip. - Create GuestFlagService to manage guest mode flags for trips. - Introduce NotificationService with local notification capabilities. - Add OfflineFlagService for managing offline caching flags. - Develop PackingService for shared packing lists per trip. - Implement ReminderService for managing reminders/to-dos per trip. - Create SosService for dispatching SOS events to a backend. - Add StorageService with album image upload functionality. - Implement TransportService for managing transport segments per trip. - Create TripChecklistService for storing and retrieving trip checklists. - Add TripDocumentService for persisting trip documents metadata. test: Add unit tests for new services - Implement tests for AlbumService, BudgetService, EmergencyService, GuestFlagService, PackingService, ReminderService, SosService, TransportService, TripChecklistService, and TripDocumentService. - Ensure tests cover adding, loading, deleting, and handling corrupted payloads for each service.
61 lines
1.7 KiB
Dart
61 lines
1.7 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:travel_mate/models/trip_document.dart';
|
|
import 'package:travel_mate/services/trip_document_service.dart';
|
|
|
|
void main() {
|
|
const tripId = 'trip-docs-1';
|
|
late TripDocumentService service;
|
|
|
|
setUp(() {
|
|
SharedPreferences.setMockInitialValues({});
|
|
service = TripDocumentService();
|
|
});
|
|
|
|
test('adds and loads documents', () async {
|
|
final doc = TripDocument.newEntry(
|
|
id: 'doc1',
|
|
title: 'Billet Aller',
|
|
category: 'billet',
|
|
downloadUrl: 'https://example.com/billet.pdf',
|
|
);
|
|
|
|
await service.addDocument(tripId, doc);
|
|
final loaded = await service.loadDocuments(tripId);
|
|
|
|
expect(loaded, hasLength(1));
|
|
expect(loaded.first.title, 'Billet Aller');
|
|
expect(loaded.first.category, 'billet');
|
|
});
|
|
|
|
test('deletes a document', () async {
|
|
final a = TripDocument.newEntry(
|
|
id: 'a',
|
|
title: 'Passeport',
|
|
category: 'passeport',
|
|
);
|
|
final b = TripDocument.newEntry(
|
|
id: 'b',
|
|
title: 'Assurance',
|
|
category: 'assurance',
|
|
);
|
|
await service.addDocument(tripId, a);
|
|
await service.addDocument(tripId, b);
|
|
|
|
final afterDelete = await service.deleteDocument(tripId, 'a');
|
|
|
|
expect(afterDelete, hasLength(1));
|
|
expect(afterDelete.first.id, 'b');
|
|
});
|
|
|
|
test('handles corrupted payload gracefully', () async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString('trip_docs_$tripId', 'oops');
|
|
|
|
final docs = await service.loadDocuments(tripId);
|
|
|
|
expect(docs, isEmpty);
|
|
expect(prefs.getString('trip_docs_$tripId'), isNull);
|
|
});
|
|
}
|