summary refs log tree commit diff
path: root/tests/events.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-03 03:42:43 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-04 17:11:04 +0300
commit02ef7411e648e5738bd5a8c97fbda5c00496f337 (patch)
tree464e34e3d4ca43576f36fd71dfc406f5dea0ccf7 /tests/events.cc
parentAdd RoomEvent (diff)
downloadnheko-02ef7411e648e5738bd5a8c97fbda5c00496f337.tar.xz
Add StateEvent
Diffstat (limited to '')
-rw-r--r--tests/events.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/events.cc b/tests/events.cc
index a6a3c30c..cb6abd88 100644
--- a/tests/events.cc
+++ b/tests/events.cc
@@ -3,6 +3,7 @@
 
 #include "Event.h"
 #include "RoomEvent.h"
+#include "StateEvent.h"
 
 #include "AliasesEventContent.h"
 #include "AvatarEventContent.h"
@@ -127,6 +128,50 @@ TEST(RoomEvent, DeserializationException)
 	}
 }
 
+TEST(StateEvent, Deserialization)
+{
+	auto data = QJsonObject{
+		{"content", QJsonObject{{"name", "Name"}}},
+		{"event_id", "$asdfafdf8af:matrix.org"},
+		{"state_key", "some_state_key"},
+		{"prev_content", QJsonObject{{"name", "Previous Name"}}},
+		{"room_id", "!aasdfaeae23r9:matrix.org"},
+		{"sender", "@alice:matrix.org"},
+		{"origin_server_ts", 1323238293289323LL},
+		{"type", "m.room.name"}};
+
+	StateEvent<NameEventContent> event;
+	event.deserialize(data);
+
+	EXPECT_EQ(event.eventId(), "$asdfafdf8af:matrix.org");
+	EXPECT_EQ(event.roomId(), "!aasdfaeae23r9:matrix.org");
+	EXPECT_EQ(event.sender(), "@alice:matrix.org");
+	EXPECT_EQ(event.timestamp(), 1323238293289323);
+	EXPECT_EQ(event.content().name(), "Name");
+	EXPECT_EQ(event.stateKey(), "some_state_key");
+	EXPECT_EQ(event.previousContent().name(), "Previous Name");
+}
+
+TEST(StateEvent, DeserializationException)
+{
+	auto data = QJsonObject{
+		{"content", QJsonObject{{"name", "Name"}}},
+		{"event_id", "$asdfafdf8af:matrix.org"},
+		{"prev_content", QJsonObject{{"name", "Previous Name"}}},
+		{"room_id", "!aasdfaeae23r9:matrix.org"},
+		{"sender", "@alice:matrix.org"},
+		{"origin_server_ts", 1323238293289323LL},
+		{"type", "m.room.name"}};
+
+	StateEvent<NameEventContent> event;
+
+	try {
+		event.deserialize(data);
+	} catch (const DeserializationException &e) {
+		ASSERT_STREQ("state_key key is missing", e.what());
+	}
+}
+
 TEST(EventType, Mapping)
 {
 	EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.aliases"}}), EventType::RoomAliases);