From f0538b044751d0ae203cd3138ee4535acd764b7a Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Tue, 6 Jun 2023 21:46:33 +0200 Subject: [PATCH] feat(xep): Write a test for XEP-0334 --- packages/moxxmpp/lib/src/xeps/xep_0334.dart | 1 - packages/moxxmpp/test/xeps/xep_0334_test.dart | 148 ++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 packages/moxxmpp/test/xeps/xep_0334_test.dart diff --git a/packages/moxxmpp/lib/src/xeps/xep_0334.dart b/packages/moxxmpp/lib/src/xeps/xep_0334.dart index 34b76c5..dd76cec 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0334.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0334.dart @@ -78,7 +78,6 @@ class MessageProcessingHintManager extends XmppManagerBase { ), ]; - // TODO: Test Future _onMessage( Stanza stanza, StanzaHandlerData state, diff --git a/packages/moxxmpp/test/xeps/xep_0334_test.dart b/packages/moxxmpp/test/xeps/xep_0334_test.dart new file mode 100644 index 0000000..f53445c --- /dev/null +++ b/packages/moxxmpp/test/xeps/xep_0334_test.dart @@ -0,0 +1,148 @@ +import 'package:moxxmpp/moxxmpp.dart'; +import 'package:moxxmpp/src/util/typed_map.dart'; +import 'package:test/test.dart'; + +import '../helpers/manager.dart'; +import '../helpers/xmpp.dart'; + +void main() { + test('Test receiving a message processing hint', () async { + final fakeSocket = StubTCPSocket( + [ + StringExpectation( + "", + ''' + + + + PLAIN + + ''', + ), + StringExpectation( + "AHBvbHlub21kaXZpc2lvbgBhYWFh", + '', + ), + StringExpectation( + "", + ''' + + + + + + + + + + + +''', + ), + StanzaExpectation( + '', + 'polynomdivision@test.server/MU29eEZn', + ignoreId: true, + ), + ], + ); + final conn = XmppConnection( + TestingReconnectionPolicy(), + AlwaysConnectedConnectivityManager(), + ClientToServerNegotiator(), + fakeSocket, + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + ); + await conn.registerManagers([ + MessageManager(), + MessageProcessingHintManager(), + ]); + await conn.registerFeatureNegotiators([ + SaslPlainNegotiator(), + ResourceBindingNegotiator(), + ]); + await conn.connect( + shouldReconnect: false, + enableReconnectOnSuccess: false, + waitUntilLogin: true, + ); + + MessageEvent? messageEvent; + conn.asBroadcastStream().listen((event) { + if (event is MessageEvent) { + messageEvent = event; + } + }); + + // Send the fake message + fakeSocket.injectRawXml( + ''' + + + + +''', + ); + + await Future.delayed(const Duration(seconds: 2)); + expect( + messageEvent!.extensions + .get()! + .hints + .contains(MessageProcessingHint.noCopies), + true, + ); + expect( + messageEvent!.extensions + .get()! + .hints + .contains(MessageProcessingHint.noStore), + true, + ); + }); + + test('Test sending a message processing hint', () async { + final manager = MessageManager(); + final holder = TestingManagerHolder( + stubSocket: StubTCPSocket([ + StanzaExpectation( + ''' + + + + +''', + '', + ) + ]), + ); + + await holder.register([ + manager, + MessageProcessingHintManager(), + ]); + + await manager.sendMessage( + JID.fromString('user@example.org'), + TypedMap() + ..set( + const MessageProcessingHintData([ + MessageProcessingHint.noCopies, + MessageProcessingHint.noStore, + ]), + ), + ); + }); +}