Files
sepot/app/test/conversation_dedup_test.dart
T
Julius Joska 9985b79aa6 fix(app): ping the relay, retry stuck messages, drop duplicates
A message sent into a dead socket ended up as failed — attachments even
stayed on "sending" forever — and only the user could send it again by
hand. Mobile NAT drops idle TCP silently, so neither side knew.

- pingInterval on the WebSocket, so the client notices a dead link itself
- outbox: after every reconnect, stuck messages are re-sent (batch of 30,
  up to a day old); permanent errors are not retried
- sendAttachment gained the try/catch it was missing, otherwise the
  attachment never reached the outbox
- de-duplicate by message id: a retry re-sends the SAME message, which
  would otherwise show up twice on the other side
2026-08-13 12:23:24 +02:00

44 lines
1.5 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:sepot/models/conversation.dart';
import 'package:sepot/models/message.dart';
/// Id zprávy nese odesílatel, takže tatáž zpráva může dorazit dvakrát:
/// odesílatel ji po výpadku spojení pošle znovu (fronta odchozích) nebo ji
/// relay doručí opakovaně, než dorazí ACK. Ani v jednom případě nesmí
/// vzniknout druhá bublina.
void main() {
Message zprava(String id, {String text = 'ahoj'}) => Message(
id: id,
senderId: 'alice',
recipientId: 'bob',
type: MessageType.text,
content: text,
timestamp: DateTime.parse('2026-08-13T09:00:00.000'),
);
test('zpráva se stejným id se podruhé nepřidá', () {
final c = Conversation(contactId: 'bob');
expect(c.addMessage(zprava('m1')), isTrue, reason: 'první doručení');
expect(c.addMessage(zprava('m1')), isFalse, reason: 'opakované doručení');
expect(c.messages.length, 1);
});
test('dedup se řídí id, ne obsahem — stejný text jinou zprávou projde', () {
final c = Conversation(contactId: 'bob');
expect(c.addMessage(zprava('m1', text: 'ahoj')), isTrue);
expect(c.addMessage(zprava('m2', text: 'ahoj')), isTrue);
expect(c.messages.length, 2);
});
test('duplicita nechá původní zprávu být', () {
final c = Conversation(contactId: 'bob');
c.addMessage(zprava('m1', text: 'původní'));
c.addMessage(zprava('m1', text: 'přepsaný'));
expect(c.messages.single.content, 'původní');
});
}