Tane dialled its four default relays at launch, before anyone had asked for anything — an F-Droid reviewer spotted it, and they were right. The seed book needs no network at all, so the app should not have one until the person joins the sharing side. - SocialSettings gains a three-state `sharingEnabled`. `null` means "never asked", which is what lets `migrateSharingEnabled` keep an existing install exactly as it was: anyone past the intro was on a build that connected at launch, so they keep messaging, device sync and offer alerts. A fresh install starts fully offline. - bootstrap only starts the shared connection when sharing is on. The inbox/sync/plantaré/alert listeners are untouched: they react to a session, and none arrives. - SharingSwitch is the single place that moves the stored choice, the live connection and the flag the UI listens to, so they cannot drift. - Agreeing to the community rules is the opt-in — one consent surface, reached from the market or from the drawer's invitation. - SocialConnection.start is now idempotent and gains stop(), so turning sharing off goes offline immediately instead of at the next launch. - The social drawer entries stay visible but padlocked while sharing is off; tapping one explains what wakes up and offers to join. Hiding them would have kept the tool a secret. "Coming soon" is gone for good — everything it labelled is built. Covered by tests for the migration in both directions, start/stop lifecycle, the gate turning sharing on, the invitation, and the drawer in all three states (no social layer / off / on).
134 lines
4.9 KiB
Dart
134 lines
4.9 KiB
Dart
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 3–5 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);
|
||
});
|
||
|
||
test('the blocklist starts empty and round-trips block/unblock', () async {
|
||
expect(await settings.blockedPubkeys(), isEmpty);
|
||
|
||
await settings.block('AB' * 32);
|
||
expect(await settings.isBlocked('ab' * 32), isTrue); // normalised
|
||
expect(await settings.blockedPubkeys(), {'ab' * 32});
|
||
|
||
await settings.block('cd' * 32);
|
||
expect(await settings.blockedPubkeys(), hasLength(2));
|
||
|
||
await settings.unblock('ab' * 32);
|
||
expect(await settings.isBlocked('ab' * 32), isFalse);
|
||
expect(await settings.blockedPubkeys(), {'cd' * 32});
|
||
});
|
||
|
||
test('blocking twice keeps a single entry', () async {
|
||
await settings.block('ab' * 32);
|
||
await settings.block(' AB' * 1 + 'ab' * 31); // messy spacing/case
|
||
expect(await settings.blockedPubkeys(), hasLength(1));
|
||
});
|
||
|
||
test('hidden (reported) offers round-trip as author:id keys', () async {
|
||
expect(await settings.hiddenOfferKeys(), isEmpty);
|
||
await settings.hideOffer(authorPubkeyHex: 'AB' * 32, offerId: 'tomate-1');
|
||
expect(
|
||
await settings.hiddenOfferKeys(),
|
||
{SocialSettings.offerKey('ab' * 32, 'tomate-1')},
|
||
);
|
||
});
|
||
|
||
group('sharing opt-in', () {
|
||
test('starts unanswered, then round-trips', () async {
|
||
expect(await settings.sharingEnabled(), isNull);
|
||
await settings.setSharingEnabled(true);
|
||
expect(await settings.sharingEnabled(), isTrue);
|
||
await settings.setSharingEnabled(false);
|
||
expect(await settings.sharingEnabled(), isFalse);
|
||
});
|
||
|
||
test('an install that had been through the intro keeps sharing on',
|
||
() async {
|
||
// The upgrade path that must not regress: these people were on a build
|
||
// that connected at launch, so they keep messaging, sync and alerts.
|
||
expect(await settings.migrateSharingEnabled(introSeen: true), isTrue);
|
||
expect(await settings.sharingEnabled(), isTrue);
|
||
});
|
||
|
||
test('a fresh install starts offline', () async {
|
||
expect(await settings.migrateSharingEnabled(introSeen: false), isFalse);
|
||
expect(await settings.sharingEnabled(), isFalse);
|
||
});
|
||
|
||
test('migration never overwrites an answer already given', () async {
|
||
await settings.setSharingEnabled(false);
|
||
// Later launches see the intro as seen; the recorded "no" must survive.
|
||
expect(await settings.migrateSharingEnabled(introSeen: true), isFalse);
|
||
expect(await settings.sharingEnabled(), isFalse);
|
||
});
|
||
});
|
||
}
|