From 70c2de86403638a7a59ef0ceab05402777050c3a Mon Sep 17 00:00:00 2001 From: The one with the braid Date: Thu, 7 Nov 2024 18:53:51 +0100 Subject: [PATCH] feat: add non-room related command_runner tests Signed-off-by: The one with the braid --- test/commands_test.dart | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/commands_test.dart b/test/commands_test.dart index 5528da27..7cc5f911 100644 --- a/test/commands_test.dart +++ b/test/commands_test.dart @@ -527,6 +527,58 @@ void main() { expect(sent, CuteEventContent.cuddle); }); + test('client - clearcache', () async { + await client.parseAndRunCommand(null, '/clearcache'); + 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 @alice:example.com --no-encryption', + stdout: stdout); + expect( + json.decode( + FakeMatrixApi.calledEndpoints['/client/v3/createRoom']?.first), + {'preset': 'private_chat'}); + expect( + (jsonDecode(stdout.toString()) as DefaultCommandOutput).rooms?.first, + '!1234:fakeServer.notExisting', + ); + }); + + test('client - missing room - discardsession', () async { + Object? error; + try { + await client.parseAndRunCommand(null, '/discardsession'); + } catch (e) { + error = e; + } + + expect(error is RoomCommandException, isTrue); + }); + test('dispose client', () async { await client.dispose(closeDatabase: true); });