From cacf7cc530c824962973106184e80f60b004f183 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Wed, 7 Aug 2019 12:27:02 +0200 Subject: [PATCH] [Tests] Fix some tests --- lib/src/Connection.dart | 23 ++++++++++++----------- lib/src/Room.dart | 6 +++--- lib/src/RoomList.dart | 2 ++ lib/src/State.dart | 14 +++++++++++++- test/Client_test.dart | 3 +++ test/Event_test.dart | 24 +++++++----------------- 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/lib/src/Connection.dart b/lib/src/Connection.dart index ab312a9c..adc202e2 100644 --- a/lib/src/Connection.dart +++ b/lib/src/Connection.dart @@ -149,24 +149,25 @@ class Connection { client.lazyLoadMembers = newLazyLoadMembers; client.prevBatch = newPrevBatch; + List rooms = []; if (client.store != null) { client.store.storeClient(); - - List rooms = await client.store + rooms = await client.store .getRoomList(onlyLeft: false, onlyGroups: false, onlyDirect: false); - client.roomList = RoomList( - client: client, - onlyLeft: false, - onlyDirect: false, - onlyGroups: false, - onUpdate: null, - onInsert: null, - onRemove: null, - rooms: rooms); client.accountData = await client.store.getAccountData(); client.presences = await client.store.getPresences(); } + client.roomList = RoomList( + client: client, + onlyLeft: false, + onlyDirect: false, + onlyGroups: false, + onUpdate: null, + onInsert: null, + onRemove: null, + rooms: rooms); + _userEventSub ??= onUserEvent.stream.listen(client.handleUserUpdate); onLoginStateChanged.add(LoginState.logged); diff --git a/lib/src/Room.dart b/lib/src/Room.dart index 04fa9c54..4d9e5b26 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -54,9 +54,9 @@ class Room { int mJoinedMemberCount; int mInvitedMemberCount; - Map states; + Map states = {}; - Map roomAccountData; + Map roomAccountData = {}; /// Time when the user has last read the chat. ChatTime unread; @@ -105,7 +105,7 @@ class Room { /// Must be one of [all, mention] String notificationSettings; - Event get lastEvent => states["m.room.message"] as Event; + Event get lastEvent => states["m.room.message"]?.timelineEvent; /// Your current client instance. final Client client; diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index 1a160b51..46aac04f 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -103,6 +103,8 @@ class RoomList { mHeroes: chatUpdate.summary?.mHeroes, mJoinedMemberCount: chatUpdate.summary?.mJoinedMemberCount, mInvitedMemberCount: chatUpdate.summary?.mInvitedMemberCount, + states: {}, + roomAccountData: {}, ); rooms.insert(position, newRoom); if (onInsert != null) onInsert(position); diff --git a/lib/src/State.dart b/lib/src/State.dart index dfd55020..15b8eef1 100644 --- a/lib/src/State.dart +++ b/lib/src/State.dart @@ -80,7 +80,19 @@ class State extends RawEvent { room: room); } + Event get timelineEvent => Event( + content: content, + typeKey: typeKey, + eventId: eventId, + room: room, + roomId: roomId, + senderId: senderId, + time: time, + unsigned: unsigned, + status: 1, + ); + /// The unique key of this event. For events with a [stateKey], it will be the /// stateKey. Otherwise it will be the [type] as a string. - String get key => stateKey != null || stateKey.isEmpty ? type : stateKey; + String get key => stateKey == null || stateKey.isEmpty ? typeKey : stateKey; } diff --git a/test/Client_test.dart b/test/Client_test.dart index 40460393..3cb89782 100644 --- a/test/Client_test.dart +++ b/test/Client_test.dart @@ -107,6 +107,9 @@ void main() { expect(loginState, LoginState.logged); expect(firstSync, true); expect(sync["next_batch"] == matrix.prevBatch, true); + + expect(matrix.accountData.length, 1); + expect(matrix.presences.length, 0); }); test('Try to get ErrorResponse', () async { diff --git a/test/Event_test.dart b/test/Event_test.dart index a6356591..1e501b6c 100644 --- a/test/Event_test.dart +++ b/test/Event_test.dart @@ -24,8 +24,7 @@ import 'dart:convert'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/src/Event.dart'; -import 'package:famedlysdk/src/User.dart'; +import 'package:famedlysdk/src/RawEvent.dart'; import 'package:flutter_test/flutter_test.dart'; import 'FakeMatrixApi.dart'; @@ -36,9 +35,6 @@ void main() { final int timestamp = DateTime.now().millisecondsSinceEpoch; final String id = "!4fsdfjisjf:server.abc"; final String senderID = "@alice:server.abc"; - final String senderDisplayname = "Alice"; - final String empty = ""; - final Membership membership = Membership.join; final String type = "m.room.message"; final String msgtype = "m.text"; final String body = "Hello World"; @@ -49,24 +45,18 @@ void main() { Map jsonObj = { "event_id": id, - "matrix_id": senderID, - "displayname": senderDisplayname, - "avatar_url": empty, - "membership": membership.toString().split('.').last, + "sender": senderID, "origin_server_ts": timestamp, - "state_key": empty, "type": type, - "content_json": contentJson, + "status": 2, + "content": contentJson, }; test("Create from json", () async { Event event = Event.fromJson(jsonObj, null); - expect(event.id, id); - expect(event.sender.id, senderID); - expect(event.sender.displayName, senderDisplayname); - expect(event.sender.avatarUrl.mxc, empty); - expect(event.sender.membership, membership); + expect(event.eventId, id); + expect(event.senderId, senderID); expect(event.status, 2); expect(event.text, body); expect(event.formattedText, formatted_body); @@ -121,7 +111,7 @@ void main() { expect(event.type, EventTypes.HistoryVisibility); jsonObj["type"] = "m.room.message"; - jsonObj["content"] = json.decode(jsonObj["content_json"]); + jsonObj["content"] = json.decode(jsonObj["content"]); jsonObj["content"]["msgtype"] = "m.notice"; event = Event.fromJson(jsonObj, null);