Merge branch 'spike/block2-derisking'
This commit is contained in:
commit
bd6938c62d
18 changed files with 308 additions and 150 deletions
46
apps/app_seeds/test/services/message_store_test.dart
Normal file
46
apps/app_seeds/test/services/message_store_test.dart
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import 'package:commons_core/commons_core.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/services/message_store.dart';
|
||||
|
||||
import '../support/test_support.dart';
|
||||
|
||||
void main() {
|
||||
late MessageStore store;
|
||||
setUp(() => store = MessageStore(InMemorySecretStore()));
|
||||
|
||||
PrivateMessage msg(String from, String text, int atMs) =>
|
||||
PrivateMessage(
|
||||
fromPubkey: from,
|
||||
text: text,
|
||||
at: DateTime.fromMillisecondsSinceEpoch(atMs));
|
||||
|
||||
test('history is empty for an unknown peer', () async {
|
||||
expect(await store.history('peer'), isEmpty);
|
||||
});
|
||||
|
||||
test('append then history round-trips, oldest first', () async {
|
||||
await store.append('peer', msg('peer', 'hi', 1000));
|
||||
await store.append('peer', msg('me', 'hello', 2000));
|
||||
final history = await store.history('peer');
|
||||
expect(history.map((m) => m.text), ['hi', 'hello']);
|
||||
expect(history.first.fromPubkey, 'peer');
|
||||
expect(history.last.at.millisecondsSinceEpoch, 2000);
|
||||
});
|
||||
|
||||
test('conversations are kept separate per peer', () async {
|
||||
await store.append('a', msg('a', 'toA', 1));
|
||||
await store.append('b', msg('b', 'toB', 1));
|
||||
expect((await store.history('a')).single.text, 'toA');
|
||||
expect((await store.history('b')).single.text, 'toB');
|
||||
});
|
||||
|
||||
test('history is capped to the most recent 200', () async {
|
||||
for (var i = 0; i < 210; i++) {
|
||||
await store.append('peer', msg('me', 'm$i', i));
|
||||
}
|
||||
final history = await store.history('peer');
|
||||
expect(history, hasLength(200));
|
||||
expect(history.first.text, 'm10'); // oldest 10 dropped
|
||||
expect(history.last.text, 'm209');
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue