refactor: port room test to nullsafety
This commit is contained in:
parent
2fd4425099
commit
3f83e5481c
|
|
@ -1,4 +1,3 @@
|
||||||
// @dart=2.9
|
|
||||||
/*
|
/*
|
||||||
* Famedly Matrix SDK
|
* Famedly Matrix SDK
|
||||||
* Copyright (C) 2019, 2020 Famedly GmbH
|
* Copyright (C) 2019, 2020 Famedly GmbH
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// @dart=2.9
|
|
||||||
/*
|
/*
|
||||||
* Famedly Matrix SDK
|
* Famedly Matrix SDK
|
||||||
* Copyright (C) 2021 Famedly GmbH
|
* Copyright (C) 2021 Famedly GmbH
|
||||||
|
|
@ -27,16 +26,16 @@ import 'fake_matrix_api.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('Commands', () {
|
group('Commands', () {
|
||||||
Client client;
|
late Client client;
|
||||||
Room room;
|
late Room room;
|
||||||
var olmEnabled = true;
|
var olmEnabled = true;
|
||||||
|
|
||||||
final getLastMessagePayload =
|
final getLastMessagePayload =
|
||||||
([String type = 'm.room.message', String stateKey]) {
|
([String type = 'm.room.message', String? stateKey]) {
|
||||||
final state = stateKey != null;
|
final state = stateKey != null;
|
||||||
return json.decode(FakeMatrixApi.calledEndpoints.entries
|
return json.decode(FakeMatrixApi.calledEndpoints.entries
|
||||||
.firstWhere((e) => e.key.startsWith(
|
.firstWhere((e) => e.key.startsWith(
|
||||||
'/client/r0/rooms/${Uri.encodeComponent(room.id)}/${state ? 'state' : 'send'}/${Uri.encodeComponent(type)}${state && stateKey.isNotEmpty ? '/' + Uri.encodeComponent(stateKey) : ''}'))
|
'/client/r0/rooms/${Uri.encodeComponent(room.id)}/${state ? 'state' : 'send'}/${Uri.encodeComponent(type)}${state && stateKey?.isNotEmpty == true ? '/' + Uri.encodeComponent(stateKey!) : ''}'))
|
||||||
.value
|
.value
|
||||||
.first);
|
.first);
|
||||||
};
|
};
|
||||||
|
|
@ -151,7 +150,7 @@ void main() {
|
||||||
'formatted_body': '<b>yay</b>',
|
'formatted_body': '<b>yay</b>',
|
||||||
},
|
},
|
||||||
originServerTs: DateTime.now(),
|
originServerTs: DateTime.now(),
|
||||||
senderId: client.userID,
|
senderId: client.userID!,
|
||||||
));
|
));
|
||||||
final sent = getLastMessagePayload('m.reaction');
|
final sent = getLastMessagePayload('m.reaction');
|
||||||
expect(sent, {
|
expect(sent, {
|
||||||
|
|
@ -169,7 +168,7 @@ void main() {
|
||||||
expect(
|
expect(
|
||||||
FakeMatrixApi
|
FakeMatrixApi
|
||||||
.calledEndpoints['/client/r0/join/!newroom%3Aexample.com']
|
.calledEndpoints['/client/r0/join/!newroom%3Aexample.com']
|
||||||
.first !=
|
?.first !=
|
||||||
null,
|
null,
|
||||||
true);
|
true);
|
||||||
});
|
});
|
||||||
|
|
@ -181,7 +180,7 @@ void main() {
|
||||||
FakeMatrixApi
|
FakeMatrixApi
|
||||||
.calledEndpoints[
|
.calledEndpoints[
|
||||||
'/client/r0/rooms/!1234%3AfakeServer.notExisting/leave']
|
'/client/r0/rooms/!1234%3AfakeServer.notExisting/leave']
|
||||||
.first !=
|
?.first !=
|
||||||
null,
|
null,
|
||||||
true);
|
true);
|
||||||
});
|
});
|
||||||
|
|
@ -209,7 +208,7 @@ void main() {
|
||||||
json.decode(FakeMatrixApi
|
json.decode(FakeMatrixApi
|
||||||
.calledEndpoints[
|
.calledEndpoints[
|
||||||
'/client/r0/rooms/!1234%3AfakeServer.notExisting/kick']
|
'/client/r0/rooms/!1234%3AfakeServer.notExisting/kick']
|
||||||
.first),
|
?.first),
|
||||||
{
|
{
|
||||||
'user_id': '@baduser:example.org',
|
'user_id': '@baduser:example.org',
|
||||||
});
|
});
|
||||||
|
|
@ -222,7 +221,7 @@ void main() {
|
||||||
json.decode(FakeMatrixApi
|
json.decode(FakeMatrixApi
|
||||||
.calledEndpoints[
|
.calledEndpoints[
|
||||||
'/client/r0/rooms/!1234%3AfakeServer.notExisting/ban']
|
'/client/r0/rooms/!1234%3AfakeServer.notExisting/ban']
|
||||||
.first),
|
?.first),
|
||||||
{
|
{
|
||||||
'user_id': '@baduser:example.org',
|
'user_id': '@baduser:example.org',
|
||||||
});
|
});
|
||||||
|
|
@ -235,7 +234,7 @@ void main() {
|
||||||
json.decode(FakeMatrixApi
|
json.decode(FakeMatrixApi
|
||||||
.calledEndpoints[
|
.calledEndpoints[
|
||||||
'/client/r0/rooms/!1234%3AfakeServer.notExisting/unban']
|
'/client/r0/rooms/!1234%3AfakeServer.notExisting/unban']
|
||||||
.first),
|
?.first),
|
||||||
{
|
{
|
||||||
'user_id': '@baduser:example.org',
|
'user_id': '@baduser:example.org',
|
||||||
});
|
});
|
||||||
|
|
@ -248,7 +247,7 @@ void main() {
|
||||||
json.decode(FakeMatrixApi
|
json.decode(FakeMatrixApi
|
||||||
.calledEndpoints[
|
.calledEndpoints[
|
||||||
'/client/r0/rooms/!1234%3AfakeServer.notExisting/invite']
|
'/client/r0/rooms/!1234%3AfakeServer.notExisting/invite']
|
||||||
.first),
|
?.first),
|
||||||
{
|
{
|
||||||
'user_id': '@baduser:example.org',
|
'user_id': '@baduser:example.org',
|
||||||
});
|
});
|
||||||
|
|
@ -276,14 +275,14 @@ void main() {
|
||||||
|
|
||||||
test('discardsession', () async {
|
test('discardsession', () async {
|
||||||
if (olmEnabled) {
|
if (olmEnabled) {
|
||||||
await client.encryption.keyManager.createOutboundGroupSession(room.id);
|
await client.encryption?.keyManager.createOutboundGroupSession(room.id);
|
||||||
expect(
|
expect(
|
||||||
client.encryption.keyManager.getOutboundGroupSession(room.id) !=
|
client.encryption?.keyManager.getOutboundGroupSession(room.id) !=
|
||||||
null,
|
null,
|
||||||
true);
|
true);
|
||||||
await room.sendTextEvent('/discardsession');
|
await room.sendTextEvent('/discardsession');
|
||||||
expect(
|
expect(
|
||||||
client.encryption.keyManager.getOutboundGroupSession(room.id) !=
|
client.encryption?.keyManager.getOutboundGroupSession(room.id) !=
|
||||||
null,
|
null,
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// @dart=2.9
|
|
||||||
/*
|
/*
|
||||||
* Famedly Matrix SDK
|
* Famedly Matrix SDK
|
||||||
* Copyright (C) 2019, 2020 Famedly GmbH
|
* Copyright (C) 2019, 2020 Famedly GmbH
|
||||||
|
|
@ -49,8 +48,8 @@ Future<bool> olmEnabled() async {
|
||||||
void testDatabase(
|
void testDatabase(
|
||||||
Future<DatabaseApi> futureDatabase,
|
Future<DatabaseApi> futureDatabase,
|
||||||
) {
|
) {
|
||||||
DatabaseApi database;
|
late DatabaseApi database;
|
||||||
int toDeviceQueueIndex;
|
late int toDeviceQueueIndex;
|
||||||
test('Open', () async {
|
test('Open', () async {
|
||||||
database = await futureDatabase;
|
database = await futureDatabase;
|
||||||
});
|
});
|
||||||
|
|
@ -151,7 +150,7 @@ void testDatabase(
|
||||||
);
|
);
|
||||||
|
|
||||||
final client = await database.getClient('name');
|
final client = await database.getClient('name');
|
||||||
expect(client['token'], 'token');
|
expect(client?['token'], 'token');
|
||||||
});
|
});
|
||||||
test('updateClient', () async {
|
test('updateClient', () async {
|
||||||
await database.updateClient(
|
await database.updateClient(
|
||||||
|
|
@ -164,21 +163,21 @@ void testDatabase(
|
||||||
'olmAccount',
|
'olmAccount',
|
||||||
);
|
);
|
||||||
final client = await database.getClient('name');
|
final client = await database.getClient('name');
|
||||||
expect(client['token'], 'token_different');
|
expect(client?['token'], 'token_different');
|
||||||
});
|
});
|
||||||
test('updateClientKeys', () async {
|
test('updateClientKeys', () async {
|
||||||
await database.updateClientKeys(
|
await database.updateClientKeys(
|
||||||
'olmAccount2',
|
'olmAccount2',
|
||||||
);
|
);
|
||||||
final client = await database.getClient('name');
|
final client = await database.getClient('name');
|
||||||
expect(client['olm_account'], 'olmAccount2');
|
expect(client?['olm_account'], 'olmAccount2');
|
||||||
});
|
});
|
||||||
test('storeSyncFilterId', () async {
|
test('storeSyncFilterId', () async {
|
||||||
await database.storeSyncFilterId(
|
await database.storeSyncFilterId(
|
||||||
'1234',
|
'1234',
|
||||||
);
|
);
|
||||||
final client = await database.getClient('name');
|
final client = await database.getClient('name');
|
||||||
expect(client['sync_filter_id'], '1234');
|
expect(client?['sync_filter_id'], '1234');
|
||||||
});
|
});
|
||||||
test('getAccountData', () async {
|
test('getAccountData', () async {
|
||||||
await database.getAccountData();
|
await database.getAccountData();
|
||||||
|
|
@ -218,28 +217,29 @@ void testDatabase(
|
||||||
Client('testclient'));
|
Client('testclient'));
|
||||||
});
|
});
|
||||||
test('getEventById', () async {
|
test('getEventById', () async {
|
||||||
final event = await database.getEventById(
|
final event = await database.getEventById('\$event:example.com',
|
||||||
'\$event:example.com', Room(id: '!testroom:example.com'));
|
Room(id: '!testroom:example.com', client: Client('testclient')));
|
||||||
expect(event.type, EventTypes.Message);
|
expect(event?.type, EventTypes.Message);
|
||||||
});
|
});
|
||||||
test('getEventList', () async {
|
test('getEventList', () async {
|
||||||
final events =
|
final events = await database.getEventList(
|
||||||
await database.getEventList(Room(id: '!testroom:example.com'));
|
Room(id: '!testroom:example.com', client: Client('testclient')));
|
||||||
expect(events.single.type, EventTypes.Message);
|
expect(events.single.type, EventTypes.Message);
|
||||||
});
|
});
|
||||||
test('getUser', () async {
|
test('getUser', () async {
|
||||||
final user = await database.getUser(
|
final user = await database.getUser('@bob:example.org',
|
||||||
'@bob:example.org', Room(id: '!testroom:example.com'));
|
Room(id: '!testroom:example.com', client: Client('testclient')));
|
||||||
expect(user, null);
|
expect(user, null);
|
||||||
});
|
});
|
||||||
test('getUsers', () async {
|
test('getUsers', () async {
|
||||||
final users = await database.getUsers(Room(id: '!testroom:example.com'));
|
final users = await database.getUsers(
|
||||||
|
Room(id: '!testroom:example.com', client: Client('testclient')));
|
||||||
expect(users.isEmpty, true);
|
expect(users.isEmpty, true);
|
||||||
});
|
});
|
||||||
test('removeEvent', () async {
|
test('removeEvent', () async {
|
||||||
await database.removeEvent('\$event:example.com', '!testroom:example.com');
|
await database.removeEvent('\$event:example.com', '!testroom:example.com');
|
||||||
final event = await database.getEventById(
|
final event = await database.getEventById('\$event:example.com',
|
||||||
'\$event:example.com', Room(id: '!testroom:example.com'));
|
Room(id: '!testroom:example.com', client: Client('testclient')));
|
||||||
expect(event, null);
|
expect(event, null);
|
||||||
});
|
});
|
||||||
test('getAllInboundGroupSessions', () async {
|
test('getAllInboundGroupSessions', () async {
|
||||||
|
|
@ -267,7 +267,7 @@ void testDatabase(
|
||||||
'!testroom:example.com',
|
'!testroom:example.com',
|
||||||
'sessionId',
|
'sessionId',
|
||||||
);
|
);
|
||||||
expect(jsonDecode(session.content)['foo'], 'bar');
|
expect(jsonDecode(session!.content)['foo'], 'bar');
|
||||||
});
|
});
|
||||||
test('markInboundGroupSessionAsUploaded', () async {
|
test('markInboundGroupSessionAsUploaded', () async {
|
||||||
await database.markInboundGroupSessionAsUploaded(
|
await database.markInboundGroupSessionAsUploaded(
|
||||||
|
|
@ -296,7 +296,7 @@ void testDatabase(
|
||||||
});
|
});
|
||||||
test('storeSSSSCache', () async {
|
test('storeSSSSCache', () async {
|
||||||
await database.storeSSSSCache('type', 'keyId', 'ciphertext', '{}');
|
await database.storeSSSSCache('type', 'keyId', 'ciphertext', '{}');
|
||||||
final cache = await database.getSSSSCache('type');
|
final cache = (await database.getSSSSCache('type'))!;
|
||||||
expect(cache.type, 'type');
|
expect(cache.type, 'type');
|
||||||
expect(cache.keyId, 'keyId');
|
expect(cache.keyId, 'keyId');
|
||||||
expect(cache.ciphertext, 'ciphertext');
|
expect(cache.ciphertext, 'ciphertext');
|
||||||
|
|
@ -349,7 +349,7 @@ void testDatabase(
|
||||||
'!testroom:example.com',
|
'!testroom:example.com',
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
);
|
);
|
||||||
expect(session.devices.isEmpty, true);
|
expect(session?.devices.isEmpty, true);
|
||||||
});
|
});
|
||||||
test('getLastSentMessageUserDeviceKey', () async {
|
test('getLastSentMessageUserDeviceKey', () async {
|
||||||
final list = await database.getLastSentMessageUserDeviceKey(
|
final list = await database.getLastSentMessageUserDeviceKey(
|
||||||
|
|
@ -361,7 +361,7 @@ void testDatabase(
|
||||||
test('getUnimportantRoomEventStatesForRoom', () async {
|
test('getUnimportantRoomEventStatesForRoom', () async {
|
||||||
final events = await database.getUnimportantRoomEventStatesForRoom(
|
final events = await database.getUnimportantRoomEventStatesForRoom(
|
||||||
['events'],
|
['events'],
|
||||||
Room(id: '!mep'),
|
Room(id: '!mep', client: Client('testclient')),
|
||||||
);
|
);
|
||||||
expect(events.isEmpty, true);
|
expect(events.isEmpty, true);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2124,35 +2124,35 @@ class FakeMatrixApi extends MockClient {
|
||||||
'/client/r0/pushrules/global/content/nocake/enabled': (var req) => {},
|
'/client/r0/pushrules/global/content/nocake/enabled': (var req) => {},
|
||||||
'/client/r0/pushrules/global/content/nocake/actions': (var req) => {},
|
'/client/r0/pushrules/global/content/nocake/actions': (var req) => {},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.history_visibility':
|
'/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.history_visibility':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.join_rules':
|
'/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.join_rules':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.guest_access':
|
'/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.guest_access':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.invite/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.invite/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.answer/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.answer/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.select_answer/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.select_answer/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.reject/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.reject/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.negotiate/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.negotiate/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.candidates/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.candidates/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.hangup/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.hangup/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.replaces/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.replaces/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.asserted_identity/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.asserted_identity/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.sdp_stream_metadata_changed/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.sdp_stream_metadata_changed/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/org.matrix.call.sdp_stream_metadata_changed/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/org.matrix.call.sdp_stream_metadata_changed/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!localpart%3Aserver.abc/send/org.matrix.call.asserted_identity/1234':
|
'/client/r0/rooms/!localpart%3Aserver.abc/send/org.matrix.call.asserted_identity/1234':
|
||||||
(var req) => {},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/rooms/!1234%3Aexample.com/redact/1143273582443PhrSn%3Aexample.org/1234':
|
'/client/r0/rooms/!1234%3Aexample.com/redact/1143273582443PhrSn%3Aexample.org/1234':
|
||||||
(var req) => {'event_id': '1234'},
|
(var req) => {'event_id': '1234'},
|
||||||
'/client/r0/pushrules/global/room/!localpart%3Aserver.abc': (var req) =>
|
'/client/r0/pushrules/global/room/!localpart%3Aserver.abc': (var req) =>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// @dart=2.9
|
|
||||||
/*
|
/*
|
||||||
* Famedly Matrix SDK
|
* Famedly Matrix SDK
|
||||||
* Copyright (C) 2021 Famedly GmbH
|
* Copyright (C) 2021 Famedly GmbH
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// @dart=2.9
|
|
||||||
/*
|
/*
|
||||||
* Famedly Matrix SDK
|
* Famedly Matrix SDK
|
||||||
* Copyright (C) 2020 Famedly GmbH
|
* Copyright (C) 2020 Famedly GmbH
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// @dart=2.9
|
|
||||||
/*
|
/*
|
||||||
* Famedly Matrix SDK
|
* Famedly Matrix SDK
|
||||||
* Copyright (C) 2020 Famedly GmbH
|
* Copyright (C) 2020 Famedly GmbH
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// @dart=2.9
|
|
||||||
/*
|
/*
|
||||||
* Famedly Matrix SDK
|
* Famedly Matrix SDK
|
||||||
* Copyright (C) 2019, 2020 Famedly GmbH
|
* Copyright (C) 2019, 2020 Famedly GmbH
|
||||||
|
|
@ -34,11 +33,11 @@ void main() {
|
||||||
);
|
);
|
||||||
expect(matrixException.errcode, 'M_FORBIDDEN');
|
expect(matrixException.errcode, 'M_FORBIDDEN');
|
||||||
final flows = matrixException.authenticationFlows;
|
final flows = matrixException.authenticationFlows;
|
||||||
expect(flows.length, 1);
|
expect(flows?.length, 1);
|
||||||
expect(flows.first.stages.length, 1);
|
expect(flows?.first.stages.length, 1);
|
||||||
expect(flows.first.stages.first, 'example.type.foo');
|
expect(flows?.first.stages.first, 'example.type.foo');
|
||||||
expect(
|
expect(
|
||||||
matrixException.authenticationParams['example.type.baz'],
|
matrixException.authenticationParams?['example.type.baz'],
|
||||||
{'example_key': 'foobar'},
|
{'example_key': 'foobar'},
|
||||||
);
|
);
|
||||||
expect(matrixException.completedAuthenticationFlows.length, 1);
|
expect(matrixException.completedAuthenticationFlows.length, 1);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// @dart=2.9
|
|
||||||
/*
|
/*
|
||||||
* Famedly Matrix SDK
|
* Famedly Matrix SDK
|
||||||
* Copyright (C) 2019, 2020 Famedly GmbH
|
* Copyright (C) 2019, 2020 Famedly GmbH
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// @dart=2.9
|
|
||||||
/*
|
/*
|
||||||
* Famedly Matrix SDK
|
* Famedly Matrix SDK
|
||||||
* Copyright (C) 2019, 2020 Famedly GmbH
|
* Copyright (C) 2019, 2020 Famedly GmbH
|
||||||
|
|
@ -33,8 +32,8 @@ import 'fake_client.dart';
|
||||||
import 'fake_matrix_api.dart';
|
import 'fake_matrix_api.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
Client matrix;
|
late Client matrix;
|
||||||
Room room;
|
late Room room;
|
||||||
|
|
||||||
/// All Tests related to the Event
|
/// All Tests related to the Event
|
||||||
group('Room', () {
|
group('Room', () {
|
||||||
|
|
@ -96,8 +95,9 @@ void main() {
|
||||||
expect(room.summary.mInvitedMemberCount, notificationCount);
|
expect(room.summary.mInvitedMemberCount, notificationCount);
|
||||||
expect(room.summary.mHeroes, heroes);
|
expect(room.summary.mHeroes, heroes);
|
||||||
expect(room.displayname, 'Alice, Bob, Charley');
|
expect(room.displayname, 'Alice, Bob, Charley');
|
||||||
expect(room.getState('m.room.join_rules').content['join_rule'], 'public');
|
expect(
|
||||||
expect(room.roomAccountData['com.test.foo'].content['foo'], 'bar');
|
room.getState('m.room.join_rules')?.content['join_rule'], 'public');
|
||||||
|
expect(room.roomAccountData['com.test.foo']?.content['foo'], 'bar');
|
||||||
|
|
||||||
room.setState(
|
room.setState(
|
||||||
Event(
|
Event(
|
||||||
|
|
@ -181,9 +181,9 @@ void main() {
|
||||||
stateKey: '',
|
stateKey: '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(room.lastEvent.eventId, '12345');
|
expect(room.lastEvent?.eventId, '12345');
|
||||||
expect(room.lastEvent.body, 'abc');
|
expect(room.lastEvent?.body, 'abc');
|
||||||
expect(room.timeCreated, room.lastEvent.originServerTs);
|
expect(room.timeCreated, room.lastEvent?.originServerTs);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('lastEvent is set properly', () {
|
test('lastEvent is set properly', () {
|
||||||
|
|
@ -199,7 +199,7 @@ void main() {
|
||||||
stateKey: '',
|
stateKey: '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(room.lastEvent.body, 'cd');
|
expect(room.lastEvent?.body, 'cd');
|
||||||
room.setState(
|
room.setState(
|
||||||
Event(
|
Event(
|
||||||
senderId: '@test:example.com',
|
senderId: '@test:example.com',
|
||||||
|
|
@ -212,7 +212,7 @@ void main() {
|
||||||
stateKey: '',
|
stateKey: '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(room.lastEvent.body, 'cdc');
|
expect(room.lastEvent?.body, 'cdc');
|
||||||
room.setState(
|
room.setState(
|
||||||
Event(
|
Event(
|
||||||
senderId: '@test:example.com',
|
senderId: '@test:example.com',
|
||||||
|
|
@ -230,7 +230,7 @@ void main() {
|
||||||
stateKey: '',
|
stateKey: '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(room.lastEvent.body, 'cdc'); // because we edited the "cd" message
|
expect(room.lastEvent?.body, 'cdc'); // because we edited the "cd" message
|
||||||
room.setState(
|
room.setState(
|
||||||
Event(
|
Event(
|
||||||
senderId: '@test:example.com',
|
senderId: '@test:example.com',
|
||||||
|
|
@ -248,7 +248,7 @@ void main() {
|
||||||
stateKey: '',
|
stateKey: '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(room.lastEvent.body, 'edited cdc');
|
expect(room.lastEvent?.body, 'edited cdc');
|
||||||
});
|
});
|
||||||
test('lastEvent when reply parent edited', () async {
|
test('lastEvent when reply parent edited', () async {
|
||||||
room.setState(
|
room.setState(
|
||||||
|
|
@ -263,7 +263,7 @@ void main() {
|
||||||
stateKey: '',
|
stateKey: '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(room.lastEvent.body, 'A');
|
expect(room.lastEvent?.body, 'A');
|
||||||
|
|
||||||
room.setState(
|
room.setState(
|
||||||
Event(
|
Event(
|
||||||
|
|
@ -281,7 +281,7 @@ void main() {
|
||||||
stateKey: '',
|
stateKey: '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(room.lastEvent.body, 'B');
|
expect(room.lastEvent?.body, 'B');
|
||||||
room.setState(
|
room.setState(
|
||||||
Event(
|
Event(
|
||||||
senderId: '@test:example.com',
|
senderId: '@test:example.com',
|
||||||
|
|
@ -299,7 +299,7 @@ void main() {
|
||||||
stateKey: '',
|
stateKey: '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(room.lastEvent.body, 'B');
|
expect(room.lastEvent?.body, 'B');
|
||||||
});
|
});
|
||||||
test('sendReadMarker', () async {
|
test('sendReadMarker', () async {
|
||||||
await room.setReadMarker('§1234:fakeServer.notExisting');
|
await room.setReadMarker('§1234:fakeServer.notExisting');
|
||||||
|
|
@ -313,12 +313,12 @@ void main() {
|
||||||
expect(user.displayName, 'Alice Margatroid');
|
expect(user.displayName, 'Alice Margatroid');
|
||||||
expect(user.membership, Membership.join);
|
expect(user.membership, Membership.join);
|
||||||
expect(user.avatarUrl.toString(), 'mxc://example.org/SEsfnsuifSDFSSEF');
|
expect(user.avatarUrl.toString(), 'mxc://example.org/SEsfnsuifSDFSSEF');
|
||||||
expect(user.room.id, '!localpart:server.abc');
|
expect(user.room?.id, '!localpart:server.abc');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getEventByID', () async {
|
test('getEventByID', () async {
|
||||||
final event = await room.getEventById('1234');
|
final event = await room.getEventById('1234');
|
||||||
expect(event.eventId, '143273582443PhrSn:example.org');
|
expect(event?.eventId, '143273582443PhrSn:example.org');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('setName', () async {
|
test('setName', () async {
|
||||||
|
|
@ -367,7 +367,7 @@ void main() {
|
||||||
stateKey: ''),
|
stateKey: ''),
|
||||||
);
|
);
|
||||||
expect(room.ownPowerLevel, 100);
|
expect(room.ownPowerLevel, 100);
|
||||||
expect(room.getPowerLevelByUserId(matrix.userID), room.ownPowerLevel);
|
expect(room.getPowerLevelByUserId(matrix.userID!), room.ownPowerLevel);
|
||||||
expect(room.getPowerLevelByUserId('@nouser:example.com'), 10);
|
expect(room.getPowerLevelByUserId('@nouser:example.com'), 10);
|
||||||
expect(room.ownPowerLevel, 100);
|
expect(room.ownPowerLevel, 100);
|
||||||
expect(room.canBan, true);
|
expect(room.canBan, true);
|
||||||
|
|
@ -381,7 +381,7 @@ void main() {
|
||||||
expect(room.canSendEvent('m.room.power_levels'), true);
|
expect(room.canSendEvent('m.room.power_levels'), true);
|
||||||
expect(room.canSendEvent('m.room.member'), true);
|
expect(room.canSendEvent('m.room.member'), true);
|
||||||
expect(room.powerLevels,
|
expect(room.powerLevels,
|
||||||
room.getState('m.room.power_levels').content['users']);
|
room.getState('m.room.power_levels')?.content['users']);
|
||||||
|
|
||||||
room.setState(
|
room.setState(
|
||||||
Event(
|
Event(
|
||||||
|
|
@ -454,12 +454,12 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getUserByMXID', () async {
|
test('getUserByMXID', () async {
|
||||||
User user;
|
User? user;
|
||||||
try {
|
try {
|
||||||
user = await room.requestUser('@getme:example.com');
|
user = await room.requestUser('@getme:example.com');
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
expect(user.stateKey, '@getme:example.com');
|
expect(user?.stateKey, '@getme:example.com');
|
||||||
expect(user.calcDisplayname(), 'Getme');
|
expect(user?.calcDisplayname(), 'Getme');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('setAvatar', () async {
|
test('setAvatar', () async {
|
||||||
|
|
@ -472,14 +472,14 @@ void main() {
|
||||||
final dynamic resp = await room.sendEvent(
|
final dynamic resp = await room.sendEvent(
|
||||||
{'msgtype': 'm.text', 'body': 'hello world'},
|
{'msgtype': 'm.text', 'body': 'hello world'},
|
||||||
txid: 'testtxid');
|
txid: 'testtxid');
|
||||||
expect(resp.startsWith('\$event'), true);
|
expect(resp?.startsWith('\$event'), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sendEvent', () async {
|
test('sendEvent', () async {
|
||||||
FakeMatrixApi.calledEndpoints.clear();
|
FakeMatrixApi.calledEndpoints.clear();
|
||||||
final dynamic resp =
|
final dynamic resp =
|
||||||
await room.sendTextEvent('Hello world', txid: 'testtxid');
|
await room.sendTextEvent('Hello world', txid: 'testtxid');
|
||||||
expect(resp.startsWith('\$event'), true);
|
expect(resp?.startsWith('\$event'), true);
|
||||||
final entry = FakeMatrixApi.calledEndpoints.entries
|
final entry = FakeMatrixApi.calledEndpoints.entries
|
||||||
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
||||||
final content = json.decode(entry.value.first);
|
final content = json.decode(entry.value.first);
|
||||||
|
|
@ -493,7 +493,7 @@ void main() {
|
||||||
FakeMatrixApi.calledEndpoints.clear();
|
FakeMatrixApi.calledEndpoints.clear();
|
||||||
final dynamic resp = await room.sendTextEvent('Hello world',
|
final dynamic resp = await room.sendTextEvent('Hello world',
|
||||||
txid: 'testtxid', editEventId: '\$otherEvent');
|
txid: 'testtxid', editEventId: '\$otherEvent');
|
||||||
expect(resp.startsWith('\$event'), true);
|
expect(resp?.startsWith('\$event'), true);
|
||||||
final entry = FakeMatrixApi.calledEndpoints.entries
|
final entry = FakeMatrixApi.calledEndpoints.entries
|
||||||
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
||||||
final content = json.decode(entry.value.first);
|
final content = json.decode(entry.value.first);
|
||||||
|
|
@ -524,7 +524,7 @@ void main() {
|
||||||
FakeMatrixApi.calledEndpoints.clear();
|
FakeMatrixApi.calledEndpoints.clear();
|
||||||
var resp = await room.sendTextEvent('Hello world',
|
var resp = await room.sendTextEvent('Hello world',
|
||||||
txid: 'testtxid', inReplyTo: event);
|
txid: 'testtxid', inReplyTo: event);
|
||||||
expect(resp.startsWith('\$event'), true);
|
expect(resp?.startsWith('\$event'), true);
|
||||||
var entry = FakeMatrixApi.calledEndpoints.entries
|
var entry = FakeMatrixApi.calledEndpoints.entries
|
||||||
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
||||||
var content = json.decode(entry.value.first);
|
var content = json.decode(entry.value.first);
|
||||||
|
|
@ -553,7 +553,7 @@ void main() {
|
||||||
FakeMatrixApi.calledEndpoints.clear();
|
FakeMatrixApi.calledEndpoints.clear();
|
||||||
resp = await room.sendTextEvent('Hello world\nfox',
|
resp = await room.sendTextEvent('Hello world\nfox',
|
||||||
txid: 'testtxid', inReplyTo: event);
|
txid: 'testtxid', inReplyTo: event);
|
||||||
expect(resp.startsWith('\$event'), true);
|
expect(resp?.startsWith('\$event'), true);
|
||||||
entry = FakeMatrixApi.calledEndpoints.entries
|
entry = FakeMatrixApi.calledEndpoints.entries
|
||||||
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
||||||
content = json.decode(entry.value.first);
|
content = json.decode(entry.value.first);
|
||||||
|
|
@ -585,7 +585,7 @@ void main() {
|
||||||
FakeMatrixApi.calledEndpoints.clear();
|
FakeMatrixApi.calledEndpoints.clear();
|
||||||
resp = await room.sendTextEvent('Hello world',
|
resp = await room.sendTextEvent('Hello world',
|
||||||
txid: 'testtxid', inReplyTo: event);
|
txid: 'testtxid', inReplyTo: event);
|
||||||
expect(resp.startsWith('\$event'), true);
|
expect(resp?.startsWith('\$event'), true);
|
||||||
entry = FakeMatrixApi.calledEndpoints.entries
|
entry = FakeMatrixApi.calledEndpoints.entries
|
||||||
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
||||||
content = json.decode(entry.value.first);
|
content = json.decode(entry.value.first);
|
||||||
|
|
@ -614,7 +614,7 @@ void main() {
|
||||||
FakeMatrixApi.calledEndpoints.clear();
|
FakeMatrixApi.calledEndpoints.clear();
|
||||||
resp = await room.sendTextEvent('Hello world',
|
resp = await room.sendTextEvent('Hello world',
|
||||||
txid: 'testtxid', inReplyTo: event);
|
txid: 'testtxid', inReplyTo: event);
|
||||||
expect(resp.startsWith('\$event'), true);
|
expect(resp?.startsWith('\$event'), true);
|
||||||
entry = FakeMatrixApi.calledEndpoints.entries
|
entry = FakeMatrixApi.calledEndpoints.entries
|
||||||
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
||||||
content = json.decode(entry.value.first);
|
content = json.decode(entry.value.first);
|
||||||
|
|
@ -636,7 +636,7 @@ void main() {
|
||||||
FakeMatrixApi.calledEndpoints.clear();
|
FakeMatrixApi.calledEndpoints.clear();
|
||||||
final dynamic resp =
|
final dynamic resp =
|
||||||
await room.sendReaction('\$otherEvent', '🦊', txid: 'testtxid');
|
await room.sendReaction('\$otherEvent', '🦊', txid: 'testtxid');
|
||||||
expect(resp.startsWith('\$event'), true);
|
expect(resp?.startsWith('\$event'), true);
|
||||||
final entry = FakeMatrixApi.calledEndpoints.entries
|
final entry = FakeMatrixApi.calledEndpoints.entries
|
||||||
.firstWhere((p) => p.key.contains('/send/m.reaction/'));
|
.firstWhere((p) => p.key.contains('/send/m.reaction/'));
|
||||||
final content = json.decode(entry.value.first);
|
final content = json.decode(entry.value.first);
|
||||||
|
|
@ -656,7 +656,7 @@ void main() {
|
||||||
final geoUri = 'geo:0.0,0.0';
|
final geoUri = 'geo:0.0,0.0';
|
||||||
final dynamic resp =
|
final dynamic resp =
|
||||||
await room.sendLocation(body, geoUri, txid: 'testtxid');
|
await room.sendLocation(body, geoUri, txid: 'testtxid');
|
||||||
expect(resp.startsWith('\$event'), true);
|
expect(resp?.startsWith('\$event'), true);
|
||||||
|
|
||||||
final entry = FakeMatrixApi.calledEndpoints.entries
|
final entry = FakeMatrixApi.calledEndpoints.entries
|
||||||
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
|
||||||
|
|
@ -684,8 +684,8 @@ void main() {
|
||||||
|
|
||||||
test('pushRuleState', () async {
|
test('pushRuleState', () async {
|
||||||
expect(room.pushRuleState, PushRuleState.mentionsOnly);
|
expect(room.pushRuleState, PushRuleState.mentionsOnly);
|
||||||
matrix.accountData['m.push_rules'].content['global']['override']
|
matrix.accountData['m.push_rules']?.content['global']['override'].add(
|
||||||
.add(matrix.accountData['m.push_rules'].content['global']['room'][0]);
|
matrix.accountData['m.push_rules']?.content['global']['room'][0]);
|
||||||
expect(room.pushRuleState, PushRuleState.dontNotify);
|
expect(room.pushRuleState, PushRuleState.dontNotify);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -756,7 +756,7 @@ void main() {
|
||||||
'type': 'm.tag'
|
'type': 'm.tag'
|
||||||
});
|
});
|
||||||
expect(room.tags.length, 1);
|
expect(room.tags.length, 1);
|
||||||
expect(room.tags[TagType.favourite].order, 0.1);
|
expect(room.tags[TagType.favourite]?.order, 0.1);
|
||||||
expect(room.isFavourite, true);
|
expect(room.isFavourite, true);
|
||||||
await room.setFavourite(false);
|
await room.setFavourite(false);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue