test: Add tests for account data store and retrieve
fixes https://gitlab.com/famedly/company/frontend/famedlysdk/-/issues/326
This commit is contained in:
parent
9d9b1e38ec
commit
8c096ef6ca
|
|
@ -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();
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue