2019-06-11 09:48:31 +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 09:48:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import 'package:famedlysdk/src/Event.dart';
|
2019-07-12 09:26:07 +00:00
|
|
|
import 'package:famedlysdk/src/User.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2019-06-11 09:48:31 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
/// All Tests related to the Event
|
|
|
|
group("Event", () {
|
|
|
|
test("Create from json", () async {
|
|
|
|
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 = "";
|
2019-07-12 09:26:07 +00:00
|
|
|
final Membership membership = Membership.join;
|
2019-06-11 09:48:31 +00:00
|
|
|
final String type = "m.room.message";
|
|
|
|
final String msgtype = "m.text";
|
|
|
|
final String body = "Hello World";
|
|
|
|
final String formatted_body = "<b>Hello</b> World";
|
|
|
|
|
|
|
|
final String contentJson =
|
|
|
|
'{"msgtype":"$msgtype","body":"$body","formatted_body":"$formatted_body"}';
|
|
|
|
|
|
|
|
Map<String, dynamic> json = {
|
2019-06-27 08:13:27 +00:00
|
|
|
"event_id": id,
|
2019-06-11 09:48:31 +00:00
|
|
|
"matrix_id": senderID,
|
|
|
|
"displayname": senderDisplayname,
|
|
|
|
"avatar_url": empty,
|
2019-07-12 09:26:07 +00:00
|
|
|
"membership": membership.toString().split('.').last,
|
2019-06-11 09:48:31 +00:00
|
|
|
"origin_server_ts": timestamp,
|
|
|
|
"state_key": empty,
|
|
|
|
"type": type,
|
|
|
|
"content_json": contentJson,
|
|
|
|
};
|
|
|
|
|
|
|
|
Event event = Event.fromJson(json, 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);
|
2019-06-26 15:27:27 +00:00
|
|
|
expect(event.status, 2);
|
2019-06-11 09:48:31 +00:00
|
|
|
expect(event.text, body);
|
|
|
|
expect(event.formattedText, formatted_body);
|
2019-06-12 08:04:54 +00:00
|
|
|
expect(event.getBody(), body);
|
2019-06-11 09:48:31 +00:00
|
|
|
expect(event.type, EventTypes.Text);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|