From c226e1b1691f3bfa765328b03662206439750f85 Mon Sep 17 00:00:00 2001 From: The one with the braid Date: Fri, 13 Dec 2024 16:00:17 +0100 Subject: [PATCH] fix: commands test Signed-off-by: The one with the braid --- lib/src/utils/commands_extension.dart | 21 ++++++++--- test/commands_test.dart | 50 ++------------------------- 2 files changed, 18 insertions(+), 53 deletions(-) diff --git a/lib/src/utils/commands_extension.dart b/lib/src/utils/commands_extension.dart index 48f59df7..2962b156 100644 --- a/lib/src/utils/commands_extension.dart +++ b/lib/src/utils/commands_extension.dart @@ -158,6 +158,7 @@ extension CommandsClientExtension on Client { final roomId = await args.client.createGroupChat( groupName: groupName.isNotEmpty ? groupName : null, enableEncryption: !parts.any((part) => part == '--no-encryption'), + waitForSync: false, ); stdout?.write(DefaultCommandOutput(rooms: [roomId]).toString()); return null; @@ -521,11 +522,21 @@ class DefaultCommandOutput { } if (json['format'] != format) return null; return DefaultCommandOutput( - rooms: json['rooms'] as List?, - events: json['events'] as List?, - users: json['users'] as List?, - messages: json['messages'] as List?, - custom: json['custom'] as Map?, + rooms: json['rooms'] == null + ? null + : List.from(json['rooms'] as Iterable), + events: json['events'] == null + ? null + : List.from(json['events'] as Iterable), + users: json['users'] == null + ? null + : List.from(json['users'] as Iterable), + messages: json['messages'] == null + ? null + : List.from(json['messages'] as Iterable), + custom: json['custom'] == null + ? null + : Map.from(json['custom'] as Map), ); } diff --git a/test/commands_test.dart b/test/commands_test.dart index 6ebd4329..92d0fd6a 100644 --- a/test/commands_test.dart +++ b/test/commands_test.dart @@ -395,7 +395,7 @@ void main() { await room.sendTextEvent('/dm @alice:example.com --no-encryption'); expect( json.decode( - FakeMatrixApi.calledEndpoints['/client/v3/createRoom']?.first, + FakeMatrixApi.calledEndpoints['/client/v3/createRoom']?.last, ), { 'invite': ['@alice:example.com'], @@ -409,7 +409,7 @@ void main() { await room.sendTextEvent('/create New room --no-encryption'); expect( json.decode( - FakeMatrixApi.calledEndpoints['/client/v3/createRoom']?.first, + FakeMatrixApi.calledEndpoints['/client/v3/createRoom']?.last, ), { 'name': 'New room', @@ -535,52 +535,6 @@ void main() { expect(client.prevBatch, null); }); - test('client - dm', () async { - FakeMatrixApi.calledEndpoints.clear(); - final stdout = StringBuffer(); - await client.parseAndRunCommand( - null, - '/dm @alice:example.com --no-encryption', - stdout: stdout, - ); - expect( - json.decode( - FakeMatrixApi.calledEndpoints['/client/v3/createRoom']?.first, - ), - { - 'invite': ['@alice:example.com'], - 'is_direct': true, - 'preset': 'trusted_private_chat', - }); - expect( - (jsonDecode(stdout.toString()) as DefaultCommandOutput).rooms?.first, - '!1234:fakeServer.notExisting', - ); - }); - - test('client - create', () async { - FakeMatrixApi.calledEndpoints.clear(); - final stdout = StringBuffer(); - await client.parseAndRunCommand( - null, - '/create New room --no-encryption', - stdout: stdout, - ); - expect( - json.decode( - FakeMatrixApi.calledEndpoints['/client/v3/createRoom']?.first, - ), - { - 'name': 'New room', - 'preset': 'private_chat', - }, - ); - expect( - (jsonDecode(stdout.toString()) as DefaultCommandOutput).rooms?.first, - '!1234:fakeServer.notExisting', - ); - }); - test('client - missing room - discardsession', () async { Object? error; try {