null safety test fixes
This commit is contained in:
parent
34b9cc0dcf
commit
92a2bd9d7e
|
|
@ -1979,7 +1979,9 @@ class FakeMatrixApi extends MockClient {
|
||||||
{'user_id': '@testuser:example.com'},
|
{'user_id': '@testuser:example.com'},
|
||||||
'/client/r0/register?kind=guest': (var req) =>
|
'/client/r0/register?kind=guest': (var req) =>
|
||||||
{'user_id': '@testuser:example.com'},
|
{'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) => {
|
'/client/r0/user/1234/openid/request_token': (var req) => {
|
||||||
'access_token': 'SomeT0kenHere',
|
'access_token': 'SomeT0kenHere',
|
||||||
'token_type': 'Bearer',
|
'token_type': 'Bearer',
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
class AuthenticationData {
|
class AuthenticationData {
|
||||||
String type;
|
String type;
|
||||||
String? /*?*/ /*?*/ session;
|
String? session;
|
||||||
|
|
||||||
AuthenticationData({required this.type, this.session});
|
AuthenticationData({required this.type, this.session});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,10 +52,10 @@ class RoomEncryptedContent {
|
||||||
senderKey = json.tryGet('sender_key') ?? '',
|
senderKey = json.tryGet('sender_key') ?? '',
|
||||||
deviceId = json.tryGet('device_id'),
|
deviceId = json.tryGet('device_id'),
|
||||||
sessionId = json.tryGet('session_id'),
|
sessionId = json.tryGet('session_id'),
|
||||||
ciphertextMegolm = json.tryGet('ciphertext'),
|
ciphertextMegolm = json.silentTryGet('ciphertext'),
|
||||||
// filter out invalid/incomplete CiphertextInfos
|
// filter out invalid/incomplete CiphertextInfos
|
||||||
ciphertextOlm = json
|
ciphertextOlm = json
|
||||||
.tryGet<Map<String, dynamic>>('ciphertext')
|
.silentTryGet<Map<String, dynamic>>('ciphertext')
|
||||||
?.entries
|
?.entries
|
||||||
.map((e) {
|
.map((e) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,18 @@ extension TryGetMapExtension on Map<String, dynamic> {
|
||||||
final value = this[key];
|
final value = this[key];
|
||||||
if (value != null && !(value is T)) {
|
if (value != null && !(value is T)) {
|
||||||
Logs().w(
|
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 null;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
|
@ -38,7 +49,8 @@ extension TryGetMapExtension on Map<String, dynamic> {
|
||||||
final value = this[key];
|
final value = this[key];
|
||||||
if (value != null && !(value is List)) {
|
if (value != null && !(value is List)) {
|
||||||
Logs().w(
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1072,8 +1072,7 @@ void main() {
|
||||||
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
||||||
matrixApi.accessToken = '1234';
|
matrixApi.accessToken = '1234';
|
||||||
|
|
||||||
await matrixApi.deleteDevice('QBUAZIFURK',
|
await matrixApi.deleteDevice('QBUAZIFURK');
|
||||||
auth: AuthenticationData.fromJson({}));
|
|
||||||
|
|
||||||
matrixApi.homeserver = matrixApi.accessToken = null;
|
matrixApi.homeserver = matrixApi.accessToken = null;
|
||||||
});
|
});
|
||||||
|
|
@ -1081,8 +1080,7 @@ void main() {
|
||||||
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
||||||
matrixApi.accessToken = '1234';
|
matrixApi.accessToken = '1234';
|
||||||
|
|
||||||
await matrixApi
|
await matrixApi.deleteDevices(['QBUAZIFURK']);
|
||||||
.deleteDevices(['QBUAZIFURK'], auth: AuthenticationData.fromJson({}));
|
|
||||||
|
|
||||||
matrixApi.homeserver = matrixApi.accessToken = null;
|
matrixApi.homeserver = matrixApi.accessToken = null;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue