null safety test fixes

This commit is contained in:
Marcus Hoffmann 2021-07-01 17:36:21 +02:00
parent 34b9cc0dcf
commit 92a2bd9d7e
5 changed files with 22 additions and 10 deletions

View File

@ -1979,7 +1979,9 @@ class FakeMatrixApi extends MockClient {
{'user_id': '@testuser:example.com'},
'/client/r0/register?kind=guest': (var req) =>
{'user_id': '@testuser:example.com'},
'/client/r0/rooms/1234/upgrade': (var req) => {},
'/client/r0/rooms/1234/upgrade': (var req) => {
'replacement_room': '!1234:fakeServer.notExisting',
},
'/client/r0/user/1234/openid/request_token': (var req) => {
'access_token': 'SomeT0kenHere',
'token_type': 'Bearer',

View File

@ -23,7 +23,7 @@
class AuthenticationData {
String type;
String? /*?*/ /*?*/ session;
String? session;
AuthenticationData({required this.type, this.session});

View File

@ -52,10 +52,10 @@ class RoomEncryptedContent {
senderKey = json.tryGet('sender_key') ?? '',
deviceId = json.tryGet('device_id'),
sessionId = json.tryGet('session_id'),
ciphertextMegolm = json.tryGet('ciphertext'),
ciphertextMegolm = json.silentTryGet('ciphertext'),
// filter out invalid/incomplete CiphertextInfos
ciphertextOlm = json
.tryGet<Map<String, dynamic>>('ciphertext')
.silentTryGet<Map<String, dynamic>>('ciphertext')
?.entries
.map((e) {
try {

View File

@ -28,7 +28,18 @@ extension TryGetMapExtension on Map<String, dynamic> {
final value = this[key];
if (value != null && !(value is T)) {
Logs().w(
'Expected "${T.runtimeType}" in event content for the Key "$key" but got "${value.runtimeType}".');
'Expected "${T.runtimeType}" in event content for the Key "$key" but got "${value.runtimeType}".',
StackTrace.current);
return null;
}
return value;
}
/// Same as tryGet but without logging any warnings.
/// This is helpful if you have a field that can mean multiple things on purpose.
T? silentTryGet<T extends Object>(String key) {
final value = this[key];
if (value != null && !(value is T)) {
return null;
}
return value;
@ -38,7 +49,8 @@ extension TryGetMapExtension on Map<String, dynamic> {
final value = this[key];
if (value != null && !(value is List)) {
Logs().w(
'Expected "List<${T.runtimeType}>" in event content for the key "$key" but got "${value.runtimeType}".');
'Expected "List<${T.runtimeType}>" in event content for the key "$key" but got "${value.runtimeType}".',
StackTrace.current);
return null;
}
try {

View File

@ -1072,8 +1072,7 @@ void main() {
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
matrixApi.accessToken = '1234';
await matrixApi.deleteDevice('QBUAZIFURK',
auth: AuthenticationData.fromJson({}));
await matrixApi.deleteDevice('QBUAZIFURK');
matrixApi.homeserver = matrixApi.accessToken = null;
});
@ -1081,8 +1080,7 @@ void main() {
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
matrixApi.accessToken = '1234';
await matrixApi
.deleteDevices(['QBUAZIFURK'], auth: AuthenticationData.fromJson({}));
await matrixApi.deleteDevices(['QBUAZIFURK']);
matrixApi.homeserver = matrixApi.accessToken = null;
});