Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2697666
redact-test.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
redact-test.cpp
View Options
/*
* 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"
#include
"factory.hpp"
using
namespace
Kazv
::
Factory
;
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
=
makeClient
({});
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
=
makeClient
({});
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
=
makeClient
(
withRoom
(
makeRoom
(
withRoomId
(
"!exampleroomid:example.com"
))
)
);
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
Details
Attached
Mime Type
text/x-c++
Expires
Fri, Jul 18, 7:02 AM (5 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
261221
Default Alt Text
redact-test.cpp (3 KB)
Attached To
Mode
rL libkazv
Attached
Detach File
Event Timeline
Log In to Comment