Page MenuHomePhorge

No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None
diff --git a/src/tests/client/redact-test.cpp b/src/tests/client/redact-test.cpp
index 76e0bf7..0c0bbf6 100644
--- a/src/tests/client/redact-test.cpp
+++ b/src/tests/client/redact-test.cpp
@@ -1,96 +1,110 @@
/*
* This file is part of libkazv.
* SPDX-FileCopyrightText: 2021-2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <libkazv-config.hpp>
#include <lager/event_loop/boost_asio.hpp>
#include <catch2/catch_all.hpp>
#include <boost/asio.hpp>
#include <asio-promise-handler.hpp>
#include <cursorutil.hpp>
#include <sdk.hpp>
#include <cprjobhandler.hpp>
#include <lagerstoreeventemitter.hpp>
#include "client-test-util.hpp"
template<class Store, class Func>
static auto getMockContext(SingleTypePromiseInterface<EffectStatus> &ph, Store &store, Func func)
{
return typename Client::ContextT([&ph, &store, func](const auto &action) {
auto [cont, res] = func(action);
if (!cont) {
return ph.createResolved(res);
}
kzo.client.err() << "Unhandled action: index " << action.index();
throw std::runtime_error{"unhandled action"};
}, ph, lager::deps<>{});
}
TEST_CASE("Redact a message", "[client][redact]")
{
ClientModel loggedInModel = createTestClientModel();
auto [resModel, dontCareEffect] = ClientModel::update(
loggedInModel, RedactEventAction{"!foo:tusooa.xyz", "$event-id", "some reason"});
assert1Job(resModel);
for1stJob(resModel, [] (const auto &job) {
REQUIRE(job.jobId() == "RedactEvent");
});
}
+TEST_CASE("Redact a message without a reason", "[client][redact]")
+{
+ ClientModel loggedInModel = createTestClientModel();
+
+ auto [resModel, dontCareEffect] = ClientModel::update(
+ loggedInModel, RedactEventAction{"!foo:tusooa.xyz", "$event-id", std::nullopt});
+
+ assert1Job(resModel);
+ for1stJob(resModel, [] (const auto &job) {
+ REQUIRE(job.jobId() == "RedactEvent");
+ REQUIRE(json::parse(std::get<BytesBody>(job.requestBody())) == json::object());
+ });
+}
+
TEST_CASE("Room::redact()", "[client][redact]")
{
boost::asio::io_context io;
SingleTypePromiseInterface<EffectStatus> sgph{AsioPromiseHandler{io.get_executor()}};
ClientModel m = createTestClientModel();
RoomModel room;
room.roomId = "!exampleroomid:example.com";
m.roomList.rooms = m.roomList.rooms.set("!exampleroomid:example.com", room);
auto jh = Kazv::CprJobHandler{io.get_executor()};
auto ee = Kazv::LagerStoreEventEmitter(lager::with_boost_asio_event_loop{io.get_executor()});
auto sdk = Kazv::makeSdk(
SdkModel{m},
jh,
ee,
Kazv::AsioPromiseHandler{io.get_executor()},
zug::identity
);
auto ctx = sdk.context();
auto redactCalled = 0;
auto redactAction = RedactEventAction{};
auto mockContext = getMockContext(sgph, ctx, [&redactCalled, &redactAction](const auto &a) {
if (std::holds_alternative<RedactEventAction>(a)) {
++redactCalled;
redactAction = std::get<RedactEventAction>(a);
return std::make_pair(/* cont = */ false, EffectStatus());
}
return std::make_pair(/* cont = */ true, EffectStatus());
});
auto client = Client(Client::InEventLoopTag{}, mockContext, sdk.context());
auto r = client.room("!exampleroomid:example.com");
r.redactEvent("$some-event", "some reason")
.then([&io](auto st) {
REQUIRE(st.success());
io.stop();
});
io.run();
REQUIRE(redactCalled == 1);
REQUIRE(redactAction.roomId == "!exampleroomid:example.com");
REQUIRE(redactAction.eventId == "$some-event");
REQUIRE(redactAction.reason == std::optional<std::string>("some reason"));
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 8:06 PM (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55428
Default Alt Text
(3 KB)

Event Timeline