fix(tests): Fix negotiator tests

This commit is contained in:
PapaTutuWawa 2023-04-03 16:15:46 +02:00
parent 03328bdf7a
commit 355d580a9a

View File

@ -1,5 +1,5 @@
import 'package:moxxmpp/moxxmpp.dart'; import 'package:moxxmpp/moxxmpp.dart';
//import 'package:test/test.dart'; import 'package:test/test.dart';
import 'helpers/logging.dart'; import 'helpers/logging.dart';
//import 'helpers/xmpp.dart'; //import 'helpers/xmpp.dart';
@ -43,67 +43,54 @@ class StubNegotiator2 extends XmppFeatureNegotiatorBase {
void main() { void main() {
initLogger(); initLogger();
// TODO(Unknown): Directly test the ClientToServerNegotiator. test('Test the priority system', () async {
// final stubSocket = StubTCPSocket( final features = [
// [ XMLNode.xmlns(tag: 'example1', xmlns: exampleXmlns1),
// StringExpectation( XMLNode.xmlns(tag: 'example2', xmlns: exampleXmlns2),
// "<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' from='user@test.server' xml:lang='en'>", ];
// '''
// <stream:stream
// xmlns="jabber:client"
// version="1.0"
// xmlns:stream="http://etherx.jabber.org/streams"
// from="test.server"
// xml:lang="en">
// <stream:features xmlns="http://etherx.jabber.org/streams">
// <example1 xmlns="im:moxxmpp:example1" />
// <example2 xmlns="im:moxxmpp:example2" />
// </stream:features>''',
// ),
// ],
// );
// final connection = XmppConnection( final negotiator = ClientToServerNegotiator()
// TestingReconnectionPolicy(), ..register(
// AlwaysConnectedConnectivityManager(), () async {},
// ClientToServerNegotiator(), (_) async {},
// stubSocket, () {},
// ) () => false,
// ..registerFeatureNegotiators([ )
// StubNegotiator1(), ..registerNegotiator(StubNegotiator1())
// StubNegotiator2(), ..registerNegotiator(StubNegotiator2());
// ]) await negotiator.runPostRegisterCallback();
// ..registerManagers([ expect(negotiator.getNextNegotiator(features)?.id, exampleNamespace2);
// PresenceManager(), });
// RosterManager(TestingRosterStateManager('', [])),
// DiscoManager([]),
// EntityCapabilitiesManager('http://moxxmpp.example'),
// ])
// ..setConnectionSettings(
// ConnectionSettings(
// jid: JID.fromString('user@test.server'),
// password: 'abc123',
// useDirectTLS: true,
// ),
// );
// final features = [
// XMLNode.xmlns(tag: 'example1', xmlns: exampleXmlns1),
// XMLNode.xmlns(tag: 'example2', xmlns: exampleXmlns2),
// ];
// test('Test the priority system', () { test('Test negotiating features with no stream restarts', () async {
// expect(connection.getNextNegotiator(features)?.id, exampleNamespace2); final negotiator = ClientToServerNegotiator()
// }); ..register(
() async {},
(_) async {},
() {},
() => false,
)
..registerNegotiator(StubNegotiator1())
..registerNegotiator(StubNegotiator2());
await negotiator.runPostRegisterCallback();
// test('Test negotiating features with no stream restarts', () async { await negotiator.negotiate(
// await connection.connect(); XMLNode.fromString(
// await Future.delayed(const Duration(seconds: 3), () { '''
// final negotiator1 = <stream:features xmlns="http://etherx.jabber.org/streams">
// connection.getNegotiatorById<StubNegotiator1>(exampleNamespace1); <example1 xmlns="im:moxxmpp:example1" />
// final negotiator2 = <example2 xmlns="im:moxxmpp:example2" />
// connection.getNegotiatorById<StubNegotiator2>(exampleNamespace2); </stream:features>''',
// expect(negotiator1?.called, true); ),
// expect(negotiator2?.called, true); );
// });
// }); expect(
negotiator.getNegotiatorById<StubNegotiator1>(exampleNamespace1)!.called,
true,
);
expect(
negotiator.getNegotiatorById<StubNegotiator2>(exampleNamespace2)!.called,
true,
);
});
} }