Page MenuHomePhorge

No OneTemporary

Size
4 KB
Referenced Files
None
Subscribers
None
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index b338d58..9d17561 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -1,77 +1,78 @@
include(CTest)
set(KAZVTEST_RESPATH ${CMAKE_CURRENT_SOURCE_DIR}/resources)
configure_file(kazvtest-respath.hpp.in kazvtest-respath.hpp)
add_executable(kazvtest
testmain.cpp
basejobtest.cpp
event-test.cpp
cursorutiltest.cpp
base/serialization-test.cpp
base/types-test.cpp
base/immer-utils-test.cpp
base/json-utils-test.cpp
client/client-test-util.cpp
client/discovery-test.cpp
client/sync-test.cpp
client/content-test.cpp
client/paginate-test.cpp
client/util-test.cpp
client/serialization-test.cpp
client/encrypted-file-test.cpp
client/sdk-test.cpp
client/thread-safety-test.cpp
client/room-test.cpp
client/random-generator-test.cpp
client/profile-test.cpp
client/kick-test.cpp
client/ban-test.cpp
client/join-test.cpp
client/keys-test.cpp
client/device-ops-test.cpp
client/send-test.cpp
client/encryption-test.cpp
client/redact-test.cpp
client/tagging-test.cpp
client/account-data-test.cpp
client/room/room-actions-test.cpp
client/room/local-echo-test.cpp
client/room/event-relationships-test.cpp
+ client/room/member-membership.cpp
client/push-rules-desc-test.cpp
client/notification-handler-test.cpp
client/validator-test.cpp
client/power-levels-desc-test.cpp
client/client-test.cpp
kazvjobtest.cpp
event-emitter-test.cpp
crypto-test.cpp
crypto/deterministic-test.cpp
promise-test.cpp
store-test.cpp
file-desc-test.cpp
)
target_include_directories(
kazvtest
PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/client)
target_compile_definitions(kazvtest PRIVATE CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS)
target_link_libraries(kazvtest
PRIVATE Catch2::Catch2WithMain
PRIVATE kazv
PRIVATE kazveventemitter
PRIVATE kazvjob
PRIVATE nlohmann_json::nlohmann_json
PRIVATE immer
PRIVATE lager
PRIVATE zug
PRIVATE kazvtestfixtures
)
add_test(NAME kazvtest COMMAND kazvtest "~[needs-internet]")
diff --git a/src/tests/client/room/member-membership.cpp b/src/tests/client/room/member-membership.cpp
new file mode 100644
index 0000000..41f0c23
--- /dev/null
+++ b/src/tests/client/room/member-membership.cpp
@@ -0,0 +1,83 @@
+/*
+ * This file is part of libkazv.
+ * SPDX-FileCopyrightText: 2024 nannanko <nannanko@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <libkazv-config.hpp>
+
+#include <event.hpp>
+#include <types.hpp>
+#include <jsonwrap.hpp>
+#include <room/room-model.hpp>
+
+#include <catch2/catch_all.hpp>
+#include <nlohmann/json.hpp>
+#include <immer/flex_vector.hpp>
+
+#include <string>
+
+using namespace Kazv;
+
+static Event event(const std::string &membership)
+{
+ return Event{json{
+ {"content", {
+ {"membership", membership}
+ }}
+ }};
+}
+
+TEST_CASE("Get members by membership", "[client][room]")
+{
+ RoomModel r;
+ const auto joinedIds = immer::flex_vector<std::string>{
+ std::string{"@mew_joined:example.com"}
+ };
+ const auto invitedIds = immer::flex_vector<std::string>{
+ std::string{"@mew_invited:example.com"}
+ };
+ const auto knockedIds = immer::flex_vector<std::string>{
+ std::string{"@mew_knocked:example.com"}
+ };
+ const auto leftIds = immer::flex_vector<std::string>{
+ std::string{"@mew_left:example.com"}
+ };
+ const auto bannedIds = immer::flex_vector<std::string>{
+ std::string{"@mew_banned:example.com"}
+ };
+
+ const auto joinedEvents = EventList{
+ event("join")
+ };
+ const auto invitedEvents = EventList{
+ event("invite")
+ };
+ const auto knockedEvents = EventList{
+ event("knock")
+ };
+ const auto leftEvents = EventList{
+ event("leave")
+ };
+ const auto bannedEvents = EventList{
+ event("ban")
+ };
+
+ r.stateEvents = r.stateEvents.set({"m.room.member", joinedIds[0]}, joinedEvents[0]);
+ r.stateEvents = r.stateEvents.set({"m.room.member", invitedIds[0]}, invitedEvents[0]);
+ r.stateEvents = r.stateEvents.set({"m.room.member", knockedIds[0]}, knockedEvents[0]);
+ r.stateEvents = r.stateEvents.set({"m.room.member", leftIds[0]}, leftEvents[0]);
+ r.stateEvents = r.stateEvents.set({"m.room.member", bannedIds[0]}, bannedEvents[0]);
+
+ REQUIRE(r.joinedMemberIds() == joinedIds);
+ REQUIRE(r.invitedMemberIds() == invitedIds);
+ REQUIRE(r.knockedMemberIds() == knockedIds);
+ REQUIRE(r.leftMemberIds() == leftIds);
+ REQUIRE(r.bannedMemberIds() == bannedIds);
+
+ REQUIRE(r.joinedMemberEvents() == joinedEvents);
+ REQUIRE(r.invitedMemberEvents() == invitedEvents);
+ REQUIRE(r.knockedMemberEvents() == knockedEvents);
+ REQUIRE(r.leftMemberEvents() == leftEvents);
+ REQUIRE(r.bannedMemberEvents() == bannedEvents);
+}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 12:16 PM (7 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55156
Default Alt Text
(4 KB)

Event Timeline