Files
IKAR/test/messages_delivery_test.dart

60 lines
1.5 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:ikar/backend/api.dart';
import 'package:ikar/backend/modules/messages.dart';
import 'package:ikar/core/protocol/opcode_map.dart';
import 'package:ikar/core/protocol/packet.dart';
class _Api extends Api {
final requests = <Map<dynamic, dynamic>>[];
@override
Future<Packet> sendRequest(
int opcode,
Map<dynamic, dynamic> payload, {
void Function()? beforeSend,
bool silent = false,
}) async {
beforeSend?.call();
expect(opcode, Opcode.msgSend);
requests.add(payload);
return Packet(
cmd: CmdType.ok,
opcode: opcode,
payload: {
'message': {'id': 123},
},
);
}
}
void main() {
test(
'retry sends the same CID and prepared wire text to the protocol',
() async {
final api = _Api();
final messages = MessagesModule(api);
for (var attempt = 0; attempt < 2; attempt++) {
expect(
await messages.sendMessage(
42,
7,
'synthetic ciphertext',
clientId: -1700000000000001,
replyToMessageId: 321,
replySourceChatId: 8,
),
'123',
);
}
expect(api.requests[0], api.requests[1]);
expect(api.requests.first['message'], {
'text': 'synthetic ciphertext',
'cid': -1700000000000001,
'elements': [],
'attaches': [],
'link': {'type': 'REPLY', 'chatId': 8, 'messageId': 321},
});
},
);
}