Skip to content

Commit

Permalink
fix: commands test
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 Jan 30, 2025
1 parent aec2b78 commit c226e1b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 53 deletions.
21 changes: 16 additions & 5 deletions lib/src/utils/commands_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -521,11 +522,21 @@ class DefaultCommandOutput {
}
if (json['format'] != format) return null;
return DefaultCommandOutput(
rooms: json['rooms'] as List<String>?,
events: json['events'] as List<String>?,
users: json['users'] as List<String>?,
messages: json['messages'] as List<String>?,
custom: json['custom'] as Map<String, Object?>?,
rooms: json['rooms'] == null
? null
: List<String>.from(json['rooms'] as Iterable),
events: json['events'] == null
? null
: List<String>.from(json['events'] as Iterable),
users: json['users'] == null
? null
: List<String>.from(json['users'] as Iterable),
messages: json['messages'] == null
? null
: List<String>.from(json['messages'] as Iterable),
custom: json['custom'] == null
? null
: Map<String, Object?>.from(json['custom'] as Map),
);
}

Expand Down
50 changes: 2 additions & 48 deletions test/commands_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c226e1b

Please sign in to comment.