chore: Add markasdm/group tests

This commit is contained in:
Nicolas Werner 2022-08-09 15:33:59 +02:00
parent 694187d5f1
commit 064b84305d
2 changed files with 75 additions and 10 deletions

View File

@ -1233,17 +1233,21 @@ class Room {
/// Removes this room from all direct chat tags.
Future<void> removeFromDirectChat() async {
final directChats = client.directChats;
if (directChats[directChatMatrixID] is List &&
directChats[directChatMatrixID].contains(id)) {
directChats[directChatMatrixID].remove(id);
} else {
return;
} // Nothing to do here
final directChats = client.directChats.copy();
for (final k in directChats.keys) {
if (directChats[k] is List && directChats[k].contains(id)) {
directChats[k].remove(id);
}
}
await client.setAccountDataPerRoom(
directChats.removeWhere((_, v) => v is List && v.isEmpty);
if (directChats == client.directChats) {
return;
}
await client.setAccountData(
client.userID!,
id,
'm.direct',
directChats,
);

View File

@ -312,7 +312,68 @@ void main() {
}
});
test('create', () async {
test('markasdm', () async {
FakeMatrixApi.calledEndpoints.clear();
await room.sendTextEvent('/markasdm @fakealice:example.com');
expect(
json.decode(FakeMatrixApi
.calledEndpoints[
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
?.first)?['@alice:example.com'],
['!1234:fakeServer.notExisting']);
expect(
json.decode(FakeMatrixApi
.calledEndpoints[
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
?.first)?['@fakealice:example.com'],
['!1234:fakeServer.notExisting']);
expect(
json
.decode(FakeMatrixApi
.calledEndpoints[
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
?.first)
.entries
.any((e) =>
e.key != '@fakealice:example.com' &&
e.key != '@alice:example.com' &&
e.value.contains('!1234:fakeServer.notExisting')),
false);
FakeMatrixApi.calledEndpoints.clear();
await room.sendTextEvent('/markasdm');
expect(
json.decode(FakeMatrixApi
.calledEndpoints[
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
?.first)?[''],
['!1234:fakeServer.notExisting']);
});
test('markasgroup', () async {
FakeMatrixApi.calledEndpoints.clear();
await room.sendTextEvent('/markasgroup');
expect(
json
.decode(FakeMatrixApi
.calledEndpoints[
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
?.first)
?.containsKey('@alice:example.com'),
false);
expect(
json
.decode(FakeMatrixApi
.calledEndpoints[
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
?.first)
.entries
.any((e) => (e.value as List<dynamic>)
.contains('!1234:fakeServer.notExisting')),
false);
});
test('clearcache', () async {
await room.sendTextEvent('/clearcache');
expect(room.client.prevBatch, null);
});