Refactor LoRa airtime tests and add new functionality
- Updated LoRa airtime calculations in `lora_airtime_test.dart` to reflect new reference values. - Introduced new tests for LDRO behavior and preamble symbol calculations. - Added `contact_path_width_test.dart` to validate path hash width handling in contacts. - Enhanced `model_changes_test.dart` to ensure legacy data migration works correctly. - Created `remote_node_stats_test.dart` to decode and validate remote node statistics. - Implemented `map_marker_parse_test.dart` for parsing marker text with coordinate validation. - Developed `map_tile_cache_key_test.dart` to ensure API keys are excluded from cache keys. - Added `message_retry_failure_test.dart` to test message retry service behavior on failures. - Extended `path_history_service_test.dart` to preserve learned state across path attempts. - Enhanced `received_image_store_test.dart` to handle concurrent writes and review fixes. - Implemented `repeater_command_service_test.dart` to validate command response handling. - Created `store_tolerant_parsing_test.dart` to ensure stores skip malformed records gracefully. - Cleared untranslated JSON file for localization updates.
This commit is contained in:
1 parent
d5f54dfa11
commit
d74587c167
105 files changed
+6419
-2072
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/models/community.dart';
|
||||
import 'package:meshcore_open/services/storage_service.dart';
|
||||
import 'package:meshcore_open/storage/channel_message_store.dart';
|
||||
import 'package:meshcore_open/storage/community_store.dart';
|
||||
import 'package:meshcore_open/storage/message_store.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
const _device = 'abcdef012345';
|
||||
|
||||
Future<void> _init(Map<String, Object> values) async {
|
||||
SharedPreferences.setMockInitialValues(values);
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
}
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'message store skips a malformed record instead of dropping all',
|
||||
() async {
|
||||
final good = {
|
||||
'senderKey': base64Encode([1, 2, 3]),
|
||||
'text': 'hello',
|
||||
'timestamp': 1000,
|
||||
'status': 1,
|
||||
};
|
||||
await _init({
|
||||
'messages_${_device.substring(0, 10)}c1': jsonEncode([
|
||||
good,
|
||||
{'text': 'no timestamp'},
|
||||
]),
|
||||
});
|
||||
final store = MessageStore()..setPublicKeyHex = _device;
|
||||
final messages = await store.loadMessages('c1');
|
||||
expect(messages.map((m) => m.text), ['hello']);
|
||||
expect(messages.single.isOutgoing, isFalse);
|
||||
},
|
||||
);
|
||||
|
||||
test('channel message store skips a malformed record', () async {
|
||||
await _init({
|
||||
'channel_messages_${_device.substring(0, 10)}0': jsonEncode([
|
||||
{'text': 'hi', 'timestamp': 1000, 'status': 1},
|
||||
'garbage',
|
||||
]),
|
||||
});
|
||||
final store = ChannelMessageStore()..setPublicKeyHex = _device;
|
||||
final messages = await store.loadChannelMessages(0);
|
||||
expect(messages.map((m) => m.text), ['hi']);
|
||||
});
|
||||
|
||||
test('community store keeps valid communities next to a bad one', () async {
|
||||
final community = Community.create(id: 'c1', name: 'Ops');
|
||||
await _init({
|
||||
'communities_v1${_device.substring(0, 10)}': jsonEncode([
|
||||
community.toJson(),
|
||||
{'id': 'broken'},
|
||||
]),
|
||||
});
|
||||
final store = CommunityStore()..setPublicKeyHex = _device;
|
||||
final communities = await store.loadCommunities();
|
||||
expect(communities.map((c) => c.id), ['c1']);
|
||||
});
|
||||
|
||||
test('delivery observations skip malformed entries', () async {
|
||||
await _init({
|
||||
'delivery_observations': jsonEncode([
|
||||
{
|
||||
'contact_key': 'k',
|
||||
'path_length': 1,
|
||||
'message_bytes': 10,
|
||||
'delivery_ms': 500,
|
||||
'timestamp': DateTime(2026).toIso8601String(),
|
||||
},
|
||||
{'contact_key': 'bad'},
|
||||
]),
|
||||
});
|
||||
final observations = await StorageService().loadDeliveryObservations();
|
||||
expect(observations, hasLength(1));
|
||||
expect(observations.single.isFlood, isFalse);
|
||||
});
|
||||
|
||||
test('community hashtag normalization trims before stripping #', () {
|
||||
final community = Community.create(id: 'c1', name: 'Ops');
|
||||
expect(
|
||||
community.deriveCommunityHashtagPsk(' #ops'),
|
||||
community.deriveCommunityHashtagPsk('#ops'),
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user