diff --git a/packages/moxxmpp/test/negotiator_test.dart b/packages/moxxmpp/test/negotiator_test.dart index ac58c00..98becc0 100644 --- a/packages/moxxmpp/test/negotiator_test.dart +++ b/packages/moxxmpp/test/negotiator_test.dart @@ -1,5 +1,5 @@ import 'package:moxxmpp/moxxmpp.dart'; -//import 'package:test/test.dart'; +import 'package:test/test.dart'; import 'helpers/logging.dart'; //import 'helpers/xmpp.dart'; @@ -43,67 +43,54 @@ class StubNegotiator2 extends XmppFeatureNegotiatorBase { void main() { initLogger(); - // TODO(Unknown): Directly test the ClientToServerNegotiator. -// final stubSocket = StubTCPSocket( -// [ -// StringExpectation( -// "", -// ''' -// -// -// -// -// ''', -// ), -// ], -// ); + test('Test the priority system', () async { + final features = [ + XMLNode.xmlns(tag: 'example1', xmlns: exampleXmlns1), + XMLNode.xmlns(tag: 'example2', xmlns: exampleXmlns2), + ]; -// final connection = XmppConnection( -// TestingReconnectionPolicy(), -// AlwaysConnectedConnectivityManager(), -// ClientToServerNegotiator(), -// stubSocket, -// ) -// ..registerFeatureNegotiators([ -// StubNegotiator1(), -// StubNegotiator2(), -// ]) -// ..registerManagers([ -// 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), -// ]; + final negotiator = ClientToServerNegotiator() + ..register( + () async {}, + (_) async {}, + () {}, + () => false, + ) + ..registerNegotiator(StubNegotiator1()) + ..registerNegotiator(StubNegotiator2()); + await negotiator.runPostRegisterCallback(); + expect(negotiator.getNextNegotiator(features)?.id, exampleNamespace2); + }); -// test('Test the priority system', () { -// expect(connection.getNextNegotiator(features)?.id, exampleNamespace2); -// }); + test('Test negotiating features with no stream restarts', () async { + final negotiator = ClientToServerNegotiator() + ..register( + () async {}, + (_) async {}, + () {}, + () => false, + ) + ..registerNegotiator(StubNegotiator1()) + ..registerNegotiator(StubNegotiator2()); + await negotiator.runPostRegisterCallback(); -// test('Test negotiating features with no stream restarts', () async { -// await connection.connect(); -// await Future.delayed(const Duration(seconds: 3), () { -// final negotiator1 = -// connection.getNegotiatorById(exampleNamespace1); -// final negotiator2 = -// connection.getNegotiatorById(exampleNamespace2); -// expect(negotiator1?.called, true); -// expect(negotiator2?.called, true); -// }); -// }); + await negotiator.negotiate( + XMLNode.fromString( + ''' + + + +''', + ), + ); + + expect( + negotiator.getNegotiatorById(exampleNamespace1)!.called, + true, + ); + expect( + negotiator.getNegotiatorById(exampleNamespace2)!.called, + true, + ); + }); }