Merge branch 'nico/account-data-test' into 'main'

test: Add tests for account data store and retrieve

Closes #326

See merge request famedly/company/frontend/famedlysdk!1199
This commit is contained in:
Krille 2022-12-27 08:51:42 +00:00
commit f5b470eea9
2 changed files with 59 additions and 1 deletions

View File

@ -287,6 +287,38 @@ void main() {
// To check if the emoji is properly added, we need to wait for a sync roundtrip // To check if the emoji is properly added, we need to wait for a sync roundtrip
}); });
test('accountData', () async {
final content = {
'bla': 'blub',
};
final key = 'abc def!/_-';
await matrix.setAccountData(matrix.userID!, key, content);
final dbContent = await matrix.database?.getAccountData();
expect(matrix.accountData[key]?.content, content);
expect(dbContent?[key]?.content, content);
});
test('roomAccountData', () async {
final content = {
'bla': 'blub',
};
final key = 'abc def!/_-';
final roomId = '!726s6s6q:example.com';
await matrix.setAccountDataPerRoom(matrix.userID!, roomId, key, content);
final roomFromList = (await matrix.database?.getRoomList(matrix))
?.firstWhere((room) => room.id == roomId);
final roomFromDb = await matrix.database?.getSingleRoom(matrix, roomId);
expect(
matrix.getRoomById(roomId)?.roomAccountData[key]?.content, content);
expect(roomFromList?.roomAccountData[key]?.content, content);
expect(roomFromDb?.roomAccountData[key]?.content, content,
skip: 'The single room function does not load account data');
});
test('Logout', () async { test('Logout', () async {
final loginStateFuture = matrix.onLoginStateChanged.stream.first; final loginStateFuture = matrix.onLoginStateChanged.stream.first;
await matrix.logout(); await matrix.logout();

View File

@ -164,7 +164,7 @@ class FakeMatrixApi extends BaseClient {
} else if (method == 'PUT' && } else if (method == 'PUT' &&
_client != null && _client != null &&
action.contains('/account_data/') && action.contains('/account_data/') &&
!action.contains('/room/')) { !action.contains('/rooms/')) {
final type = Uri.decodeComponent(action.split('/').last); final type = Uri.decodeComponent(action.split('/').last);
final syncUpdate = sdk.SyncUpdate( final syncUpdate = sdk.SyncUpdate(
nextBatch: '', nextBatch: '',
@ -178,6 +178,32 @@ class FakeMatrixApi extends BaseClient {
await _client?.handleSync(syncUpdate); await _client?.handleSync(syncUpdate);
} }
res = {}; res = {};
} else if (method == 'PUT' &&
_client != null &&
action.contains('/account_data/') &&
action.contains('/rooms/')) {
final segments = action.split('/');
final type = Uri.decodeComponent(segments.last);
final roomId = Uri.decodeComponent(segments[segments.length - 3]);
final syncUpdate = sdk.SyncUpdate(
nextBatch: '',
rooms: RoomsUpdate(
join: {
roomId: JoinedRoomUpdate(accountData: [
sdk.BasicRoomEvent(
content: decodeJson(data), type: type, roomId: roomId)
])
},
),
);
if (_client?.database != null) {
await _client?.database?.transaction(() async {
await _client?.handleSync(syncUpdate);
});
} else {
await _client?.handleSync(syncUpdate);
}
res = {};
} else { } else {
res = {'errcode': 'M_UNRECOGNIZED', 'error': 'Unrecognized request'}; res = {'errcode': 'M_UNRECOGNIZED', 'error': 'Unrecognized request'};
statusCode = 405; statusCode = 405;