Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add rooms created by fake matrix api to sync for tests #2000

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ coverage/
coverage_badge.svg
coverage.xml
TEST-report.*
coverage_dir/*

# IntelliJ related
*.iml
Expand Down
34 changes: 23 additions & 11 deletions lib/fake_matrix_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class FakeMatrixApi extends BaseClient {

static Map<String, List<dynamic>> get calledEndpoints =>
currentApi!._calledEndpoints;

static int get eventCounter => currentApi!._eventCounter;
static set eventCounter(int c) {
currentApi!._eventCounter = c;
Expand All @@ -69,6 +70,8 @@ class FakeMatrixApi extends BaseClient {

static FakeMatrixApi? currentApi;

static RoomsUpdate? _pendingRoomsUpdate;

static Future<String> firstWhereValue(String value) {
return firstWhere((v) => v == value);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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) => {},
Expand Down
7 changes: 5 additions & 2 deletions test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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',
Expand All @@ -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,
Expand Down
Loading