fix(tests): Fix SFS parsing test

This commit is contained in:
PapaTutuWawa 2023-06-06 21:31:14 +02:00
parent 60279a84e0
commit 968604b0ba
16 changed files with 68 additions and 30 deletions

View File

@ -16,7 +16,9 @@ import 'package:moxxmpp/src/xeps/xep_0461.dart';
/// A callback that is called whenever a message is sent using /// A callback that is called whenever a message is sent using
/// [MessageManager.sendMessage]. The input the typed map that is passed to /// [MessageManager.sendMessage]. The input the typed map that is passed to
/// sendMessage. /// sendMessage.
typedef MessageSendingCallback = List<XMLNode> Function(TypedMap<StanzaHandlerExtension>); typedef MessageSendingCallback = List<XMLNode> Function(
TypedMap<StanzaHandlerExtension>,
);
/// The raw content of the <body /> element. /// The raw content of the <body /> element.
class MessageBodyData { class MessageBodyData {
@ -85,7 +87,10 @@ class MessageManager extends XmppManagerBase {
/// Send an unawaitable message to [to]. [extensions] is a typed map that contains /// Send an unawaitable message to [to]. [extensions] is a typed map that contains
/// data for building the message. /// data for building the message.
Future<void> sendMessage(JID to, TypedMap<StanzaHandlerExtension> extensions) async { Future<void> sendMessage(
JID to,
TypedMap<StanzaHandlerExtension> extensions,
) async {
await getAttributes().sendStanza( await getAttributes().sendStanza(
StanzaDetails( StanzaDetails(
Stanza.message( Stanza.message(
@ -102,7 +107,9 @@ class MessageManager extends XmppManagerBase {
); );
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
if (extensions.get<ReplyData>() != null) { if (extensions.get<ReplyData>() != null) {
return []; return [];
} }

View File

@ -141,7 +141,9 @@ class FileUploadNotificationManager extends XmppManagerBase {
); );
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final fun = extensions.get<FileUploadNotificationData>(); final fun = extensions.get<FileUploadNotificationData>();
if (fun != null) { if (fun != null) {
return [fun.toXML()]; return [fun.toXML()];

View File

@ -68,7 +68,9 @@ class OOBManager extends XmppManagerBase {
); );
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<OOBData>(); final data = extensions.get<OOBData>();
return data != null return data != null
? [ ? [

View File

@ -112,7 +112,9 @@ class ChatStateManager extends XmppManagerBase {
); );
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<ChatState>(); final data = extensions.get<ChatState>();
return data != null return data != null
? [ ? [

View File

@ -104,7 +104,9 @@ class MessageDeliveryReceiptManager extends XmppManagerBase {
return state..done = true; return state..done = true;
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<MessageDeliveryReceivedData>(); final data = extensions.get<MessageDeliveryReceivedData>();
return data != null return data != null
? [ ? [

View File

@ -66,7 +66,7 @@ enum HashFunction {
return HashFunction.blake2b512; return HashFunction.blake2b512;
} }
throw Exception(); throw Exception('Invalid hash function $name');
} }
/// Like [HashFunction.fromName], but returns null if the hash function is unknown /// Like [HashFunction.fromName], but returns null if the hash function is unknown

View File

@ -57,7 +57,9 @@ class LastMessageCorrectionManager extends XmppManagerBase {
); );
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<LastMessageCorrectionData>(); final data = extensions.get<LastMessageCorrectionData>();
return data != null return data != null
? [ ? [

View File

@ -17,9 +17,12 @@ enum ChatMarker {
factory ChatMarker.fromName(String name) { factory ChatMarker.fromName(String name) {
switch (name) { switch (name) {
case 'received': return ChatMarker.received; case 'received':
case 'displayed': return ChatMarker.displayed; return ChatMarker.received;
case 'acknowledged': return ChatMarker.acknowledged; case 'displayed':
return ChatMarker.displayed;
case 'acknowledged':
return ChatMarker.acknowledged;
} }
throw Exception('Invalid chat marker $name'); throw Exception('Invalid chat marker $name');
@ -129,7 +132,9 @@ class ChatMarkerManager extends XmppManagerBase {
return state..done = true; return state..done = true;
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final children = List<XMLNode>.empty(growable: true); final children = List<XMLNode>.empty(growable: true);
final marker = extensions.get<ChatMarkerData>(); final marker = extensions.get<ChatMarkerData>();
if (marker != null) { if (marker != null) {
@ -149,6 +154,8 @@ class ChatMarkerManager extends XmppManagerBase {
await super.postRegisterCallback(); await super.postRegisterCallback();
// Register the sending callback // Register the sending callback
getAttributes().getManagerById<MessageManager>(messageManager)?.registerMessageSendingCallback(_messageSendingCallback); getAttributes()
.getManagerById<MessageManager>(messageManager)
?.registerMessageSendingCallback(_messageSendingCallback);
} }
} }

View File

@ -87,16 +87,18 @@ class MessageProcessingHintManager extends XmppManagerBase {
return state return state
..extensions.set( ..extensions.set(
MessageProcessingHintData( MessageProcessingHintData(
elements.map((element) => MessageProcessingHint.fromName(element.tag)).toList(), elements
.map((element) => MessageProcessingHint.fromName(element.tag))
.toList(),
), ),
); );
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<MessageProcessingHintData>(); final data = extensions.get<MessageProcessingHintData>();
return data != null return data != null ? data.hints.map((hint) => hint.toXML()).toList() : [];
? data.hints.map((hint) => hint.toXML()).toList()
: [];
} }
@override @override

View File

@ -123,7 +123,9 @@ class StableIdManager extends XmppManagerBase {
); );
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<StableIdData>(); final data = extensions.get<StableIdData>();
return data != null ? data.toXML() : []; return data != null ? data.toXML() : [];
} }

View File

@ -63,7 +63,9 @@ class MessageRetractionManager extends XmppManagerBase {
); );
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<MessageRetractionData>(); final data = extensions.get<MessageRetractionData>();
return data != null return data != null
? [ ? [

View File

@ -69,7 +69,9 @@ class MessageReactionsManager extends XmppManagerBase {
); );
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<MessageReactions>(); final data = extensions.get<MessageReactions>();
return data != null return data != null
? [ ? [

View File

@ -140,7 +140,9 @@ class SFSManager extends XmppManagerBase {
@override @override
Future<bool> isSupported() async => true; Future<bool> isSupported() async => true;
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<StatelessFileSharingData>(); final data = extensions.get<StatelessFileSharingData>();
if (data == null) { if (data == null) {
return []; return [];

View File

@ -270,7 +270,9 @@ class StickersManager extends XmppManagerBase {
); );
} }
List<XMLNode> _messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> _messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<StickersData>(); final data = extensions.get<StickersData>();
return data != null return data != null
? [ ? [

View File

@ -103,7 +103,9 @@ class MessageRepliesManager extends XmppManagerBase {
Future<bool> isSupported() async => true; Future<bool> isSupported() async => true;
@visibleForTesting @visibleForTesting
List<XMLNode> messageSendingCallback(TypedMap<StanzaHandlerExtension> extensions) { List<XMLNode> messageSendingCallback(
TypedMap<StanzaHandlerExtension> extensions,
) {
final data = extensions.get<ReplyData>(); final data = extensions.get<ReplyData>();
return data != null return data != null
? [ ? [

View File

@ -13,7 +13,7 @@ void main() {
<size>3032449</size> <size>3032449</size>
<dimensions>4096x2160</dimensions> <dimensions>4096x2160</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha3-256'>2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU=</hash> <hash xmlns='urn:xmpp:hashes:2' algo='sha3-256'>2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU=</hash>
<hash xmlns='urn:xmpp:hashes:2' algo='id-blake2b256'>2AfMGH8O7UNPTvUVAM9aK13mpCY=</hash> <hash xmlns='urn:xmpp:hashes:2' algo='blake2b-256'>2AfMGH8O7UNPTvUVAM9aK13mpCY=</hash>
<desc>Photo from the summit.</desc> <desc>Photo from the summit.</desc>
<thumbnail xmlns='urn:xmpp:thumbs:1' uri='cid:sha1+ffd7c8d28e9c5e82afea41f97108c6b4@bob.xmpp.org' media-type='image/png' width='128' height='96'/> <thumbnail xmlns='urn:xmpp:thumbs:1' uri='cid:sha1+ffd7c8d28e9c5e82afea41f97108c6b4@bob.xmpp.org' media-type='image/png' width='128' height='96'/>
</file> </file>
@ -28,11 +28,11 @@ void main() {
); );
expect( expect(
sfs.metadata.hashes['sha3-256'], sfs.metadata.hashes[HashFunction.sha3_256],
'2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU=', '2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU=',
); );
expect( expect(
sfs.metadata.hashes['id-blake2b256'], sfs.metadata.hashes[HashFunction.blake2b256],
'2AfMGH8O7UNPTvUVAM9aK13mpCY=', '2AfMGH8O7UNPTvUVAM9aK13mpCY=',
); );
}); });