Skip to content

Commit

Permalink
feat: add non-room related command_runner tests
Browse files Browse the repository at this point in the history
Signed-off-by: The one with the braid <[email protected]>
  • Loading branch information
TheOneWithTheBraid committed Dec 7, 2024
1 parent e9f6f72 commit 70c2de8
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/commands_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 70c2de8

Please sign in to comment.