2019-06-11 10:21:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Zender & Kurtz GbR.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Christian Pauly <krille@famedly.com>
|
|
|
|
* Marcel Radzio <mtrnord@famedly.com>
|
|
|
|
*
|
|
|
|
* This file is part of famedlysdk.
|
|
|
|
*
|
|
|
|
* famedlysdk is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* famedlysdk is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-06-21 12:38:07 +00:00
|
|
|
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
|
2019-06-11 10:21:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import 'package:famedlysdk/src/Client.dart';
|
2019-06-28 08:59:00 +00:00
|
|
|
import 'package:famedlysdk/src/Event.dart';
|
2019-07-12 09:26:07 +00:00
|
|
|
import 'package:famedlysdk/src/Room.dart';
|
2019-08-08 09:41:42 +00:00
|
|
|
import 'package:famedlysdk/src/State.dart';
|
|
|
|
import 'package:famedlysdk/src/Timeline.dart';
|
2019-06-18 10:06:55 +00:00
|
|
|
import 'package:famedlysdk/src/User.dart';
|
2019-08-08 09:41:42 +00:00
|
|
|
import 'package:famedlysdk/src/utils/ChatTime.dart';
|
2019-07-12 09:26:07 +00:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
2019-06-11 10:21:45 +00:00
|
|
|
import 'FakeMatrixApi.dart';
|
|
|
|
|
|
|
|
void main() {
|
2019-06-18 10:06:55 +00:00
|
|
|
Client matrix;
|
|
|
|
Room room;
|
|
|
|
|
2019-06-11 10:21:45 +00:00
|
|
|
/// All Tests related to the Event
|
|
|
|
group("Room", () {
|
2019-06-18 10:06:55 +00:00
|
|
|
test('Login', () async {
|
|
|
|
matrix = Client("testclient", debug: true);
|
2019-06-11 10:21:45 +00:00
|
|
|
matrix.connection.httpClient = FakeMatrixApi();
|
|
|
|
|
2019-06-18 10:06:55 +00:00
|
|
|
final bool checkResp =
|
|
|
|
await matrix.checkServer("https://fakeServer.notExisting");
|
|
|
|
|
|
|
|
final bool loginResp = await matrix.login("test", "1234");
|
|
|
|
|
|
|
|
expect(checkResp, true);
|
|
|
|
expect(loginResp, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Create from json", () async {
|
2019-06-11 10:25:47 +00:00
|
|
|
final String id = "!localpart:server.abc";
|
2019-07-12 09:26:07 +00:00
|
|
|
final Membership membership = Membership.join;
|
2019-06-11 10:21:45 +00:00
|
|
|
final int notificationCount = 2;
|
|
|
|
final int highlightCount = 1;
|
2019-08-06 09:47:09 +00:00
|
|
|
final List<String> heroes = [
|
|
|
|
"@alice:matrix.org",
|
|
|
|
"@bob:example.com",
|
|
|
|
"@charley:example.org"
|
|
|
|
];
|
2019-06-11 10:21:45 +00:00
|
|
|
|
2019-08-06 09:47:09 +00:00
|
|
|
Map<String, dynamic> jsonObj = {
|
2019-06-11 10:21:45 +00:00
|
|
|
"id": id,
|
2019-07-12 09:26:07 +00:00
|
|
|
"membership": membership.toString().split('.').last,
|
2019-06-11 10:21:45 +00:00
|
|
|
"avatar_url": "",
|
|
|
|
"notification_count": notificationCount,
|
|
|
|
"highlight_count": highlightCount,
|
|
|
|
"prev_batch": "",
|
2019-08-06 09:47:09 +00:00
|
|
|
"joined_member_count": notificationCount,
|
|
|
|
"invited_member_count": notificationCount,
|
|
|
|
"heroes": heroes.join(","),
|
2019-06-11 10:21:45 +00:00
|
|
|
};
|
|
|
|
|
2019-06-11 10:25:47 +00:00
|
|
|
room = await Room.getRoomFromTableRow(jsonObj, matrix);
|
2019-06-11 10:21:45 +00:00
|
|
|
|
2019-06-12 06:40:43 +00:00
|
|
|
expect(room.id, id);
|
2019-06-12 10:30:22 +00:00
|
|
|
expect(room.membership, membership);
|
2019-06-12 06:40:43 +00:00
|
|
|
expect(room.notificationCount, notificationCount);
|
|
|
|
expect(room.highlightCount, highlightCount);
|
2019-08-06 09:47:09 +00:00
|
|
|
expect(room.mJoinedMemberCount, notificationCount);
|
|
|
|
expect(room.mInvitedMemberCount, notificationCount);
|
|
|
|
expect(room.mHeroes, heroes);
|
|
|
|
expect(room.displayname, "alice, bob, charley");
|
2019-08-08 09:41:42 +00:00
|
|
|
|
|
|
|
room.states["m.room.canonical_alias"] = State(
|
|
|
|
senderId: "@test:example.com",
|
|
|
|
typeKey: "m.room.canonical_alias",
|
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
|
|
|
eventId: "123",
|
|
|
|
content: {"alias": "#testalias:example.com"},
|
|
|
|
stateKey: "");
|
|
|
|
expect(room.displayname, "testalias");
|
|
|
|
expect(room.canonicalAlias, "#testalias:example.com");
|
|
|
|
|
|
|
|
room.states["m.room.name"] = State(
|
|
|
|
senderId: "@test:example.com",
|
|
|
|
typeKey: "m.room.name",
|
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
|
|
|
eventId: "123",
|
|
|
|
content: {"name": "testname"},
|
|
|
|
stateKey: "");
|
|
|
|
expect(room.displayname, "testname");
|
|
|
|
|
|
|
|
expect(room.topic, "");
|
|
|
|
room.states["m.room.topic"] = State(
|
|
|
|
senderId: "@test:example.com",
|
|
|
|
typeKey: "m.room.topic",
|
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
|
|
|
eventId: "123",
|
|
|
|
content: {"topic": "testtopic"},
|
|
|
|
stateKey: "");
|
|
|
|
expect(room.topic, "testtopic");
|
|
|
|
|
|
|
|
expect(room.avatar.mxc, "");
|
|
|
|
room.states["m.room.avatar"] = State(
|
|
|
|
senderId: "@test:example.com",
|
|
|
|
typeKey: "m.room.avatar",
|
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
|
|
|
eventId: "123",
|
|
|
|
content: {"url": "mxc://testurl"},
|
|
|
|
stateKey: "");
|
|
|
|
expect(room.avatar.mxc, "mxc://testurl");
|
|
|
|
|
|
|
|
expect(room.lastEvent, null);
|
|
|
|
room.states["m.room.message"] = State(
|
|
|
|
senderId: "@test:example.com",
|
|
|
|
typeKey: "m.room.message",
|
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
|
|
|
eventId: "12345",
|
|
|
|
time: ChatTime.now(),
|
|
|
|
content: {"msgtype": "m.text", "body": "test"},
|
|
|
|
stateKey: "");
|
|
|
|
expect(room.lastEvent.eventId, "12345");
|
|
|
|
expect(room.lastMessage, "test");
|
|
|
|
expect(room.timeCreated, room.lastEvent.time);
|
2019-06-11 10:21:45 +00:00
|
|
|
});
|
2019-06-18 10:06:55 +00:00
|
|
|
|
|
|
|
test("sendReadReceipt", () async {
|
|
|
|
final dynamic resp =
|
|
|
|
await room.sendReadReceipt("§1234:fakeServer.notExisting");
|
|
|
|
expect(resp, {});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("requestParticipants", () async {
|
|
|
|
final List<User> participants = await room.requestParticipants();
|
|
|
|
expect(participants.length, 1);
|
|
|
|
User user = participants[0];
|
|
|
|
expect(user.id, "@alice:example.org");
|
|
|
|
expect(user.displayName, "Alice Margatroid");
|
2019-07-12 09:26:07 +00:00
|
|
|
expect(user.membership, Membership.join);
|
2019-06-18 10:06:55 +00:00
|
|
|
expect(user.avatarUrl.mxc, "mxc://example.org/SEsfnsuifSDFSSEF");
|
|
|
|
expect(user.room.id, "!localpart:server.abc");
|
|
|
|
});
|
2019-06-28 08:59:00 +00:00
|
|
|
|
|
|
|
test("getEventByID", () async {
|
|
|
|
final Event event = await room.getEventById("1234");
|
2019-08-08 08:31:39 +00:00
|
|
|
expect(event.eventId, "143273582443PhrSn:example.org");
|
2019-06-28 08:59:00 +00:00
|
|
|
});
|
2019-08-08 09:41:42 +00:00
|
|
|
|
|
|
|
test("setName", () async {
|
|
|
|
final dynamic resp = await room.setName("Testname");
|
|
|
|
expect(resp["event_id"], "42");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("setDescription", () async {
|
|
|
|
final dynamic resp = await room.setDescription("Testname");
|
|
|
|
expect(resp["event_id"], "42");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("kick", () async {
|
|
|
|
final dynamic resp = await room.kick("Testname");
|
|
|
|
expect(resp, {});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("ban", () async {
|
|
|
|
final dynamic resp = await room.ban("Testname");
|
|
|
|
expect(resp, {});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("unban", () async {
|
|
|
|
final dynamic resp = await room.unban("Testname");
|
|
|
|
expect(resp, {});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("PowerLevels", () async {
|
|
|
|
room.states["m.room.power_levels"] = State(
|
|
|
|
senderId: "@test:example.com",
|
|
|
|
typeKey: "m.room.power_levels",
|
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
|
|
|
eventId: "123",
|
|
|
|
content: {
|
|
|
|
"ban": 50,
|
|
|
|
"events": {"m.room.name": 100, "m.room.power_levels": 100},
|
|
|
|
"events_default": 0,
|
|
|
|
"invite": 50,
|
|
|
|
"kick": 50,
|
|
|
|
"notifications": {"room": 20},
|
|
|
|
"redact": 50,
|
|
|
|
"state_default": 50,
|
|
|
|
"users": {"@test:fakeServer.notExisting": 100},
|
|
|
|
"users_default": 10
|
|
|
|
},
|
|
|
|
stateKey: "");
|
|
|
|
expect(room.ownPowerLevel, 100);
|
|
|
|
expect(room.getPowerLevelByUserId(matrix.userID), room.ownPowerLevel);
|
|
|
|
expect(room.getPowerLevelByUserId("@nouser:example.com"), 10);
|
|
|
|
expect(room.powerLevels,
|
|
|
|
room.states["m.room.power_levels"].content["users"]);
|
|
|
|
final dynamic resp =
|
|
|
|
await room.setPower("@test:fakeServer.notExisting", 90);
|
|
|
|
expect(resp["event_id"], "42");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("invite", () async {
|
|
|
|
final dynamic resp = await room.invite("Testname");
|
|
|
|
expect(resp, {});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("addToDirectChat", () async {
|
|
|
|
final dynamic resp = await room.addToDirectChat("Testname");
|
|
|
|
expect(resp, {});
|
|
|
|
});
|
|
|
|
|
2019-08-08 09:54:39 +00:00
|
|
|
test("getTimeline", () async {
|
|
|
|
final Timeline timeline = await room.getTimeline();
|
|
|
|
expect(timeline.events, []);
|
|
|
|
});
|
2019-08-08 09:41:42 +00:00
|
|
|
|
2019-08-08 09:54:39 +00:00
|
|
|
test("loadEvents", () async {
|
|
|
|
final List<Event> events = await room.loadEvents();
|
|
|
|
expect(events, []);
|
|
|
|
});
|
2019-08-08 09:41:42 +00:00
|
|
|
|
2019-08-08 09:54:39 +00:00
|
|
|
test("getUserByMXID", () async {
|
|
|
|
final User user = await room.getUserByMXID("@getme:example.com");
|
|
|
|
expect(user.stateKey, "@getme:example.com");
|
|
|
|
expect(user.calcDisplayname(), "You got me");
|
|
|
|
});
|
2019-06-11 10:21:45 +00:00
|
|
|
});
|
|
|
|
}
|