[Tests] Fix some tests
This commit is contained in:
parent
898767875a
commit
cacf7cc530
|
|
@ -149,24 +149,25 @@ class Connection {
|
||||||
client.lazyLoadMembers = newLazyLoadMembers;
|
client.lazyLoadMembers = newLazyLoadMembers;
|
||||||
client.prevBatch = newPrevBatch;
|
client.prevBatch = newPrevBatch;
|
||||||
|
|
||||||
|
List<Room> rooms = [];
|
||||||
if (client.store != null) {
|
if (client.store != null) {
|
||||||
client.store.storeClient();
|
client.store.storeClient();
|
||||||
|
rooms = await client.store
|
||||||
List<Room> rooms = await client.store
|
|
||||||
.getRoomList(onlyLeft: false, onlyGroups: false, onlyDirect: false);
|
.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.accountData = await client.store.getAccountData();
|
||||||
client.presences = await client.store.getPresences();
|
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);
|
_userEventSub ??= onUserEvent.stream.listen(client.handleUserUpdate);
|
||||||
|
|
||||||
onLoginStateChanged.add(LoginState.logged);
|
onLoginStateChanged.add(LoginState.logged);
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,9 @@ class Room {
|
||||||
int mJoinedMemberCount;
|
int mJoinedMemberCount;
|
||||||
int mInvitedMemberCount;
|
int mInvitedMemberCount;
|
||||||
|
|
||||||
Map<String, State> states;
|
Map<String, State> states = {};
|
||||||
|
|
||||||
Map<String, RoomAccountData> roomAccountData;
|
Map<String, RoomAccountData> roomAccountData = {};
|
||||||
|
|
||||||
/// Time when the user has last read the chat.
|
/// Time when the user has last read the chat.
|
||||||
ChatTime unread;
|
ChatTime unread;
|
||||||
|
|
@ -105,7 +105,7 @@ class Room {
|
||||||
/// Must be one of [all, mention]
|
/// Must be one of [all, mention]
|
||||||
String notificationSettings;
|
String notificationSettings;
|
||||||
|
|
||||||
Event get lastEvent => states["m.room.message"] as Event;
|
Event get lastEvent => states["m.room.message"]?.timelineEvent;
|
||||||
|
|
||||||
/// Your current client instance.
|
/// Your current client instance.
|
||||||
final Client client;
|
final Client client;
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,8 @@ class RoomList {
|
||||||
mHeroes: chatUpdate.summary?.mHeroes,
|
mHeroes: chatUpdate.summary?.mHeroes,
|
||||||
mJoinedMemberCount: chatUpdate.summary?.mJoinedMemberCount,
|
mJoinedMemberCount: chatUpdate.summary?.mJoinedMemberCount,
|
||||||
mInvitedMemberCount: chatUpdate.summary?.mInvitedMemberCount,
|
mInvitedMemberCount: chatUpdate.summary?.mInvitedMemberCount,
|
||||||
|
states: {},
|
||||||
|
roomAccountData: {},
|
||||||
);
|
);
|
||||||
rooms.insert(position, newRoom);
|
rooms.insert(position, newRoom);
|
||||||
if (onInsert != null) onInsert(position);
|
if (onInsert != null) onInsert(position);
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,19 @@ class State extends RawEvent {
|
||||||
room: room);
|
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
|
/// 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.
|
/// 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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,9 @@ void main() {
|
||||||
expect(loginState, LoginState.logged);
|
expect(loginState, LoginState.logged);
|
||||||
expect(firstSync, true);
|
expect(firstSync, true);
|
||||||
expect(sync["next_batch"] == matrix.prevBatch, true);
|
expect(sync["next_batch"] == matrix.prevBatch, true);
|
||||||
|
|
||||||
|
expect(matrix.accountData.length, 1);
|
||||||
|
expect(matrix.presences.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Try to get ErrorResponse', () async {
|
test('Try to get ErrorResponse', () async {
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:famedlysdk/src/Event.dart';
|
import 'package:famedlysdk/src/RawEvent.dart';
|
||||||
import 'package:famedlysdk/src/User.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
import 'FakeMatrixApi.dart';
|
import 'FakeMatrixApi.dart';
|
||||||
|
|
@ -36,9 +35,6 @@ void main() {
|
||||||
final int timestamp = DateTime.now().millisecondsSinceEpoch;
|
final int timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||||
final String id = "!4fsdfjisjf:server.abc";
|
final String id = "!4fsdfjisjf:server.abc";
|
||||||
final String senderID = "@alice: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 type = "m.room.message";
|
||||||
final String msgtype = "m.text";
|
final String msgtype = "m.text";
|
||||||
final String body = "Hello World";
|
final String body = "Hello World";
|
||||||
|
|
@ -49,24 +45,18 @@ void main() {
|
||||||
|
|
||||||
Map<String, dynamic> jsonObj = {
|
Map<String, dynamic> jsonObj = {
|
||||||
"event_id": id,
|
"event_id": id,
|
||||||
"matrix_id": senderID,
|
"sender": senderID,
|
||||||
"displayname": senderDisplayname,
|
|
||||||
"avatar_url": empty,
|
|
||||||
"membership": membership.toString().split('.').last,
|
|
||||||
"origin_server_ts": timestamp,
|
"origin_server_ts": timestamp,
|
||||||
"state_key": empty,
|
|
||||||
"type": type,
|
"type": type,
|
||||||
"content_json": contentJson,
|
"status": 2,
|
||||||
|
"content": contentJson,
|
||||||
};
|
};
|
||||||
|
|
||||||
test("Create from json", () async {
|
test("Create from json", () async {
|
||||||
Event event = Event.fromJson(jsonObj, null);
|
Event event = Event.fromJson(jsonObj, null);
|
||||||
|
|
||||||
expect(event.id, id);
|
expect(event.eventId, id);
|
||||||
expect(event.sender.id, senderID);
|
expect(event.senderId, senderID);
|
||||||
expect(event.sender.displayName, senderDisplayname);
|
|
||||||
expect(event.sender.avatarUrl.mxc, empty);
|
|
||||||
expect(event.sender.membership, membership);
|
|
||||||
expect(event.status, 2);
|
expect(event.status, 2);
|
||||||
expect(event.text, body);
|
expect(event.text, body);
|
||||||
expect(event.formattedText, formatted_body);
|
expect(event.formattedText, formatted_body);
|
||||||
|
|
@ -121,7 +111,7 @@ void main() {
|
||||||
expect(event.type, EventTypes.HistoryVisibility);
|
expect(event.type, EventTypes.HistoryVisibility);
|
||||||
|
|
||||||
jsonObj["type"] = "m.room.message";
|
jsonObj["type"] = "m.room.message";
|
||||||
jsonObj["content"] = json.decode(jsonObj["content_json"]);
|
jsonObj["content"] = json.decode(jsonObj["content"]);
|
||||||
|
|
||||||
jsonObj["content"]["msgtype"] = "m.notice";
|
jsonObj["content"]["msgtype"] = "m.notice";
|
||||||
event = Event.fromJson(jsonObj, null);
|
event = Event.fromJson(jsonObj, null);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue