Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F111996
ban-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
ban-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
<catch2/catch_all.hpp>
#include
<boost/asio.hpp>
#include
<asio-promise-handler.hpp>
#include
<cursorutil.hpp>
#include
<sdk-model.hpp>
#include
<client/client.hpp>
#include
"client-test-util.hpp"
#include
"factory.hpp"
using
namespace
Kazv
::
Factory
;
TEST_CASE
(
"Send ban job"
,
"[client][membership]"
)
{
ClientModel
loggedInModel
=
makeClient
({});
auto
[
resModel
,
dontCareEffect
]
=
ClientModel
::
update
(
loggedInModel
,
BanAction
{
"!room:example.com"
,
"@alice:example.com"
,
"spamming"
});
assert1Job
(
resModel
);
for1stJob
(
resModel
,
[]
(
const
auto
&
job
)
{
REQUIRE
(
job
.
jobId
()
==
"Ban"
);
REQUIRE
(
job
.
url
().
find
(
"!room:example.com"
)
!=
std
::
string
::
npos
);
auto
jsonBody
=
json
::
parse
(
std
::
get
<
BytesBody
>
(
job
.
requestBody
()));
REQUIRE
(
jsonBody
[
"user_id"
]
==
"@alice:example.com"
);
REQUIRE
(
jsonBody
[
"reason"
]
==
"spamming"
);
});
}
TEST_CASE
(
"Process ban response"
,
"[client][membership]"
)
{
boost
::
asio
::
io_context
io
;
AsioPromiseHandler
ph
{
io
.
get_executor
()};
auto
store
=
createTestClientStore
(
ph
);
WHEN
(
"Success response"
)
{
auto
succResponse
=
makeResponse
(
"Ban"
);
store
.
dispatch
(
ProcessResponseAction
{
succResponse
})
.
then
([]
(
auto
stat
)
{
REQUIRE
(
stat
.
success
());
});
}
WHEN
(
"Failed response"
)
{
auto
failResponse
=
makeResponse
(
"Ban"
,
withResponseJsonBody
(
R
"
(
{
"errcode": "M_FORBIDDEN",
"error": "You do not have a high enough power level to ban from this room."
}
)
"
_json
)
|
withResponseStatusCode
(
403
));
store
.
dispatch
(
ProcessResponseAction
{
failResponse
})
.
then
([]
(
auto
stat
)
{
REQUIRE
(
!
stat
.
success
());
REQUIRE
(
stat
.
dataStr
(
"error"
)
==
"You do not have a high enough power level to ban from this room."
);
REQUIRE
(
stat
.
dataStr
(
"errorCode"
)
==
"M_FORBIDDEN"
);
});
}
io
.
run
();
}
TEST_CASE
(
"Send unban job"
,
"[client][membership]"
)
{
ClientModel
loggedInModel
=
makeClient
({});
auto
[
resModel
,
dontCareEffect
]
=
ClientModel
::
update
(
loggedInModel
,
UnbanAction
{
"!room:example.com"
,
"@alice:example.com"
});
assert1Job
(
resModel
);
for1stJob
(
resModel
,
[]
(
const
auto
&
job
)
{
REQUIRE
(
job
.
jobId
()
==
"Unban"
);
REQUIRE
(
job
.
url
().
find
(
"!room:example.com"
)
!=
std
::
string
::
npos
);
auto
jsonBody
=
json
::
parse
(
std
::
get
<
BytesBody
>
(
job
.
requestBody
()));
REQUIRE
(
jsonBody
[
"user_id"
]
==
"@alice:example.com"
);
// No reason field in r0
// REQUIRE(jsonBody["reason"] == "spamming");
});
}
TEST_CASE
(
"Process unban response"
,
"[client][membership]"
)
{
boost
::
asio
::
io_context
io
;
AsioPromiseHandler
ph
{
io
.
get_executor
()};
auto
store
=
createTestClientStore
(
ph
);
WHEN
(
"Success response"
)
{
auto
succResponse
=
makeResponse
(
"Unban"
);
store
.
dispatch
(
ProcessResponseAction
{
succResponse
})
.
then
([]
(
auto
stat
)
{
REQUIRE
(
stat
.
success
());
});
}
WHEN
(
"Failed response"
)
{
auto
failResponse
=
makeResponse
(
"Unban"
,
withResponseJsonBody
(
R
"
(
{
"errcode": "M_FORBIDDEN",
"error": "You do not have a high enough power level to unban from this room."
}
)
"
_json
)
|
withResponseStatusCode
(
403
));
store
.
dispatch
(
ProcessResponseAction
{
failResponse
})
.
then
([]
(
auto
stat
)
{
REQUIRE
(
!
stat
.
success
());
REQUIRE
(
stat
.
dataStr
(
"error"
)
==
"You do not have a high enough power level to unban from this room."
);
REQUIRE
(
stat
.
dataStr
(
"errorCode"
)
==
"M_FORBIDDEN"
);
});
}
io
.
run
();
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Fri, Nov 22, 9:05 PM (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38710
Default Alt Text
ban-test.cpp (3 KB)
Attached To
Mode
rL libkazv
Attached
Detach File
Event Timeline
Log In to Comment