Skip to content
Snippets Groups Projects
Unverified Commit 36c6d33b authored by NepNep21's avatar NepNep21
Browse files

(De)serialization test + fix null values

parent 2aec3756
No related branches found
No related tags found
No related merge requests found
Pipeline #4911 passed
......@@ -25,7 +25,7 @@ to_json(nlohmann::json &obj, const IgnoredUsers &content)
{
std::unordered_map<std::string, nlohmann::json> map;
for (const IgnoredUser &user : content.users) {
map[user.id] = {};
map[user.id] = nlohmann::json::object(); // {} = null
}
obj["ignored_users"] = map;
}
......
#include <algorithm>
#include <gtest/gtest.h>
#include <mtx.hpp>
......@@ -1615,6 +1616,38 @@ TEST(AccountData, FullyRead)
EXPECT_EQ(j.dump(), json(event).dump());
}
TEST(AccountData, IgnoredUsers)
{
json j = R"({
"content": {
"ignored_users": {
"@someone:example.org": {},
"@anotherone:example.org": {}
}
},
"type": "m.ignored_user_list"
})"_json;
ns::AccountDataEvent<ns::account_data::IgnoredUsers> event =
j.get<ns::AccountDataEvent<ns::account_data::IgnoredUsers>>();
ASSERT_EQ(event.content.users.size(), 2);
// JSON does not demand a guaranteed key order
ASSERT_TRUE(std::any_of(event.content.users.cbegin(),
event.content.users.cend(),
[](const ns::account_data::IgnoredUser &entry) {
return entry.id == "@someone:example.org";
}));
ASSERT_TRUE(std::any_of(event.content.users.cbegin(),
event.content.users.cend(),
[](const ns::account_data::IgnoredUser &entry) {
return entry.id == "@anotherone:example.org";
}));
ASSERT_EQ(event.type, ns::EventType::IgnoredUsers);
ASSERT_EQ(j.dump(), json(event).dump());
}
TEST(ToDevice, KeyVerificationRequest)
{
json request_data = R"({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment