Page MenuHomePhorge

D138.1732555343.diff
No OneTemporary

Size
6 KB
Referenced Files
None
Subscribers
None

D138.1732555343.diff

diff --git a/src/client/client.hpp b/src/client/client.hpp
--- a/src/client/client.hpp
+++ b/src/client/client.hpp
@@ -301,7 +301,8 @@
bool allowFederate = true,
std::optional<std::string> topic = {},
JsonWrap powerLevelContentOverride = json::object(),
- std::optional<CreateRoomPreset> preset = std::nullopt
+ std::optional<CreateRoomPreset> preset = std::nullopt,
+ immer::array<Event> initialState = immer::array<Event>()
) const;
/**
diff --git a/src/client/client.cpp b/src/client/client.cpp
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -156,7 +156,8 @@
bool allowFederate,
std::optional<std::string> topic,
JsonWrap powerLevelContentOverride,
- std::optional<CreateRoomPreset> preset
+ std::optional<CreateRoomPreset> preset,
+ immer::array<Event> initialState
) const
-> PromiseT
{
@@ -174,6 +175,7 @@
{"m.federate", allowFederate}
};
a.preset = preset;
+ a.initialState = initialState;
return m_ctx.dispatch(std::move(a));
}
diff --git a/src/tests/client/create-room-test.cpp b/src/tests/client/create-room-test.cpp
--- a/src/tests/client/create-room-test.cpp
+++ b/src/tests/client/create-room-test.cpp
@@ -16,7 +16,7 @@
#include <cursorutil.hpp>
#include <sdk-model.hpp>
#include <client/client.hpp>
-
+#include <client/actions/membership.hpp>
#include "client-test-util.hpp"
#include "action-mock-utils.hpp"
#include "factory.hpp"
@@ -53,6 +53,10 @@
auto client = Client(Client::InEventLoopTag{}, mockContext, sdk.context());
+ auto initialState = immer::array<Event>{
+ makeEvent(withEventType("moe.kazv.mxc.some-type") | withStateKey(""))
+ };
+
client.createRoom(
/* visibility = */ RoomVisibility::Private,
/* name = */ "some name",
@@ -62,7 +66,8 @@
/* allowFederate = */ true,
/* topic = */ "some topic",
/* powerLevelContentOverride = */ json::object({{"messages", 1}}),
- /* preset = */ CreateRoomPreset::TrustedPrivateChat
+ /* preset = */ CreateRoomPreset::TrustedPrivateChat,
+ /* initialState = */ initialState
).then([&io](auto) {
io.stop();
});
@@ -81,4 +86,113 @@
}));
REQUIRE(action.topic == "some topic");
REQUIRE(action.preset == CreateRoomPreset::TrustedPrivateChat);
+ REQUIRE(action.initialState == initialState);
+}
+
+TEST_CASE("CreateRoomAction", "[client][create-room]")
+{
+ ClientModel m = makeClient();
+ auto action = CreateRoomAction{};
+ action.visibility = RoomVisibility::Private;
+ action.name = "some name";
+ action.roomAliasName = "alias";
+ action.invite = immer::array<std::string>{"@invited:example.com"};
+ action.isDirect = true;
+ action.powerLevelContentOverride = json{{"messages", 1}};
+ action.creationContent = json::object({
+ {"m.federate", true},
+ });
+ action.topic = "some topic";
+ action.preset = CreateRoomPreset::TrustedPrivateChat;
+ action.initialState = immer::array<Event>{
+ json{
+ {"type", "moe.kazv.mxc.some-type"},
+ {"state_key", "@mew:example.com"},
+ {"content", {
+ {"foo", "bar"},
+ }},
+ },
+ };
+
+ SECTION("base") {
+ auto [next, _] = updateClient(m, action);
+ assert1Job(next);
+ for1stJob(next, [action](const BaseJob &job) {
+ auto body = json::parse(std::get<BytesBody>(job.requestBody()));
+ REQUIRE(body["creation_content"] == json{
+ {"m.federate", true},
+ });
+ REQUIRE(body["initial_state"] == json::array({action.initialState[0].originalJson().get()}));
+ REQUIRE(body["invite"] == json{"@invited:example.com"});
+ REQUIRE(!body.contains("invite_3pid"));
+ REQUIRE(body["is_direct"] == true);
+ REQUIRE(body["name"] == "some name");
+ REQUIRE(body["power_level_content_override"] == json{
+ {"messages", 1},
+ });
+ REQUIRE(body["preset"] == "trusted_private_chat");
+ REQUIRE(body["room_alias_name"] == "alias");
+ REQUIRE(!body.contains("room_version"));
+ REQUIRE(body["topic"] == "some topic");
+ REQUIRE(body["visibility"] == "private");
+ });
+ }
+
+ WHEN("visibility: public") {
+ action.visibility = RoomVisibility::Public;
+ auto [next, _] = updateClient(m, action);
+ for1stJob(next, [action](const BaseJob &job) {
+ auto body = json::parse(std::get<BytesBody>(job.requestBody()));
+ REQUIRE(body["visibility"] == "public");
+ });
+ }
+
+ WHEN("preset: public_chat") {
+ action.preset = CreateRoomPreset::PublicChat;
+ auto [next, _] = updateClient(m, action);
+ for1stJob(next, [action](const BaseJob &job) {
+ auto body = json::parse(std::get<BytesBody>(job.requestBody()));
+ REQUIRE(body["preset"] == "public_chat");
+ });
+ }
+
+ WHEN("preset: private_chat") {
+ action.preset = CreateRoomPreset::PrivateChat;
+ auto [next, _] = updateClient(m, action);
+ for1stJob(next, [action](const BaseJob &job) {
+ auto body = json::parse(std::get<BytesBody>(job.requestBody()));
+ REQUIRE(body["preset"] == "private_chat");
+ });
+ }
+}
+
+TEST_CASE("Process create room response", "[client][create-room]")
+{
+ boost::asio::io_context io;
+ AsioPromiseHandler ph{io.get_executor()};
+
+ auto store = createTestClientStore(ph);
+
+ WHEN("Success response")
+ {
+ auto succResponse = makeResponse("CreateRoom", withResponseJsonBody(json{{"room_id", "!some-room:example.com"}}));
+ store.dispatch(ProcessResponseAction{succResponse})
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ });
+ }
+ WHEN("Failed response")
+ {
+ auto failResponse = makeResponse("CreateRoom", withResponseStatusCode(400) | withResponseJsonBody(json{
+ {"error", "An unknown error occurred"},
+ {"errcode", "M_UNKNOWN"},
+ }));
+ store.dispatch(ProcessResponseAction{failResponse})
+ .then([](auto stat) {
+ REQUIRE(!stat.success());
+ REQUIRE(stat.dataStr("error") == "An unknown error occurred");
+ REQUIRE(stat.dataStr("errorCode") == "400");
+ });
+ }
+ io.run();
}

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 9:22 AM (12 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39916
Default Alt Text
D138.1732555343.diff (6 KB)

Event Timeline