feat(block2): social settings + offers cubit factory (area, relays)

Persistence + wiring the offers screen needs, per the product decisions:
- SocialSettings (keystore-backed, no plaintext): coarse area geohash +
  configurable relay URLs, both empty by default (no bundled public relays —
  don't leak metadata to third parties). Registered in DI.
- createOffersCubit(): opens a SocialSession on the first configured relay when
  online, else a null-transport cubit that degrades gracefully. OffersCubit now
  closes the owning session on dispose.

4 settings tests green; offers/social suites still green.
This commit is contained in:
vjrj 2026-07-10 02:54:06 +02:00
parent 7fd87e6e62
commit 528b499209
4 changed files with 116 additions and 1 deletions

View file

@ -0,0 +1,45 @@
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, no relays, not configured', () async {
expect(await settings.areaGeohash(), '');
expect(await settings.relayUrls(), isEmpty);
expect(await settings.isConfigured, isFalse);
});
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 only with both an area and at least one relay', () async {
await settings.setAreaGeohash('sp3e9');
expect(await settings.isConfigured, isFalse);
await settings.setRelayUrls(['wss://relay.comunes.org']);
expect(await settings.isConfigured, isTrue);
});
}