Merge branch 'tests-enhance-coverage' into 'master'

[Tests] Add more tests

See merge request famedly/famedlysdk!48
This commit is contained in:
Marcel 2019-07-24 08:55:21 +00:00
commit 036e50b1d1
6 changed files with 61 additions and 6 deletions

View file

@ -23,7 +23,9 @@
library famedlysdk;
export 'package:famedlysdk/src/requests/SetPushersRequest.dart';
export 'package:famedlysdk/src/responses/ErrorResponse.dart';
export 'package:famedlysdk/src/responses/PushrulesResponse.dart';
export 'package:famedlysdk/src/sync/RoomUpdate.dart';
export 'package:famedlysdk/src/sync/EventUpdate.dart';
export 'package:famedlysdk/src/utils/ChatTime.dart';

View file

@ -255,7 +255,7 @@ class Client {
}
/// 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(
type: HTTPType.POST,
action: "/client/r0/pushers/set",
@ -264,9 +264,8 @@ class Client {
if (resp is ErrorResponse) {
connection.onError.add(resp);
return null;
}
return null;
return resp;
}
}

View file

@ -170,11 +170,12 @@ class Event {
}
/// Removes this event if the status is < 1. This event will just be removed
/// from the database and the timelines.
Future<dynamic> remove() async {
/// from the database and the timelines. Returns false if not removed.
Future<bool> remove() async {
if (status < 1) {
if (room.client.store != null)
room.client.store.db.rawDelete("DELETE FROM Events WHERE id=?", [id]);
await room.client.store.db
.rawDelete("DELETE FROM Events WHERE id=?", [id]);
room.client.connection.onEvent.add(EventUpdate(
roomID: room.id,
@ -185,7 +186,9 @@ class Event {
"status": -2,
"content": {"body": "Removed..."}
}));
return true;
}
return false;
}
/// Try to send this event again. Only works with events of status -1.

View file

@ -26,6 +26,7 @@ import 'dart:async';
import 'package:famedlysdk/src/Client.dart';
import 'package:famedlysdk/src/Connection.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/PushrulesResponse.dart';
import 'package:famedlysdk/src/sync/EventUpdate.dart';
@ -248,6 +249,26 @@ void main() {
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",
kind: "http",
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 {
Future<LoginState> loginStateFuture =
matrix.connection.onLoginStateChanged.stream.first;

View file

@ -23,10 +23,13 @@
import 'dart:convert';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:famedlysdk/src/Event.dart';
import 'package:famedlysdk/src/User.dart';
import 'package:flutter_test/flutter_test.dart';
import 'FakeMatrixApi.dart';
void main() {
/// All Tests related to the Event
group("Event", () {
@ -157,5 +160,30 @@ void main() {
event = Event.fromJson(jsonObj, null);
expect(event.type, EventTypes.Reply);
});
test("remove", () async {
Event event = Event.fromJson(
jsonObj, Room(id: "1234", client: Client("testclient", debug: true)));
final bool removed1 = await event.remove();
event.status = 0;
final bool removed2 = await event.remove();
expect(removed1, false);
expect(removed2, true);
});
test("sendAgain", () async {
Client matrix = Client("testclient", debug: true);
matrix.connection.httpClient = FakeMatrixApi();
await matrix.checkServer("https://fakeServer.notExisting");
await matrix.login("test", "1234");
Event event = Event.fromJson(
jsonObj, Room(id: "!1234:example.com", client: matrix));
final String resp1 = await event.sendAgain();
event.status = -1;
final String resp2 = await event.sendAgain(txid: "1234");
expect(resp1, null);
expect(resp2, "42");
});
});
}

View file

@ -451,6 +451,8 @@ class FakeMatrixApi extends MockClient {
"device_id": "GHTYAJCE"
},
"/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/createRoom": (var reqI) => {
"room_id": "!1234:fakeServer.notExisting",