From 06bcf90d6e8b166a178c31839f7fe6a622116f13 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Wed, 12 Jun 2019 10:04:54 +0200 Subject: [PATCH] Fix tests --- lib/src/User.dart | 24 +++++++++++++----------- test/Event_test.dart | 2 +- test/Room_test.dart | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/src/User.dart b/lib/src/User.dart index 2d11c6e..4b777ce 100644 --- a/lib/src/User.dart +++ b/lib/src/User.dart @@ -21,13 +21,13 @@ * along with Foobar. If not, see . */ +import 'package:famedlysdk/src/responses/ErrorResponse.dart'; import 'package:famedlysdk/src/Client.dart'; import 'package:famedlysdk/src/utils/MxContent.dart'; import 'package:famedlysdk/src/Room.dart'; /// Represents a Matrix User which may be a participant in a Matrix Room. class User { - /// The full qualified Matrix ID in the format @username:server.abc. final String id; @@ -62,7 +62,8 @@ class User { @Deprecated("Use avatarUrl instead!") MxContent get avatar_url => avatarUrl; - User(this.id, { + User( + this.id, { this.membership, this.displayName, this.avatarUrl, @@ -72,10 +73,9 @@ class User { /// Returns the displayname or the local part of the Matrix ID if the user /// has no displayname. - String calcDisplayname() => - displayName.isEmpty - ? mxid.replaceFirst("@", "").split(":")[0] - : displayName; + String calcDisplayname() => displayName.isEmpty + ? mxid.replaceFirst("@", "").split(":")[0] + : displayName; /// Creates a new User object from a json string like a row from the database. static User fromJson(Map json, Room room) { @@ -90,13 +90,15 @@ class User { /// Checks if the client's user has the permission to kick this user. Future get canKick async { final int ownPowerLevel = await room.client.store.getPowerLevel(room.id); - return ownPowerLevel > powerLevel && ownPowerLevel >= room.powerLevels["power_kick"]; + return ownPowerLevel > powerLevel && + ownPowerLevel >= room.powerLevels["power_kick"]; } /// Checks if the client's user has the permission to ban or unban this user. Future get canBan async { final int ownPowerLevel = await room.client.store.getPowerLevel(room.id); - return ownPowerLevel > powerLevel && ownPowerLevel >= room.powerLevels["power_ban"]; + return ownPowerLevel > powerLevel && + ownPowerLevel >= room.powerLevels["power_ban"]; } /// Call the Matrix API to kick this user from this room. @@ -130,8 +132,9 @@ class User { if (roomID != null) return roomID; // Start a new direct chat - Map resp = await room.client.connection.jsonRequest(type: "POST", action: "/client/r0/createRoom", data: { - "invite": [ id ], + Map resp = await room.client.connection + .jsonRequest(type: "POST", action: "/client/r0/createRoom", data: { + "invite": [id], "is_direct": true, "preset": "trusted_private_chat" }); @@ -145,5 +148,4 @@ class User { return resp["room_id"]; } - } diff --git a/test/Event_test.dart b/test/Event_test.dart index f65e2fa..959fd92 100644 --- a/test/Event_test.dart +++ b/test/Event_test.dart @@ -66,7 +66,7 @@ void main() { expect(event.status, status); expect(event.text, body); expect(event.formattedText, formatted_body); - expect(event.getBody(), formatted_body); + expect(event.getBody(), body); expect(event.type, EventTypes.Text); }); }); diff --git a/test/Room_test.dart b/test/Room_test.dart index 2b1b3e3..4ac607b 100644 --- a/test/Room_test.dart +++ b/test/Room_test.dart @@ -107,7 +107,7 @@ void main() { expect(room.guestAccess, guestAccess); expect(room.historyVisibility, historyVisibility); expect(room.joinRules, joinRules); - expect(room.lastMessage, "Hello World"); + expect(room.lastMessage, body); expect(room.timeCreated.toTimeStamp() >= now, true); room.powerLevels.forEach((String key, int value) { expect(value, 0);