feat(market): save others' offers as favorites (Wallapop-style)
Adds a Favorites feature: a heart on the offer detail saves another person's listing to an encrypted, per-identity SavedOffersStore (keystore JSON snapshot, no plaintext at rest). A new /favorites screen (wired from the drawer) lists saved offers offline-first and, when a relay is reachable, flags ones that are gone as "no longer available". i18n en/es/pt/ast; store + screen + detail-heart tests.
This commit is contained in:
parent
f6967e8cbb
commit
d6225eed38
19 changed files with 806 additions and 3 deletions
100
apps/app_seeds/test/services/saved_offers_store_test.dart
Normal file
100
apps/app_seeds/test/services/saved_offers_store_test.dart
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import 'package:commons_core/commons_core.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/services/saved_offers_store.dart';
|
||||
|
||||
import '../support/test_support.dart';
|
||||
|
||||
Offer _offer(
|
||||
String id, {
|
||||
String author = 'aa',
|
||||
OfferType type = OfferType.gift,
|
||||
num? price,
|
||||
String? currency,
|
||||
String geohash = 'u09',
|
||||
}) => Offer(
|
||||
id: id,
|
||||
authorPubkeyHex: author,
|
||||
summary: 'Tomate $id',
|
||||
type: type,
|
||||
approxGeohash: geohash,
|
||||
priceAmount: price,
|
||||
priceCurrency: currency,
|
||||
isOrganic: true,
|
||||
);
|
||||
|
||||
void main() {
|
||||
late SavedOffersStore store;
|
||||
|
||||
setUp(() => store = SavedOffersStore(InMemorySecretStore()));
|
||||
|
||||
test('keyOf is the author:id coordinate', () {
|
||||
expect(SavedOffersStore.keyOf(_offer('x', author: 'bb')), 'bb:x');
|
||||
});
|
||||
|
||||
test('starts empty', () async {
|
||||
expect(await store.list(), isEmpty);
|
||||
expect(await store.isSaved('aa:x'), isFalse);
|
||||
});
|
||||
|
||||
test('save then list round-trips every field', () async {
|
||||
await store.save(
|
||||
_offer('1', type: OfferType.sale, price: 3, currency: 'Ğ1'),
|
||||
savedAt: 100,
|
||||
);
|
||||
final saved = await store.list();
|
||||
expect(saved, hasLength(1));
|
||||
final o = saved.single;
|
||||
expect(o.id, '1');
|
||||
expect(o.authorPubkeyHex, 'aa');
|
||||
expect(o.type, OfferType.sale);
|
||||
expect(o.priceAmount, 3);
|
||||
expect(o.priceCurrency, 'Ğ1');
|
||||
expect(o.isOrganic, isTrue);
|
||||
expect(await store.isSaved('aa:1'), isTrue);
|
||||
});
|
||||
|
||||
test('list is newest-first by savedAt', () async {
|
||||
await store.save(_offer('old'), savedAt: 100);
|
||||
await store.save(_offer('new'), savedAt: 200);
|
||||
expect([for (final o in await store.list()) o.id], ['new', 'old']);
|
||||
});
|
||||
|
||||
test('saving the same coordinate again de-duplicates', () async {
|
||||
await store.save(_offer('1'), savedAt: 100);
|
||||
await store.save(_offer('1'), savedAt: 200); // same author:id
|
||||
expect(await store.list(), hasLength(1));
|
||||
});
|
||||
|
||||
test('remove drops it', () async {
|
||||
await store.save(_offer('1'), savedAt: 100);
|
||||
await store.remove('aa:1');
|
||||
expect(await store.list(), isEmpty);
|
||||
expect(await store.isSaved('aa:1'), isFalse);
|
||||
});
|
||||
|
||||
test('toggle saves then removes and reports the new state', () async {
|
||||
expect(await store.toggle(_offer('1'), savedAt: 100), isTrue);
|
||||
expect(await store.isSaved('aa:1'), isTrue);
|
||||
expect(await store.toggle(_offer('1'), savedAt: 200), isFalse);
|
||||
expect(await store.isSaved('aa:1'), isFalse);
|
||||
});
|
||||
|
||||
test('scopes are isolated by account', () async {
|
||||
final secret = InMemorySecretStore();
|
||||
final a = SavedOffersStore(secret, accountScope: 'acct1');
|
||||
final b = SavedOffersStore(secret, accountScope: 'acct2');
|
||||
await a.save(_offer('1'), savedAt: 100);
|
||||
expect(await a.list(), hasLength(1));
|
||||
expect(await b.list(), isEmpty);
|
||||
});
|
||||
|
||||
test('changes stream fires on save and remove', () async {
|
||||
final events = <void>[];
|
||||
final sub = store.changes.listen(events.add);
|
||||
await store.save(_offer('1'), savedAt: 100);
|
||||
await store.remove('aa:1');
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(events, hasLength(2));
|
||||
await sub.cancel();
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue