[Event] Add more tests
This commit is contained in:
parent
f4252f2fc3
commit
b827bc7714
|
@ -170,8 +170,8 @@ class Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes this event if the status is < 1. This event will just be removed
|
/// Removes this event if the status is < 1. This event will just be removed
|
||||||
/// from the database and the timelines.
|
/// from the database and the timelines. Returns false if not removed.
|
||||||
Future<dynamic> remove() async {
|
bool remove() {
|
||||||
if (status < 1) {
|
if (status < 1) {
|
||||||
if (room.client.store != null)
|
if (room.client.store != null)
|
||||||
room.client.store.db.rawDelete("DELETE FROM Events WHERE id=?", [id]);
|
room.client.store.db.rawDelete("DELETE FROM Events WHERE id=?", [id]);
|
||||||
|
@ -185,7 +185,9 @@ class Event {
|
||||||
"status": -2,
|
"status": -2,
|
||||||
"content": {"body": "Removed..."}
|
"content": {"body": "Removed..."}
|
||||||
}));
|
}));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to send this event again. Only works with events of status -1.
|
/// Try to send this event again. Only works with events of status -1.
|
||||||
|
|
|
@ -23,10 +23,13 @@
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:famedlysdk/src/Event.dart';
|
import 'package:famedlysdk/src/Event.dart';
|
||||||
import 'package:famedlysdk/src/User.dart';
|
import 'package:famedlysdk/src/User.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
import 'FakeMatrixApi.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
/// All Tests related to the Event
|
/// All Tests related to the Event
|
||||||
group("Event", () {
|
group("Event", () {
|
||||||
|
@ -157,5 +160,28 @@ void main() {
|
||||||
event = Event.fromJson(jsonObj, null);
|
event = Event.fromJson(jsonObj, null);
|
||||||
expect(event.type, EventTypes.Reply);
|
expect(event.type, EventTypes.Reply);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("remove", () async {
|
||||||
|
Event event = Event.fromJson(
|
||||||
|
jsonObj, Room(id: "1234", client: Client("testclient", debug: true)));
|
||||||
|
expect(event.remove(), false);
|
||||||
|
event.status = 0;
|
||||||
|
expect(event.remove(), 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");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue