tane/apps/app_seeds/test/services/discovery_area_test.dart
vjrj 1af0282e00 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

22 lines
843 B
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:tane/services/discovery_area.dart';
void main() {
test('coarsens the area to the search precision', () {
expect(searchPrefix('sp3e9', 4), 'sp3e');
expect(searchPrefix('sp3e9', 3), 'sp3');
expect(searchPrefix('sp3e9', 5), 'sp3e9');
});
test('never asks for more than the area actually has', () {
expect(searchPrefix('sp', 4), 'sp');
expect(searchPrefix('', 4), '');
});
test('two neighbours in adjacent 5-char cells share a 4-char prefix', () {
// The crux of the bug: sp3e9 and sp3e8 are different ±2.4 km cells, but
// searching at precision 4 collapses both to 'sp3e', so they find each
// other. Publishing emits the ladder down to 'sp3e', so this matches.
expect(searchPrefix('sp3e9', 4), searchPrefix('sp3e8', 4));
});
}