chore: disable dynamic calls

This commit is contained in:
Nicolas Werner 2022-08-20 11:28:43 +02:00
parent 57ec5014d9
commit 7471743be3
8 changed files with 194 additions and 177 deletions

View File

@ -7,6 +7,7 @@ linter:
constant_identifier_names: false constant_identifier_names: false
prefer_final_locals: true prefer_final_locals: true
prefer_final_in_for_each: true prefer_final_in_for_each: true
avoid_dynamic_calls: true
analyzer: analyzer:
errors: errors:

View File

@ -33,12 +33,14 @@ Map<String, dynamic> decodeJson(dynamic data) {
if (data is String) { if (data is String) {
return json.decode(data); return json.decode(data);
} }
if (data.isEmpty) { if (data is Map && data.isEmpty) {
return <String, dynamic>{}; return <String, dynamic>{};
} }
return data; return data;
} }
T? tryCast<T>(dynamic object) => object is T ? object : null;
/// A mock http client for testing purposes. /// A mock http client for testing purposes.
class FakeMatrixApi extends MockClient { class FakeMatrixApi extends MockClient {
static final calledEndpoints = <String, List<dynamic>>{}; static final calledEndpoints = <String, List<dynamic>>{};
@ -83,7 +85,7 @@ class FakeMatrixApi extends MockClient {
} }
calledEndpoints[action]!.add(data); calledEndpoints[action]!.add(data);
if (api.containsKey(method) && api[method]!.containsKey(action)) { if (api.containsKey(method) && api[method]!.containsKey(action)) {
res = api[method]![action](data); res = api[method]![action]?.call(data);
if (res is Map && res.containsKey('errcode')) { if (res is Map && res.containsKey('errcode')) {
statusCode = 405; statusCode = 405;
} }
@ -953,7 +955,7 @@ class FakeMatrixApi extends MockClient {
] ]
}; };
static final Map<String, Map<String, dynamic>> api = { static final Map<String, Map<String, dynamic Function(dynamic)>> api = {
'GET': { 'GET': {
'/path/to/auth/error': (var req) => { '/path/to/auth/error': (var req) => {
'errcode': 'M_FORBIDDEN', 'errcode': 'M_FORBIDDEN',
@ -1942,42 +1944,45 @@ class FakeMatrixApi extends MockClient {
'prev_batch': 'p1902', 'prev_batch': 'p1902',
'total_room_count_estimate': 115 'total_room_count_estimate': 115
}, },
'/client/v3/keys/claim': (var req) => { '/client/v3/keys/claim': (dynamic req) {
'failures': {}, final request = decodeJson(req)["one_time_keys"];
'one_time_keys': { final keys = (request is Map<String, dynamic>)
if (decodeJson(req)['one_time_keys']['@alice:example.com'] != ? request["one_time_keys"] as Map<String, dynamic>?
null) : null;
'@alice:example.com': { return {
'JLAFKJWSCS': { 'failures': {},
'signed_curve25519:AAAAAQ': { 'one_time_keys': {
'key': 'ikMXajRlkS7Xi9CROrAh3jXnbygk8mLBdSaY9/al0X0', if (keys?['@alice:example.com'] != null)
'signatures': { '@alice:example.com': {
'@alice:example.com': { 'JLAFKJWSCS': {
'ed25519:JLAFKJWSCS': 'signed_curve25519:AAAAAQ': {
'XdboCa0Ljoh0Y0i/IVnmMqy/+T1hJyu8BA/nRYniJMQ7QWh/pGS5AsWswdARD+MAX+r4u98Qzk0y27HUddZXDA' 'key': 'ikMXajRlkS7Xi9CROrAh3jXnbygk8mLBdSaY9/al0X0',
} 'signatures': {
'@alice:example.com': {
'ed25519:JLAFKJWSCS':
'XdboCa0Ljoh0Y0i/IVnmMqy/+T1hJyu8BA/nRYniJMQ7QWh/pGS5AsWswdARD+MAX+r4u98Qzk0y27HUddZXDA'
} }
} }
} }
}, }
if (decodeJson(req)['one_time_keys'] },
['@test:fakeServer.notExisting'] != if (keys?['@test:fakeServer.notExisting'] != null)
null) '@test:fakeServer.notExisting': {
'@test:fakeServer.notExisting': { 'GHTYAJCE': {
'GHTYAJCE': { 'signed_curve25519:AAAAAQ': {
'signed_curve25519:AAAAAQ': { 'key': 'qc72ve94cA28iuE0fXa98QO3uls39DHWdQlYyvvhGh0',
'key': 'qc72ve94cA28iuE0fXa98QO3uls39DHWdQlYyvvhGh0', 'signatures': {
'signatures': { '@test:fakeServer.notExisting': {
'@test:fakeServer.notExisting': { 'ed25519:GHTYAJCE':
'ed25519:GHTYAJCE': 'dFwffr5kTKefO7sjnWLMhTzw7oV31nkPIDRxFy5OQT2OP5++Ao0KRbaBZ6qfuT7lW1owKK0Xk3s7QTBvc/eNDA',
'dFwffr5kTKefO7sjnWLMhTzw7oV31nkPIDRxFy5OQT2OP5++Ao0KRbaBZ6qfuT7lW1owKK0Xk3s7QTBvc/eNDA',
},
}, },
}, },
}, },
}, },
} },
}, }
};
},
'/client/v3/rooms/!localpart%3Aexample.com/invite': (var req) => {}, '/client/v3/rooms/!localpart%3Aexample.com/invite': (var req) => {},
'/client/v3/rooms/!localpart%3Aexample.com/leave': (var req) => {}, '/client/v3/rooms/!localpart%3Aexample.com/leave': (var req) => {},
'/client/v3/rooms/!localpart%3Aexample.com/forget': (var req) => {}, '/client/v3/rooms/!localpart%3Aexample.com/forget': (var req) => {},
@ -1992,8 +1997,11 @@ class FakeMatrixApi extends MockClient {
'/client/v3/keys/upload': (var req) => { '/client/v3/keys/upload': (var req) => {
'one_time_key_counts': { 'one_time_key_counts': {
'curve25519': 10, 'curve25519': 10,
'signed_curve25519': 'signed_curve25519': tryCast<Map<String, Map<String, dynamic>>>(
decodeJson(req)['one_time_keys']?.keys?.length ?? 0, decodeJson(req))?['one_time_keys']
?.keys
.length ??
0,
} }
}, },
'/client/v3/keys/query': (var req) => { '/client/v3/keys/query': (var req) => {

View File

@ -209,7 +209,10 @@ class MatrixApi extends Api {
// fix invalid responses from synapse // fix invalid responses from synapse
// https://github.com/matrix-org/synapse/pull/10922 // https://github.com/matrix-org/synapse/pull/10922
json['ttl'] = json['ttl'].toInt(); final ttl = json['ttl'];
if (ttl is double) {
json['ttl'] = ttl.toInt();
}
return TurnServerCredentials.fromJson(json); return TurnServerCredentials.fromJson(json);
} }

View File

@ -106,12 +106,14 @@ class MatrixException implements Exception {
/// to authenticate itself. Each flow comprises a series of stages. If this request /// to authenticate itself. Each flow comprises a series of stages. If this request
/// doesn't need additional authentication, then this is null. /// doesn't need additional authentication, then this is null.
List<AuthenticationFlow>? get authenticationFlows { List<AuthenticationFlow>? get authenticationFlows {
if (!raw.containsKey('flows') || raw['flows'] is! List) return null; final flows = raw['flows'];
return (raw['flows'] as List) return (flows is List<Map<String, List<String>>>)
.map((flow) => flow['stages']) ? flows
.whereType<List>() .map((flow) => flow['stages'])
.map((stages) => AuthenticationFlow(List<String>.from(stages))) .whereType<List<String>>()
.toList(); .map((stages) => AuthenticationFlow(List<String>.from(stages)))
.toList()
: null;
} }
/// This section contains any information that the client will need to know in order to use a given type /// This section contains any information that the client will need to know in order to use a given type

View File

@ -113,7 +113,7 @@ class MatrixDeviceKeys extends MatrixSignableKey {
@override @override
MatrixDeviceKeys.fromJson(Map<String, dynamic> json) MatrixDeviceKeys.fromJson(Map<String, dynamic> json)
: algorithms = json['algorithms'].cast<String>(), : algorithms = (json['algorithms'] as List).cast<String>(),
deviceId = json['device_id'], deviceId = json['device_id'],
super.fromJson(json); super.fromJson(json);

View File

@ -54,24 +54,15 @@ class SyncUpdate {
: nextBatch = json['next_batch'], : nextBatch = json['next_batch'],
rooms = rooms =
json['rooms'] != null ? RoomsUpdate.fromJson(json['rooms']) : null, json['rooms'] != null ? RoomsUpdate.fromJson(json['rooms']) : null,
presence = presence = ((json['presence'] as Map?)?['events'] as List?)
(json['presence'] != null && json['presence']['events'] != null) ?.map((i) => Presence.fromJson(i))
? (json['presence']['events'] as List) .toList(),
.map((i) => Presence.fromJson(i)) accountData = ((json['account_data'] as Map?)?['events'] as List?)
.toList() ?.map((i) => BasicEvent.fromJson(i))
: null, .toList(),
accountData = (json['account_data'] != null && toDevice = ((json['to_device'] as Map?)?['events'] as List?)
json['account_data']['events'] != null) ?.map((i) => BasicEventWithSender.fromJson(i))
? (json['account_data']['events'] as List) .toList(),
.map((i) => BasicEvent.fromJson(i))
.toList()
: null,
toDevice =
(json['to_device'] != null && json['to_device']['events'] != null)
? (json['to_device']['events'] as List)
.map((i) => BasicEventWithSender.fromJson(i))
.toList()
: null,
deviceLists = json['device_lists'] != null deviceLists = json['device_lists'] != null
? DeviceListsUpdate.fromJson(json['device_lists']) ? DeviceListsUpdate.fromJson(json['device_lists'])
: null, : null,
@ -183,34 +174,25 @@ class JoinedRoomUpdate extends SyncRoomUpdate {
this.unreadNotifications, this.unreadNotifications,
}); });
JoinedRoomUpdate.fromJson(Map<String, dynamic> json) { JoinedRoomUpdate.fromJson(Map<String, dynamic> json)
summary = : summary = json['summary'] != null
json['summary'] != null ? RoomSummary.fromJson(json['summary']) : null; ? RoomSummary.fromJson(json['summary'])
state = (json['state'] != null && json['state']['events'] != null) : null,
? (json['state']['events'] as List) state = ((json['state'] as Map?)?['events'] as List?)
.map((i) => MatrixEvent.fromJson(i)) ?.map((i) => MatrixEvent.fromJson(i))
.toList() .toList(),
: null; timeline = json['timeline'] != null
timeline = json['timeline'] != null ? TimelineUpdate.fromJson(json['timeline'])
? TimelineUpdate.fromJson(json['timeline']) : null,
: null; ephemeral = ((json['ephemeral'] as Map?)?['events'] as List?)
?.map((i) => BasicRoomEvent.fromJson(i))
ephemeral = .toList(),
(json['ephemeral'] != null && json['ephemeral']['events'] != null) accountData = ((json['account_data'] as Map?)?['events'] as List?)
? (json['ephemeral']['events'] as List) ?.map((i) => BasicRoomEvent.fromJson(i))
.map((i) => BasicRoomEvent.fromJson(i)) .toList(),
.toList() unreadNotifications = json['unread_notifications'] != null
? UnreadNotificationCounts.fromJson(json['unread_notifications'])
: null; : null;
accountData =
(json['account_data'] != null && json['account_data']['events'] != null)
? (json['account_data']['events'] as List)
.map((i) => BasicRoomEvent.fromJson(i))
.toList()
: null;
unreadNotifications = json['unread_notifications'] != null
? UnreadNotificationCounts.fromJson(json['unread_notifications'])
: null;
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
@ -247,14 +229,10 @@ class InvitedRoomUpdate extends SyncRoomUpdate {
InvitedRoomUpdate({this.inviteState}); InvitedRoomUpdate({this.inviteState});
InvitedRoomUpdate.fromJson(Map<String, dynamic> json) { InvitedRoomUpdate.fromJson(Map<String, dynamic> json)
inviteState = : inviteState = ((json['invite_state'] as Map?)?['events'] as List?)
(json['invite_state'] != null && json['invite_state']['events'] != null) ?.map((i) => StrippedStateEvent.fromJson(i))
? (json['invite_state']['events'] as List) .toList();
.map((i) => StrippedStateEvent.fromJson(i))
.toList()
: null;
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
@ -278,22 +256,16 @@ class LeftRoomUpdate extends SyncRoomUpdate {
this.accountData, this.accountData,
}); });
LeftRoomUpdate.fromJson(Map<String, dynamic> json) { LeftRoomUpdate.fromJson(Map<String, dynamic> json)
state = (json['state'] != null && json['state']['events'] != null) : state = ((json['state'] as Map?)?['events'] as List?)
? (json['state']['events'] as List) ?.map((i) => MatrixEvent.fromJson(i))
.map((i) => MatrixEvent.fromJson(i)) .toList(),
.toList() timeline = json['timeline'] != null
: null; ? TimelineUpdate.fromJson(json['timeline'])
timeline = json['timeline'] != null : null,
? TimelineUpdate.fromJson(json['timeline']) accountData = ((json['account_data'] as Map?)?['events'] as List?)
: null; ?.map((i) => BasicRoomEvent.fromJson(i))
accountData = .toList();
(json['account_data'] != null && json['account_data']['events'] != null)
? (json['account_data']['events'] as List)
.map((i) => BasicRoomEvent.fromJson(i))
.toList()
: null;
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -35,10 +35,10 @@ void main() {
}, },
}; };
final copy = original.copy(); final copy = original.copy();
original['child']['attr'] = 'raccoon'; (original['child'] as Map<String, dynamic>)['attr'] = 'raccoon';
expect(copy['child']['attr'], 'bunny'); expect((copy['child'] as Map<String, dynamic>)['attr'], 'bunny');
original['child']['list'].add(3); ((original['child'] as Map<String, dynamic>)['list'] as List<int>).add(3);
expect(copy['child']['list'], [1, 2]); expect((copy['child'] as Map<String, dynamic>)['list'], [1, 2]);
}); });
test('should do arrays', () { test('should do arrays', () {
final original = <String, dynamic>{ final original = <String, dynamic>{
@ -48,10 +48,11 @@ void main() {
], ],
}; };
final copy = original.copy(); final copy = original.copy();
original['arr'][0].add(3); ((original['arr'] as List)[0] as List<int>).add(3);
expect(copy['arr'][0], [1, 2]); expect((copy['arr'] as List)[0], [1, 2]);
original['arr'][1]['beep'] = 'blargh'; ((original['arr'] as List)[1] as Map<String, dynamic>)['beep'] = 'blargh';
expect(copy['arr'][1]['beep'], 'boop'); expect(
((copy['arr'] as List)[1] as Map<String, dynamic>)['beep'], 'boop');
}); });
}); });
} }

View File

@ -123,7 +123,7 @@ void main() {
final supportedVersions = await matrixApi.getVersions(); final supportedVersions = await matrixApi.getVersions();
expect(supportedVersions.versions.contains('r0.5.0'), true); expect(supportedVersions.versions.contains('r0.5.0'), true);
expect(supportedVersions.unstableFeatures!['m.lazy_load_members'], true); expect(supportedVersions.unstableFeatures!['m.lazy_load_members'], true);
expect(FakeMatrixApi.api['GET']!['/client/versions']({}), expect(FakeMatrixApi.api['GET']!['/client/versions']!.call({}),
supportedVersions.toJson()); supportedVersions.toJson());
matrixApi.homeserver = null; matrixApi.homeserver = null;
}); });
@ -146,7 +146,7 @@ void main() {
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
final loginTypes = await matrixApi.getLoginFlows(); final loginTypes = await matrixApi.getLoginFlows();
expect(loginTypes?.first.type, 'm.login.password'); expect(loginTypes?.first.type, 'm.login.password');
expect(FakeMatrixApi.api['GET']!['/client/v3/login']({}), expect(FakeMatrixApi.api['GET']!['/client/v3/login']!.call({}),
{'flows': loginTypes?.map((x) => x.toJson()).toList()}); {'flows': loginTypes?.map((x) => x.toJson()).toList()});
matrixApi.homeserver = null; matrixApi.homeserver = null;
}); });
@ -156,7 +156,7 @@ void main() {
LoginType.mLoginPassword, LoginType.mLoginPassword,
identifier: AuthenticationUserIdentifier(user: 'username'), identifier: AuthenticationUserIdentifier(user: 'username'),
); );
expect(FakeMatrixApi.api['POST']!['/client/v3/login']({}), expect(FakeMatrixApi.api['POST']!['/client/v3/login']!.call({}),
loginResponse.toJson()); loginResponse.toJson());
matrixApi.homeserver = null; matrixApi.homeserver = null;
}); });
@ -176,7 +176,9 @@ void main() {
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
final registerResponse = final registerResponse =
await matrixApi.register(kind: AccountKind.guest, username: 'test'); await matrixApi.register(kind: AccountKind.guest, username: 'test');
expect(FakeMatrixApi.api['POST']!['/client/v3/register?kind=guest']({}), expect(
FakeMatrixApi.api['POST']!['/client/v3/register?kind=guest']!
.call({}),
registerResponse.toJson()); registerResponse.toJson());
matrixApi.homeserver = null; matrixApi.homeserver = null;
}); });
@ -192,8 +194,8 @@ void main() {
idAccessToken: '1234', idAccessToken: '1234',
); );
expect( expect(
FakeMatrixApi FakeMatrixApi.api['POST']!['/client/v3/register/email/requestToken']!
.api['POST']!['/client/v3/register/email/requestToken']({}), .call({}),
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
}); });
@ -210,8 +212,8 @@ void main() {
idAccessToken: '1234', idAccessToken: '1234',
); );
expect( expect(
FakeMatrixApi FakeMatrixApi.api['POST']!['/client/v3/register/email/requestToken']!
.api['POST']!['/client/v3/register/email/requestToken']({}), .call({}),
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
}); });
@ -280,7 +282,7 @@ void main() {
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
matrixApi.accessToken = '1234'; matrixApi.accessToken = '1234';
final response = await matrixApi.getAccount3PIDs(); final response = await matrixApi.getAccount3PIDs();
expect(FakeMatrixApi.api['GET']!['/client/v3/account/3pid']({}), expect(FakeMatrixApi.api['GET']!['/client/v3/account/3pid']!.call({}),
{'threepids': response?.map((t) => t.toJson()).toList()}); {'threepids': response?.map((t) => t.toJson()).toList()});
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
}); });
@ -362,7 +364,7 @@ void main() {
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
matrixApi.accessToken = '1234'; matrixApi.accessToken = '1234';
final response = await matrixApi.getCapabilities(); final response = await matrixApi.getCapabilities();
expect(FakeMatrixApi.api['GET']!['/client/v3/capabilities']({}), expect(FakeMatrixApi.api['GET']!['/client/v3/capabilities']!.call({}),
{'capabilities': response.toJson()}); {'capabilities': response.toJson()});
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
}); });
@ -497,8 +499,8 @@ void main() {
); );
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/sync?filter=%7B%7D&since=1234&full_state=false&set_presence=unavailable&timeout=15']( '/client/v3/sync?filter=%7B%7D&since=1234&full_state=false&set_presence=unavailable&timeout=15']!
{}) as Map?, .call({}) as Map?,
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
}); });
@ -575,8 +577,8 @@ void main() {
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/rooms/!localpart%3Aserver.abc/messages?from=1234&to=1234&dir=b&limit=10&filter=%7B%22lazy_load_members%22%3Atrue%7D']( '/client/v3/rooms/!localpart%3Aserver.abc/messages?from=1234&to=1234&dir=b&limit=10&filter=%7B%22lazy_load_members%22%3Atrue%7D']!
{}) as Map?, .call({}) as Map?,
timelineHistoryResponse.toJson()); timelineHistoryResponse.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -666,7 +668,8 @@ void main() {
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/directory/room/%23testalias%3Aexample.com']({}), '/client/v3/directory/room/%23testalias%3Aexample.com']!
.call({}),
roomAliasInformation.toJson()); roomAliasInformation.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -828,7 +831,8 @@ void main() {
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/publicRooms?limit=10&since=1234&server=example.com']({}), '/client/v3/publicRooms?limit=10&since=1234&server=example.com']!
.call({}),
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -850,7 +854,8 @@ void main() {
expect( expect(
FakeMatrixApi FakeMatrixApi
.api['POST']!['/client/v3/publicRooms?server=example.com']({}), .api['POST']!['/client/v3/publicRooms?server=example.com']!
.call({}),
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -864,7 +869,8 @@ void main() {
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v1/rooms/${Uri.encodeComponent('!gPxZhKUssFZKZcoCKY:neko.dev')}/hierarchy']({}), '/client/v1/rooms/${Uri.encodeComponent('!gPxZhKUssFZKZcoCKY:neko.dev')}/hierarchy']!
.call({}),
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -878,7 +884,9 @@ void main() {
limit: 10, limit: 10,
); );
expect(FakeMatrixApi.api['POST']!['/client/v3/user_directory/search']({}), expect(
FakeMatrixApi.api['POST']!['/client/v3/user_directory/search']!
.call({}),
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -926,7 +934,8 @@ void main() {
final response = await matrixApi.getUserProfile('@alice:example.com'); final response = await matrixApi.getUserProfile('@alice:example.com');
expect( expect(
FakeMatrixApi FakeMatrixApi
.api['GET']!['/client/v3/profile/%40alice%3Aexample.com']({}), .api['GET']!['/client/v3/profile/%40alice%3Aexample.com']!
.call({}),
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -936,7 +945,7 @@ void main() {
matrixApi.accessToken = '1234'; matrixApi.accessToken = '1234';
final response = await matrixApi.getTurnServer(); final response = await matrixApi.getTurnServer();
expect(FakeMatrixApi.api['GET']!['/client/v3/voip/turnServer']({}), expect(FakeMatrixApi.api['GET']!['/client/v3/voip/turnServer']!.call({}),
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -1000,7 +1009,8 @@ void main() {
); );
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/presence/${Uri.encodeComponent('@alice:example.com')}/status']({}), '/client/v3/presence/${Uri.encodeComponent('@alice:example.com')}/status']!
.call({}),
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -1030,7 +1040,8 @@ void main() {
); );
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/media/v3/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10']({}), '/media/v3/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10']!
.call({}),
openGraphData.toJson()); openGraphData.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -1061,7 +1072,9 @@ void main() {
matrixApi.accessToken = '1234'; matrixApi.accessToken = '1234';
final devices = await matrixApi.getDevices(); final devices = await matrixApi.getDevices();
expect(FakeMatrixApi.api['GET']!['/client/v3/devices']({})['devices'], expect(
(FakeMatrixApi.api['GET']!['/client/v3/devices']!.call({})
as Map<String, dynamic>?)?['devices'],
devices?.map((i) => i.toJson()).toList()); devices?.map((i) => i.toJson()).toList());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -1131,8 +1144,8 @@ void main() {
.deviceDisplayName, .deviceDisplayName,
'Alices mobile phone'); 'Alices mobile phone');
expect( expect(
FakeMatrixApi FakeMatrixApi.api['POST']!['/client/v3/keys/query']!
.api['POST']!['/client/v3/keys/query']({'device_keys': {}}), .call({'device_keys': {}}),
response.toJson()); response.toJson());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -1148,7 +1161,7 @@ void main() {
timeout: 10, timeout: 10,
); );
expect( expect(
FakeMatrixApi.api['POST']!['/client/v3/keys/claim']({ FakeMatrixApi.api['POST']!['/client/v3/keys/claim']!.call({
'one_time_keys': { 'one_time_keys': {
'@alice:example.com': {'JLAFKJWSCS': 'signed_curve25519'} '@alice:example.com': {'JLAFKJWSCS': 'signed_curve25519'}
} }
@ -1207,7 +1220,7 @@ void main() {
final response = await matrixApi.getPushers(); final response = await matrixApi.getPushers();
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/pushers']({}), FakeMatrixApi.api['GET']!['/client/v3/pushers']!.call({}),
{'pushers': response?.map((i) => i.toJson()).toList()}, {'pushers': response?.map((i) => i.toJson()).toList()},
); );
@ -1245,7 +1258,8 @@ void main() {
); );
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/notifications?from=1234&limit=10&only=1234']({}), '/client/v3/notifications?from=1234&limit=10&only=1234']!
.call({}),
response.toJson(), response.toJson(),
); );
@ -1257,7 +1271,7 @@ void main() {
final response = await matrixApi.getPushRules(); final response = await matrixApi.getPushRules();
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/pushrules']({}), FakeMatrixApi.api['GET']!['/client/v3/pushrules']!.call({}),
{'global': response.toJson()}, {'global': response.toJson()},
); );
@ -1270,8 +1284,8 @@ void main() {
final response = final response =
await matrixApi.getPushRule('global', PushRuleKind.content, 'nocake'); await matrixApi.getPushRule('global', PushRuleKind.content, 'nocake');
expect( expect(
FakeMatrixApi FakeMatrixApi.api['GET']!['/client/v3/pushrules/global/content/nocake']!
.api['GET']!['/client/v3/pushrules/global/content/nocake']({}), .call({}),
response.toJson(), response.toJson(),
); );
@ -1371,7 +1385,8 @@ void main() {
from: '1234', roomId: '!1234', timeout: 10); from: '1234', roomId: '!1234', timeout: 10);
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/events?from=1234&timeout=10&room_id=%211234']({}), '/client/v3/events?from=1234&timeout=10&room_id=%211234']!
.call({}),
response.toJson(), response.toJson(),
); );
@ -1385,7 +1400,8 @@ void main() {
'@alice:example.com', '!localpart:example.com'); '@alice:example.com', '!localpart:example.com');
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags']({}), '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags']!
.call({}),
{'tags': response?.map((k, v) => MapEntry(k, v.toJson()))}, {'tags': response?.map((k, v) => MapEntry(k, v.toJson()))},
); );
@ -1471,7 +1487,8 @@ void main() {
final response = await matrixApi.getWhoIs('@alice:example.com'); final response = await matrixApi.getWhoIs('@alice:example.com');
expect( expect(
FakeMatrixApi FakeMatrixApi
.api['GET']!['/client/v3/admin/whois/%40alice%3Aexample.com']({}), .api['GET']!['/client/v3/admin/whois/%40alice%3Aexample.com']!
.call({}),
response.toJson(), response.toJson(),
); );
@ -1485,7 +1502,8 @@ void main() {
limit: 10, filter: '{}'); limit: 10, filter: '{}');
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/rooms/1234/context/1234?limit=10&filter=%7B%7D']({}), '/client/v3/rooms/1234/context/1234?limit=10&filter=%7B%7D']!
.call({}),
response.toJson(), response.toJson(),
); );
@ -1510,7 +1528,7 @@ void main() {
final response = await matrixApi.getProtocols(); final response = await matrixApi.getProtocols();
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/thirdparty/protocols']({}), FakeMatrixApi.api['GET']!['/client/v3/thirdparty/protocols']!.call({}),
response.map((k, v) => MapEntry(k, v.toJson())), response.map((k, v) => MapEntry(k, v.toJson())),
); );
@ -1522,7 +1540,8 @@ void main() {
final response = await matrixApi.getProtocolMetadata('irc'); final response = await matrixApi.getProtocolMetadata('irc');
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/thirdparty/protocol/irc']({}), FakeMatrixApi.api['GET']!['/client/v3/thirdparty/protocol/irc']!
.call({}),
response.toJson(), response.toJson(),
); );
@ -1534,7 +1553,8 @@ void main() {
final response = await matrixApi.queryLocationByProtocol('irc'); final response = await matrixApi.queryLocationByProtocol('irc');
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/thirdparty/location/irc']({}), FakeMatrixApi.api['GET']!['/client/v3/thirdparty/location/irc']!
.call({}),
response.map((i) => i.toJson()).toList(), response.map((i) => i.toJson()).toList(),
); );
@ -1546,7 +1566,7 @@ void main() {
final response = await matrixApi.queryUserByProtocol('irc'); final response = await matrixApi.queryUserByProtocol('irc');
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/thirdparty/user/irc']({}), FakeMatrixApi.api['GET']!['/client/v3/thirdparty/user/irc']!.call({}),
response.map((i) => i.toJson()).toList(), response.map((i) => i.toJson()).toList(),
); );
@ -1558,8 +1578,8 @@ void main() {
final response = await matrixApi.queryLocationByAlias('1234'); final response = await matrixApi.queryLocationByAlias('1234');
expect( expect(
FakeMatrixApi FakeMatrixApi.api['GET']!['/client/v3/thirdparty/location?alias=1234']!
.api['GET']!['/client/v3/thirdparty/location?alias=1234']({}), .call({}),
response.map((i) => i.toJson()).toList(), response.map((i) => i.toJson()).toList(),
); );
@ -1571,7 +1591,8 @@ void main() {
final response = await matrixApi.queryUserByID('1234'); final response = await matrixApi.queryUserByID('1234');
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/thirdparty/user?userid=1234']({}), FakeMatrixApi.api['GET']!['/client/v3/thirdparty/user?userid=1234']!
.call({}),
response.map((i) => i.toJson()).toList(), response.map((i) => i.toJson()).toList(),
); );
@ -1583,8 +1604,8 @@ void main() {
final response = await matrixApi.requestOpenIdToken('1234', {}); final response = await matrixApi.requestOpenIdToken('1234', {});
expect( expect(
FakeMatrixApi FakeMatrixApi.api['POST']!['/client/v3/user/1234/openid/request_token']!
.api['POST']!['/client/v3/user/1234/openid/request_token']({}), .call({}),
response.toJson(), response.toJson(),
); );
@ -1609,8 +1630,8 @@ void main() {
}; };
final ret = await matrixApi.postRoomKeysVersion(algorithm, authData); final ret = await matrixApi.postRoomKeysVersion(algorithm, authData);
expect( expect(
FakeMatrixApi (FakeMatrixApi.api['POST']!['/client/v3/room_keys/version']!.call({})
.api['POST']!['/client/v3/room_keys/version']({})['version'], as Map<String, dynamic>)['version'],
ret); ret);
}); });
test('getRoomKeysVersionCurrent', () async { test('getRoomKeysVersionCurrent', () async {
@ -1618,7 +1639,8 @@ void main() {
matrixApi.accessToken = '1234'; matrixApi.accessToken = '1234';
final ret = await matrixApi.getRoomKeysVersionCurrent(); final ret = await matrixApi.getRoomKeysVersionCurrent();
expect(FakeMatrixApi.api['GET']!['/client/v3/room_keys/version']({}), expect(
FakeMatrixApi.api['GET']!['/client/v3/room_keys/version']!.call({}),
ret.toJson()); ret.toJson());
}); });
test('putRoomKeysVersion', () async { test('putRoomKeysVersion', () async {
@ -1659,7 +1681,8 @@ void main() {
roomId, sessionId, '5', session); roomId, sessionId, '5', session);
expect( expect(
FakeMatrixApi.api['PUT']![ FakeMatrixApi.api['PUT']![
'/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']!
.call({}),
ret.toJson()); ret.toJson());
}); });
test('getRoomKeyBySessionId', () async { test('getRoomKeyBySessionId', () async {
@ -1671,7 +1694,8 @@ void main() {
final ret = await matrixApi.getRoomKeyBySessionId(roomId, sessionId, '5'); final ret = await matrixApi.getRoomKeyBySessionId(roomId, sessionId, '5');
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']!
.call({}),
ret.toJson()); ret.toJson());
}); });
test('deleteRoomKeyBySessionId', () async { test('deleteRoomKeyBySessionId', () async {
@ -1684,7 +1708,8 @@ void main() {
await matrixApi.deleteRoomKeyBySessionId(roomId, sessionId, '5'); await matrixApi.deleteRoomKeyBySessionId(roomId, sessionId, '5');
expect( expect(
FakeMatrixApi.api['DELETE']![ FakeMatrixApi.api['DELETE']![
'/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']!
.call({}),
ret.toJson()); ret.toJson());
}); });
test('putRoomKeysByRoomId', () async { test('putRoomKeysByRoomId', () async {
@ -1711,7 +1736,8 @@ void main() {
final ret = await matrixApi.putRoomKeysByRoomId(roomId, '5', session); final ret = await matrixApi.putRoomKeysByRoomId(roomId, '5', session);
expect( expect(
FakeMatrixApi.api['PUT']![ FakeMatrixApi.api['PUT']![
'/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']!
.call({}),
ret.toJson()); ret.toJson());
}); });
test('getRoomKeysByRoomId', () async { test('getRoomKeysByRoomId', () async {
@ -1722,7 +1748,8 @@ void main() {
final ret = await matrixApi.getRoomKeysByRoomId(roomId, '5'); final ret = await matrixApi.getRoomKeysByRoomId(roomId, '5');
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']!
.call({}),
ret.toJson()); ret.toJson());
}); });
test('deleteRoomKeysByRoomId', () async { test('deleteRoomKeysByRoomId', () async {
@ -1733,7 +1760,8 @@ void main() {
final ret = await matrixApi.deleteRoomKeysByRoomId(roomId, '5'); final ret = await matrixApi.deleteRoomKeysByRoomId(roomId, '5');
expect( expect(
FakeMatrixApi.api['DELETE']![ FakeMatrixApi.api['DELETE']![
'/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']!
.call({}),
ret.toJson()); ret.toJson());
}); });
test('putRoomKeys', () async { test('putRoomKeys', () async {
@ -1763,7 +1791,8 @@ void main() {
}); });
final ret = await matrixApi.putRoomKeys('5', session); final ret = await matrixApi.putRoomKeys('5', session);
expect( expect(
FakeMatrixApi.api['PUT']!['/client/v3/room_keys/keys?version=5']({}), FakeMatrixApi.api['PUT']!['/client/v3/room_keys/keys?version=5']!
.call({}),
ret.toJson()); ret.toJson());
}); });
test('getRoomKeys', () async { test('getRoomKeys', () async {
@ -1772,7 +1801,8 @@ void main() {
final ret = await matrixApi.getRoomKeys('5'); final ret = await matrixApi.getRoomKeys('5');
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/room_keys/keys?version=5']({}), FakeMatrixApi.api['GET']!['/client/v3/room_keys/keys?version=5']!
.call({}),
ret.toJson()); ret.toJson());
}); });
test('deleteRoomKeys', () async { test('deleteRoomKeys', () async {
@ -1781,8 +1811,8 @@ void main() {
final ret = await matrixApi.deleteRoomKeys('5'); final ret = await matrixApi.deleteRoomKeys('5');
expect( expect(
FakeMatrixApi FakeMatrixApi.api['DELETE']!['/client/v3/room_keys/keys?version=5']!
.api['DELETE']!['/client/v3/room_keys/keys?version=5']({}), .call({}),
ret.toJson()); ret.toJson());
}); });
test('AuthenticationData', () { test('AuthenticationData', () {