diff --git a/.gitignore b/.gitignore index 68373a03..beee394e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ coverage/ coverage_badge.svg coverage.xml TEST-report.* +coverage_dir/* # IntelliJ related *.iml diff --git a/lib/fake_matrix_api.dart b/lib/fake_matrix_api.dart index 34bf8e37..a0dcc359 100644 --- a/lib/fake_matrix_api.dart +++ b/lib/fake_matrix_api.dart @@ -43,6 +43,7 @@ class FakeMatrixApi extends BaseClient { static Map> get calledEndpoints => currentApi!._calledEndpoints; + static int get eventCounter => currentApi!._eventCounter; static set eventCounter(int c) { currentApi!._eventCounter = c; @@ -69,6 +70,8 @@ class FakeMatrixApi extends BaseClient { static FakeMatrixApi? currentApi; + static RoomsUpdate? _pendingRoomsUpdate; + static Future firstWhereValue(String value) { return firstWhere((v) => v == value); } @@ -105,20 +108,17 @@ class FakeMatrixApi extends BaseClient { '${request.url.path.split('/_matrix').last}?${request.url.query}'; } - // ignore: avoid_print - if (_trace) print('called $action'); - if (action.endsWith('?')) { action = action.substring(0, action.length - 1); } - if (action.endsWith('?server_name')) { - // This can be removed after matrix_api_lite is released with: - // https://gitlab.com/famedly/libraries/matrix_api_lite/-/merge_requests/16 - action = action.substring(0, action.length - 12); - } + if (action.endsWith('/')) { action = action.substring(0, action.length - 1); } + + // ignore: avoid_print + if (_trace) print('called $action'); + final method = request.method; final dynamic data = method == 'GET' ? request.url.queryParameters : request.body; @@ -214,6 +214,8 @@ class FakeMatrixApi extends BaseClient { 'curve25519': 10, 'signed_curve25519': 100, }, + if (_pendingRoomsUpdate != null) + 'rooms': _pendingRoomsUpdate?.toJson(), }; } else if (method == 'PUT' && _client != null && @@ -2536,9 +2538,19 @@ class FakeMatrixApi extends BaseClient { '/client/v3/pushers/set': (var reqI) => {}, '/client/v3/join/1234': (var reqI) => {'room_id': '1234'}, '/client/v3/logout/all': (var reqI) => {}, - '/client/v3/createRoom': (var reqI) => { - 'room_id': '!1234:fakeServer.notExisting', - }, + '/client/v3/createRoom': (var reqI) { + final roomId = '!1234:fakeServer.notExisting'; + unawaited( + Future.delayed(Duration(milliseconds: 100)).then((_) { + _pendingRoomsUpdate = + RoomsUpdate(join: {roomId: JoinedRoomUpdate()}); + }), + ); + + return { + 'room_id': roomId, + }; + }, '/client/v3/rooms/!localpart%3Aserver.abc/read_markers': (var reqI) => {}, '/client/v3/rooms/!localpart:server.abc/kick': (var reqI) => {}, '/client/v3/rooms/!localpart%3Aserver.abc/ban': (var reqI) => {}, diff --git a/test/client_test.dart b/test/client_test.dart index 50bb4e9f..269045f6 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -1234,6 +1234,9 @@ void main() { 'preset': 'private_chat', }, ); + + // we wait for the rooms to be added to sync in the fake matrix api + await Future.delayed(Duration(milliseconds: 100)); }); test('Test the fake store api', () async { final database = await getDatabase(null); @@ -1255,7 +1258,7 @@ void main() { await client1.abortSync(); expect(client1.isLogged(), true); - expect(client1.rooms.length, 3); + expect(client1.rooms.length, 8); final client2 = Client( 'testclient', @@ -1273,7 +1276,7 @@ void main() { expect(client2.homeserver, client1.homeserver); expect(client2.deviceID, client1.deviceID); expect(client2.deviceName, client1.deviceName); - expect(client2.rooms.length, 3); + expect(client2.rooms.length, 4); if (client2.encryptionEnabled) { expect( client2.encryption?.fingerprintKey,