Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F140215
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/tests/client/profile-test.cpp b/src/tests/client/profile-test.cpp
index baa9847..4c780b2 100644
--- a/src/tests/client/profile-test.cpp
+++ b/src/tests/client/profile-test.cpp
@@ -1,81 +1,96 @@
/*
* This file is part of libkazv.
* SPDX-FileCopyrightText: 2022 Tusooa Zhu <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <libkazv-config.hpp>
#include <catch2/catch.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"
static const json getUserProfileResponseJson = R"({
"avatar_url": "mxc://matrix.org/SDGdghriugerRg",
"displayname": "Alice Margatroid"
})"_json;
TEST_CASE("GetUserProfile", "[client][profile]")
{
WHEN("We initiate this job")
{
ClientModel loggedInModel = createTestClientModel();
auto [resModel, dontCareEffect] = ClientModel::update(loggedInModel, GetUserProfileAction{"@alice:example.com"});
THEN("it should be added")
{
REQUIRE(resModel.nextJobs.size() == 1);
REQUIRE(resModel.nextJobs[0].jobId() == "GetUserProfile");
}
THEN("we should not send access token")
{
REQUIRE_FALSE(hasAccessToken(resModel.nextJobs[0]));
}
}
using namespace Kazv::CursorOp;
boost::asio::io_context io;
AsioPromiseHandler ph{io.get_executor()};
auto store = createTestClientStore(ph);
WHEN("We got a successful response")
{
auto resp = createResponse("GetUserProfile", getUserProfileResponseJson);
THEN("We should return the avatar url and display name in the response")
{
store.dispatch(ProcessResponseAction{resp})
.then([](auto stat) {
REQUIRE(stat.success());
REQUIRE(stat.dataStr("avatarUrl") == getUserProfileResponseJson["avatar_url"]);
REQUIRE(stat.dataStr("displayName") == getUserProfileResponseJson["displayname"]);
});
}
}
+ WHEN("We got an empty json")
+ {
+ auto resp = createResponse("GetUserProfile", json());
+
+ THEN("We should return empty string avatar url and display name")
+ {
+ store.dispatch(ProcessResponseAction{resp})
+ .then([](auto stat) {
+ REQUIRE(stat.success());
+ REQUIRE(stat.dataStr("avatarUrl") == "");
+ REQUIRE(stat.dataStr("displayName") == "");
+ });
+ }
+ }
+
WHEN("We got a failed response")
{
auto resp = createResponse("GetUserProfile", json{});
resp.statusCode = 404;
THEN("We should fail")
{
store.dispatch(ProcessResponseAction{resp})
.then([](auto stat) {
REQUIRE(!stat.success());
REQUIRE(stat.dataStr("errorCode") == "404");
});
}
}
io.run();
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 3:23 PM (23 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55267
Default Alt Text
(3 KB)
Attached To
Mode
rL libkazv
Attached
Detach File
Event Timeline
Log In to Comment