More tests
This commit is contained in:
parent
e1352e0f9e
commit
fd7302bcde
|
@ -263,6 +263,7 @@ class Connection {
|
|||
_syncRequest = jsonRequest(type: "GET", action: action);
|
||||
final int hash = _syncRequest.hashCode;
|
||||
final syncResp = await _syncRequest;
|
||||
if (hash != _syncRequest.hashCode) return;
|
||||
if (syncResp is ErrorResponse) {
|
||||
onError.add(syncResp);
|
||||
await Future.delayed(Duration(seconds: syncErrorTimeoutSec), () {});
|
||||
|
|
|
@ -437,10 +437,10 @@ class Room {
|
|||
|
||||
/// Request the full list of participants from the server. The local list
|
||||
/// from the store is not complete if the client uses lazy loading.
|
||||
Future<List<User>> requestParticipants(Client matrix) async {
|
||||
Future<List<User>> requestParticipants() async {
|
||||
List<User> participants = [];
|
||||
|
||||
dynamic res = await matrix.connection
|
||||
dynamic res = await client.connection
|
||||
.jsonRequest(type: "GET", action: "/client/r0/rooms/${id}/members");
|
||||
if (res is ErrorResponse || !(res["chunk"] is List<dynamic>))
|
||||
return participants;
|
||||
|
|
|
@ -71,6 +71,24 @@ class FakeMatrixApi extends MockClient {
|
|||
{"type": "m.login.password"}
|
||||
]
|
||||
},
|
||||
"/client/r0/rooms/!localpart:server.abc/members": (var req) => {
|
||||
"chunk": [
|
||||
{
|
||||
"content": {
|
||||
"membership": "join",
|
||||
"avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF",
|
||||
"displayname": "Alice Margatroid"
|
||||
},
|
||||
"type": "m.room.member",
|
||||
"event_id": "§143273582443PhrSn:example.org",
|
||||
"room_id": "!636q39766251:example.com",
|
||||
"sender": "@example:example.org",
|
||||
"origin_server_ts": 1432735824653,
|
||||
"unsigned": {"age": 1234},
|
||||
"state_key": "@alice:example.org"
|
||||
}
|
||||
]
|
||||
},
|
||||
"/client/r0/sync": (var req) => {
|
||||
"next_batch": Random().nextDouble().toString(),
|
||||
"presence": {
|
||||
|
@ -210,7 +228,8 @@ class FakeMatrixApi extends MockClient {
|
|||
"/client/r0/logout/all": (var reqI) => {},
|
||||
"/client/r0/createRoom": (var reqI) => {
|
||||
"room_id": "!1234:fakeServer.notExisting",
|
||||
}
|
||||
},
|
||||
"/client/r0/rooms/!localpart:server.abc/read_markers": (var reqI) => {},
|
||||
},
|
||||
"PUT": {},
|
||||
"DELETE": {
|
||||
|
|
|
@ -24,22 +24,29 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:famedlysdk/src/Room.dart';
|
||||
import 'package:famedlysdk/src/Client.dart';
|
||||
import 'dart:async';
|
||||
import 'package:famedlysdk/src/User.dart';
|
||||
import 'FakeMatrixApi.dart';
|
||||
|
||||
void main() {
|
||||
/// All Tests related to the Event
|
||||
group("Room", () {
|
||||
Client matrix = Client("testclient");
|
||||
matrix.connection.httpClient = FakeMatrixApi();
|
||||
matrix.homeserver = "https://fakeServer.notExisting";
|
||||
Client matrix;
|
||||
Room room;
|
||||
|
||||
test("Create from json", () async {
|
||||
Client matrix = Client("testclient");
|
||||
/// All Tests related to the Event
|
||||
group("Room", () {
|
||||
test('Login', () async {
|
||||
matrix = Client("testclient", debug: true);
|
||||
matrix.connection.httpClient = FakeMatrixApi();
|
||||
matrix.homeserver = "https://fakeServer.notExisting";
|
||||
|
||||
final bool checkResp =
|
||||
await matrix.checkServer("https://fakeServer.notExisting");
|
||||
|
||||
final bool loginResp = await matrix.login("test", "1234");
|
||||
|
||||
expect(checkResp, true);
|
||||
expect(loginResp, true);
|
||||
});
|
||||
|
||||
test("Create from json", () async {
|
||||
final String id = "!localpart:server.abc";
|
||||
final String name = "My Room";
|
||||
final String membership = "join";
|
||||
|
@ -116,5 +123,22 @@ void main() {
|
|||
expect(value, 0);
|
||||
});
|
||||
});
|
||||
|
||||
test("sendReadReceipt", () async {
|
||||
final dynamic resp =
|
||||
await room.sendReadReceipt("§1234:fakeServer.notExisting");
|
||||
expect(resp, {});
|
||||
});
|
||||
|
||||
test("requestParticipants", () async {
|
||||
final List<User> participants = await room.requestParticipants();
|
||||
expect(participants.length, 1);
|
||||
User user = participants[0];
|
||||
expect(user.id, "@alice:example.org");
|
||||
expect(user.displayName, "Alice Margatroid");
|
||||
expect(user.membership, "join");
|
||||
expect(user.avatarUrl.mxc, "mxc://example.org/SEsfnsuifSDFSSEF");
|
||||
expect(user.room.id, "!localpart:server.abc");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue