[Client] Add more tests

This commit is contained in:
Christian Pauly 2019-07-24 09:59:29 +02:00
parent d088e053ed
commit f4252f2fc3
3 changed files with 24 additions and 3 deletions

View file

@ -255,7 +255,7 @@ class Client {
} }
/// This endpoint allows the creation, modification and deletion of pushers for this user ID. /// This endpoint allows the creation, modification and deletion of pushers for this user ID.
Future setPushers(SetPushersRequest data) async { Future<dynamic> setPushers(SetPushersRequest data) async {
final dynamic resp = await connection.jsonRequest( final dynamic resp = await connection.jsonRequest(
type: HTTPType.POST, type: HTTPType.POST,
action: "/client/r0/pushers/set", action: "/client/r0/pushers/set",
@ -264,9 +264,8 @@ class Client {
if (resp is ErrorResponse) { if (resp is ErrorResponse) {
connection.onError.add(resp); connection.onError.add(resp);
return null;
} }
return null; return resp;
} }
} }

View file

@ -26,6 +26,7 @@ import 'dart:async';
import 'package:famedlysdk/src/Client.dart'; import 'package:famedlysdk/src/Client.dart';
import 'package:famedlysdk/src/Connection.dart'; import 'package:famedlysdk/src/Connection.dart';
import 'package:famedlysdk/src/User.dart'; import 'package:famedlysdk/src/User.dart';
import 'package:famedlysdk/src/requests/SetPushersRequest.dart';
import 'package:famedlysdk/src/responses/ErrorResponse.dart'; import 'package:famedlysdk/src/responses/ErrorResponse.dart';
import 'package:famedlysdk/src/responses/PushrulesResponse.dart'; import 'package:famedlysdk/src/responses/PushrulesResponse.dart';
import 'package:famedlysdk/src/sync/EventUpdate.dart'; import 'package:famedlysdk/src/sync/EventUpdate.dart';
@ -248,6 +249,25 @@ void main() {
expect(pushrules.toJson(), awaited_resp.toJson()); expect(pushrules.toJson(), awaited_resp.toJson());
}); });
test('setPushers', () async {
final SetPushersRequest data = SetPushersRequest(
app_id: "com.famedly.famedlysdk",
device_display_name: "GitLabCi",
app_display_name: "famedlySDK",
pushkey: "abcdefg",
lang: "en",
data: PusherData(
format: "event_id_only", url: "https://examplepushserver.com"));
final dynamic resp = await matrix.setPushers(data);
expect(resp is ErrorResponse, false);
});
test('joinRoomById', () async {
final String roomID = "1234";
final Map<String, dynamic> resp = await matrix.joinRoomById(roomID);
expect(resp["room_id"], roomID);
});
test('Logout when token is unknown', () async { test('Logout when token is unknown', () async {
Future<LoginState> loginStateFuture = Future<LoginState> loginStateFuture =
matrix.connection.onLoginStateChanged.stream.first; matrix.connection.onLoginStateChanged.stream.first;

View file

@ -451,6 +451,8 @@ class FakeMatrixApi extends MockClient {
"device_id": "GHTYAJCE" "device_id": "GHTYAJCE"
}, },
"/client/r0/logout": (var reqI) => {}, "/client/r0/logout": (var reqI) => {},
"/client/r0/pushers/set": (var reqI) => {},
"/client/r0/join/1234": (var reqI) => {"room_id": "1234"},
"/client/r0/logout/all": (var reqI) => {}, "/client/r0/logout/all": (var reqI) => {},
"/client/r0/createRoom": (var reqI) => { "/client/r0/createRoom": (var reqI) => {
"room_id": "!1234:fakeServer.notExisting", "room_id": "!1234:fakeServer.notExisting",