From bb41db7f142dcfd2f9ee7e8d83cdc82dc07c0597 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 8 Aug 2019 09:58:37 +0200 Subject: [PATCH] [Tests] Bugfixes --- lib/src/Client.dart | 6 +++--- lib/src/Room.dart | 2 +- lib/src/RoomList.dart | 1 + test/Client_test.dart | 22 ++++++++++++++-------- test/FakeMatrixApi.dart | 40 +++++++++++++++++++++++++++++++++++++++- 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/lib/src/Client.dart b/lib/src/Client.dart index 6de66c26..c25f59d0 100644 --- a/lib/src/Client.dart +++ b/lib/src/Client.dart @@ -110,14 +110,14 @@ class Client { } } - Map> get directChats => + Map get directChats => accountData["m.direct"] != null ? accountData["m.direct"].content : {}; /// Returns the (first) room ID from the store which is a private chat with the user [userId]. /// Returns null if there is none. String getDirectChatFromUserId(String userId) => accountData["m.direct"] != null && - accountData["m.direct"].content[userId] is List && + accountData["m.direct"].content[userId] is List && accountData["m.direct"].content[userId].length > 0 ? accountData["m.direct"].content[userId][0] : null; @@ -266,7 +266,7 @@ class Client { if (contactDiscoveryRoom != null) contacts = await contactDiscoveryRoom.requestParticipants(); else - contacts = await store.loadContacts(); + contacts = await store?.loadContacts(); return contacts; } diff --git a/lib/src/Room.dart b/lib/src/Room.dart index 4d9e5b26..f9de44bc 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -96,7 +96,7 @@ class Room { /// The address in the format: #roomname:homeserver.org. String get canonicalAlias => states["m.room.canonical_alias"] != null - ? states["m.room.canonical_alias"].content["canonical_alias"] + ? states["m.room.canonical_alias"].content["alias"] : ""; /// If this room is a direct chat, this is the matrix ID of the user diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index 46aac04f..b8079556 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -105,6 +105,7 @@ class RoomList { mInvitedMemberCount: chatUpdate.summary?.mInvitedMemberCount, states: {}, roomAccountData: {}, + client: client, ); rooms.insert(position, newRoom); if (onInsert != null) onInsert(position); diff --git a/test/Client_test.dart b/test/Client_test.dart index 3cb89782..11183ae5 100644 --- a/test/Client_test.dart +++ b/test/Client_test.dart @@ -62,9 +62,9 @@ void main() { matrix.connection.onError.stream.first; final bool checkResp1 = - await matrix.checkServer("https://fakeServer.wrongaddress"); + await matrix.checkServer("https://fakeserver.wrongaddress"); final bool checkResp2 = - await matrix.checkServer("https://fakeServer.notExisting"); + await matrix.checkServer("https://fakeserver.notexisting"); ErrorResponse checkError = await errorFuture; @@ -108,8 +108,17 @@ void main() { expect(firstSync, true); expect(sync["next_batch"] == matrix.prevBatch, true); - expect(matrix.accountData.length, 1); - expect(matrix.presences.length, 0); + expect(matrix.accountData.length, 2); + expect(matrix.getDirectChatFromUserId("@bob:example.com"), + "!abcdefgh:example.com"); + expect(matrix.directChats, matrix.accountData["m.direct"].content); + expect(matrix.presences.length, 1); + expect(matrix.roomList.rooms.length, 2); + expect(matrix.roomList.rooms[1].canonicalAlias, + "#famedlyContactDiscovery:${matrix.userID.split(":")[1]}"); + final List contacts = await matrix.loadFamedlyContacts(); + expect(contacts.length, 1); + expect(contacts[0].senderId, "@alice:example.com"); }); test('Try to get ErrorResponse', () async { @@ -212,16 +221,13 @@ void main() { List eventUpdateList = await userUpdateListFuture; - expect(eventUpdateList.length, 3); + expect(eventUpdateList.length, 4); expect(eventUpdateList[0].eventType == "m.presence", true); expect(eventUpdateList[0].type == "presence", true); expect(eventUpdateList[1].eventType == "org.example.custom.config", true); expect(eventUpdateList[1].type == "account_data", true); - - expect(eventUpdateList[2].eventType == "m.new_device", true); - expect(eventUpdateList[2].type == "to_device", true); }); testWidgets('should get created', create); diff --git a/test/FakeMatrixApi.dart b/test/FakeMatrixApi.dart index 5f3e8a96..bda93ad8 100644 --- a/test/FakeMatrixApi.dart +++ b/test/FakeMatrixApi.dart @@ -153,6 +153,24 @@ class FakeMatrixApi extends MockClient { {"type": "m.login.password"} ] }, + "/client/r0/rooms/!726s6s6q:example.com/members": (var req) => { + "chunk": [ + { + "content": { + "membership": "join", + "avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF", + "displayname": "Alice Margatroid" + }, + "type": "m.room.member", + "event_id": "ยง143273582443PhrSn:example.org", + "room_id": "!636q39766251:example.com", + "sender": "@alice:example.org", + "origin_server_ts": 1432735824653, + "unsigned": {"age": 1234}, + "state_key": "@alice:example.org" + } + ] + }, "/client/r0/rooms/!localpart:server.abc/members": (var req) => { "chunk": [ { @@ -333,7 +351,16 @@ class FakeMatrixApi extends MockClient { { "type": "org.example.custom.config", "content": {"custom_config_key": "custom_config_value"} - } + }, + { + "content": { + "@bob:example.com": [ + "!abcdefgh:example.com", + "!hgfedcba:example.com" + ] + }, + "type": "m.direct" + }, ] }, "to_device": { @@ -364,6 +391,17 @@ class FakeMatrixApi extends MockClient { "content": {"membership": "join"}, "origin_server_ts": 1417731086795, "event_id": "66697273743031:example.com" + }, + { + "sender": "@alice:example.com", + "type": "m.room.canonical_alias", + "content": { + "alias": + "#famedlyContactDiscovery:fakeServer.notExisting" + }, + "state_key": "", + "origin_server_ts": 1417731086796, + "event_id": "66697273743032:example.com" } ] },