tane/apps/app_seeds/test/services/social_settings_test.dart
vjrj 97b9223cb2 fix(market): search your zone by a coarse prefix, not the exact cell
Discovery searched the full 5-char geohash (~2.4 km) with an exact Nostr tag
match, so two devices in adjacent cells never found each other even though
publish emits the full NIP-52 prefix ladder. Search now coarsens the area to a
configurable precision (SocialSettings.searchPrecision, default 4 ~20 km) via
searchPrefix(), with a human-worded 'how far' selector (Very close / Around
here / My region -> 5/4/3) in the market setup sheet.

Also: surface a clear 'couldn't reach the servers' message when no relay
accepts a share (instead of 'shared 0'), and add wss://relay.comunes.org as the
first default relay (reliable community home; public relays are backup).

Tests: settings precision (default/clamp/roundtrip), searchPrefix helper,
neighbour-cell discovery regression (offers_cubit + commons_core nostr
transports), and the range-selector widget test.
2026-07-10 16:12:38 +02:00

74 lines
2.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter_test/flutter_test.dart';
import 'package:tane/security/secret_store.dart';
import 'package:tane/services/social_settings.dart';
/// In-memory [SecretStore] for tests.
class FakeSecretStore implements SecretStore {
final Map<String, String> _data = {};
@override
Future<String?> read(String key) async => _data[key];
@override
Future<void> write(String key, String value) async => _data[key] = value;
}
void main() {
late SocialSettings settings;
setUp(() => settings = SocialSettings(FakeSecretStore()));
test('defaults: empty area, but relays fall back to the defaults', () async {
expect(await settings.areaGeohash(), '');
expect(await settings.relayUrls(), SocialSettings.defaultRelays);
// Not configured yet: the area is still unset.
expect(await settings.isConfigured, isFalse);
});
test('an explicitly empty relay choice turns the network off', () async {
await settings.setRelayUrls(const []);
expect(await settings.relayUrls(), isEmpty);
});
test('stores and normalises the area geohash (trim + lowercase)', () async {
await settings.setAreaGeohash(' SP3E9 ');
expect(await settings.areaGeohash(), 'sp3e9');
});
test('stores relay urls, dropping blanks', () async {
await settings.setRelayUrls([
'wss://relay.comunes.org',
' ',
'wss://seeds.example.org',
]);
expect(await settings.relayUrls(),
['wss://relay.comunes.org', 'wss://seeds.example.org']);
});
test('is configured once an area is set (relays are defaulted)', () async {
expect(await settings.isConfigured, isFalse); // no area yet
await settings.setAreaGeohash('sp3e9');
expect(await settings.isConfigured, isTrue);
});
test('search precision defaults to 4 (a wide "around here")', () async {
expect(await settings.searchPrecision(), 4);
});
test('stores and reads back the search precision', () async {
await settings.setSearchPrecision(3);
expect(await settings.searchPrecision(), 3);
await settings.setSearchPrecision(5);
expect(await settings.searchPrecision(), 5);
});
test('search precision is clamped to the 35 range', () async {
await settings.setSearchPrecision(1);
expect(await settings.searchPrecision(), 3);
await settings.setSearchPrecision(9);
expect(await settings.searchPrecision(), 5);
});
test('a corrupt stored precision falls back to the default', () async {
final store = FakeSecretStore();
await store.write('tane.social.search_precision', 'oops');
expect(await SocialSettings(store).searchPrecision(), 4);
});
}